Hello,
I'm trying to build a simple chatbot using nltk. The problem I have with this code is that whenever I input a response (ex: my name is bob) the bot responds with this "Great to hear that, How can I help you?" OR "Nice to hear that" which is supposed to be triggered when I say/enter: "I am fine" , "i'm (.*) doing good" OR "great".
For some reason it keeps using that ("Great to hear that, How can I help you?" OR "Nice to hear that") as a default response no matter what I type. I had it working before (with the comments in the code included) and I don't know what happened.
I'm fairly new to nltk and I'm trying to learn but this issue has me stumped.
Can anyone help me figure out why it keeps defaulting to these responses?
Thanks.
Main Code:
I'm trying to build a simple chatbot using nltk. The problem I have with this code is that whenever I input a response (ex: my name is bob) the bot responds with this "Great to hear that, How can I help you?" OR "Nice to hear that" which is supposed to be triggered when I say/enter: "I am fine" , "i'm (.*) doing good" OR "great".
For some reason it keeps using that ("Great to hear that, How can I help you?" OR "Nice to hear that") as a default response no matter what I type. I had it working before (with the comments in the code included) and I don't know what happened.
I'm fairly new to nltk and I'm trying to learn but this issue has me stumped.
Can anyone help me figure out why it keeps defaulting to these responses?
Thanks.
Main Code:
import nltk from nltk.chat.util import Chat, reflections from Reflections import * from Intents import * def chat(): print("Hi! I am a chatbot") chat = Chat(pairs, reflections) chat.converse() #initiate the conversation if __name__ == "__main__": chat()Intents script:
pairs = [ #------------------------------------------------ #Greetings #------------------------------------------------ [ r"hi|hey|hello", ["Hello", "Hey there",] ], [ r"bye|goodbye| see ya", ["Goodbye",] ], [ r"how are you ?", ["I'm doing good. How about you?",] ], [ r"I am fine|i'm (.*) doing good|great|", ["Great to hear that, How can I help you?","Nice to hear that",] ], #------------------------------------------------ #About #------------------------------------------------ [ r"my name is (.*)", ["Hello %1, How are you today?",] ], [ r"what is your name ?", ["I am a Baxter.",] ], [ r"sorry (.*)|sorry|(.*) sorry", ["It's alright","It's OK, never mind",] ], [ r"(.*) age?", ["I lost track.",] ], [ r"what (.*) want ?", ["Make me an offer I can't refuse",] ], [ r"(.*) created ?", ["I was created by you",] ], [ r"(.*) (sports|game) ?", ["I'm a very big fan of Soccer",] ], [ r"who (.*) sportsperson ?", ["Messy","Ronaldo"] ], [ r"who (.*) (moviestar|actor)?", ["Will Smith"] ], [ r"quit", ["Until next time"] ], ]Reflections Script:
reflections = { "i am" : "you are", "i was" : "you were", "i" : "you", "i'm" : "you are", "i'd" : "you would", "i've" : "you have", "i'll" : "you will", "my" : "your", "you are" : "I am", "you were" : "I was", "you've" : "I have", "you'll" : "I will", "your" : "my", "yours" : "mine", "you" : "me", "me" : "you" }