Why is my NLTK bot not working correctly?

30 Views Asked by At

I am trying to write a chatbot using NLTK, now while the rest of my code works, the quit stop word "quit" returns "hello quit how may I assist you today" instead of "Bye, take care. See you soon!"

import nltk
nltk.download
from nltk.chat.util import Chat, reflections
 
 
pairs = [
 
    (
        r"hi",
        ["Hello what is your name?", ]
    ),
    (
        r"hello",
        ["Hello what is your name?", ]
    ),
    (
        r"(.*)",
        ["Hello %1, how can I help you today?", ]
    ),
    (
        r"my name is (.*)",
        ["Hello %1, how can I help you today?", ]
    ),
    (
        r"what is your name?",
        ["My name is ZeroBot and I'm here to assist you.", ]
    ),
    (
        r"how are you ?",
        ["I'm doing well, thank you!", ]
    ),
    (
        r"sorry (.*)",
        ["It's alright, no problem.", ]
    ),
    (
        r"quit",
        ["Bye, take care. See you soon!"]
    ),
]
 
 
chatbot = Chat(pairs, reflections)
 
 
def Chat():
    print("Hi, I'm ZeroBot. How can I assist you today? Type 'quit' to exit.")
    while True:
        user_input = input("You: ")
        response = chatbot.respond(user_input)
        print("ZeroBot:", response)
        if user_input == "quit":
            break
 
 
Chat()

where am I going Wrong? I am relatively new to both Python and the NLTK chat module so If possible id like for the answer to also explain what I was doing wrong as well as the fix

0

There are 0 best solutions below