Reputation: 545
I'm working on a chatbot which has two scenarios.
1: When the user types a question, if that question is available it training dataset, It picks a response for that question from the training dataset.
2: If the question typed by user is not available in the dataset, system gives response from default answers which are defined with in the code.
My problem is, when the system gets a question statement that is not in the training data, it picks a random answer from the code (Fine). But from that point, it starts giving default answers no matter which question we ask. It never picks an answer from training data despite having that particular question and its answer in the training data.
The entire code is too large to paste here. I'm writing just those functions where the problem occurs. Hope someone could help me with this.
def response(sentence, userID='123', show_details=False):
results = classify(sentence)
# if we have a classification then find the matching intent tag
if results:
# loop as long as there are matches to process
while results:
#some if else statements to match the question
results.pop(0)
while not results:
pairs = (
(r'I need (.*)',
("Why do you need %1?",
"Would it really help you to get %1?",
"Are you sure you need %1?")),
(r'Why don\'t you (.*)',
("Do you really think I don't %1?",
"Perhaps eventually I will %1.",
"Do you really want me to %1?"))
)
aida_chatbot = Chat(pairs, reflections)
def aida_chat():
aida_chatbot.converse()
def demo():
aida_chat()
if __name__ == "__main__":
demo()
else:
response()
# sentence = sys.stdin.readline()
sys.stdout.write("> ")
sys.stdout.flush()
classify(sentence=sys.stdin.readline())
while True:
response(sentence=sys.stdin.readline())
When I put the pairs outside the while statement, (e.g in else statement after the if statement is closed), program never enters the else statement and this part of code is never executed. Cany anybody help me with this?
Upvotes: 0
Views: 829
Reputation: 464
if __name__ == "__main__":
demo()
else:
response()
You are not passing question text from this response function call. Just pass your question as an argument from this response function call.
Upvotes: 1