Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Argument Passing issue in python

I have been working on chatbot in python and is learning from the udemy course.I am stuck at the following error and can not understand it.Can you please help me with the error

File "<ipython-input-39-24afce68eaf5>", line 3, in <module>
        questions.append(idline2[conversation[i]])

    KeyError: 'L194

here is the code

import numpy as np
import tensorflow as tf
import re
import time 

#data Preprocessing
lines=open('movie_lines.txt', encoding = 'utf-8', errors = 'ignore').read().split('\n')
conversations=open('movie_conversations.txt', encoding = 'utf-8', errors = 'ignore').read().split('\n')
#making a dictionary
idline2={}
for line in lines:
    _line= line.split ('+++$+++')
    if len(_line)== 5:
        idline2[_line[0]]= _line[4]
#making the list
conversations_ids = []
for conversation in conversations [:-1]:
    _conversation = conversation.split(' +++$+++ ')[-1][1:-1].replace("'" , "").replace(" ", "")
    conversations_ids.append(_conversation.split(','))
#separating questions and answers

questions=[]
answers=[]
for conversation in conversations_ids:
    for i in range(len(conversation) - 1):
        questions.append(idline2[conversation[i]])
        answers.append(idline2[conversation[i+1]])

Comments