Python Forum
Help with simple nltk Chatbot
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with simple nltk Chatbot
#1
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:
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"
}
Reply


Messages In This Thread
Help with simple nltk Chatbot - by Extra - Dec-30-2021, 11:14 PM
RE: Help with simple nltk Chatbot - by Extra - Dec-30-2021, 11:47 PM
RE: Help with simple nltk Chatbot - by bowlofred - Dec-31-2021, 01:24 AM
RE: Help with simple nltk Chatbot - by bepammoifoge - Jan-02-2022, 07:50 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Bug beginner attempting to make chatbot MonikaDreemur 1 1,141 Feb-02-2022, 10:24 PM
Last Post: BashBedlam
  Python Reminder MSTeams Chatbot ajaymedidi 0 1,173 Sep-16-2021, 07:13 AM
Last Post: ajaymedidi
  Saving a download of stopwords (nltk) Drone4four 1 9,448 Nov-19-2020, 11:50 PM
Last Post: snippsat
  Generate questions from excel to test my chatbot mcubac08 5 2,925 Sep-01-2020, 06:15 PM
Last Post: mcubac08
  Installing nltk dependency Eshwar 0 1,863 Aug-30-2020, 06:10 PM
Last Post: Eshwar
  Trying to pass an exe filepath to tkinter Chatbot & expecting the chatbot to run it svkroy 0 1,612 Jul-16-2020, 07:46 AM
Last Post: svkroy
  Chatbot metro17 2 12,144 Sep-21-2019, 02:05 PM
Last Post: Larz60+
  Clean Data using NLTK disruptfwd8 0 3,359 May-12-2018, 11:21 PM
Last Post: disruptfwd8
  error in database for chatbot TaraSunray 0 2,601 Mar-13-2018, 03:02 PM
Last Post: TaraSunray
  Text Processing and NLTK (POS tagging) TwelveMoons 2 4,933 Mar-16-2017, 02:53 AM
Last Post: TwelveMoons

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020