Search code examples
pythonneural-networkchatbot

IndexError: list index out of range (Chatbot is not working)


I Was Coding a chatbot, but it doesn't work Every time I Run my program and start A conversation. I get that error code, why is that so and what can I do ?

Error Code

It says that there is something in line 46

def get_response(intents_list, intents_json):
tag = intents_list[0]["intent"] #line 46 
list_of_intents = intents["intents"]
for i in list_of_intents:
    if i ["tag"] == tag:
        result = random.choice(i["response"])
        break
return result

and it also says that there is a problem in line 59

while True:
message = input("")
ints = predict_class(message)
res = get_response(ints, intents) #line 59
print(res)

Solution

  • It indeed looks kike predict_class returns an empty list so intents_list[0] does not exist and throws an out of bound on line 46. Line 59 is just the call stack, aka that is where you call the function that contains the error, which you do on that line.