Psychologist chat bot using python
Python program that creates a simple psychologist chat bot using the `nltk` library for natural language processing:
import nltk
from nltk.chat.util import Chat, reflections
# Define some pattern-response pairs for the chat bot
pairs = [
[
r"my name is (.*)",
["Hello %1, How are you today?",]
],
[
r"hi|hey|hello",
["Hello", "Hey there",]
],
[
r"what is your name ?",
["I am a psychologist bot and my name is Chatty. How can I help you?",]
],
[
r"how are you ?",
["I'm doing good. How about you?",]
],
[
r"sorry (.*)",
["Its alright", "Its OK, never mind",]
],
[
r"I am fine",
["Great to hear that, How can I help you?",]
],
[
r"quit",
["Bye-bye. Take care. It was nice talking to you.",]
],
]
# Create a chat bot instance
chat_bot = Chat(pairs, reflections)
# Run the chat bot
chat_bot.converse()
When you run this program, it will create a simple command-line chat bot that can have conversations with the user. The chat bot will match user inputs with the defined patterns in the `pairs` list and respond accordingly.
For example, if the user input is "My name is John", the chat bot will respond with "Hello John, How are you today?". Similarly, if the user input is "Hi", the chat bot will respond with "Hello" or "Hey there".
Feel free to modify the pattern-response pairs to fit your desired conversation flow.
Comments
Post a Comment