-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathnltk_chatbot.py
51 lines (48 loc) · 1.61 KB
/
nltk_chatbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Basic Chatbot with NLTK
# Required Modules
import nltk
from nltk.chat.util import Chat, reflections
# Pairs:Reflections
pairs = [
[
r"hi|hello|hey",
["Hello!", "Hi there!", "Hey!"]
],
[
r"how are you?",
["I'm good, thank you! How about you?", "Doing well, how are you?"]
],
[
r"what is your name?",
["I'm a chatbot created using NLTK.", "You can call me NLTKBot."]
],
[
r"what can you do?",
["I can chat with you and answer some basic questions.", "I'm here to talk and help you with basic queries."]
],
[
r"how does natural language processing work?",
["Natural Language Processing (NLP) is a field of artificial intelligence that focuses on the interaction between computers and humans through natural language.",
"NLP combines computational linguistics with statistical, machine learning, and deep learning models to process and understand human language."]
],
[
r"(.*) your favorite (.*)?",
["I'm just a bot, but I think everything is interesting!", "I don't have preferences, but I enjoy learning new things!"]
],
[
r"quit",
["Bye for now. See you soon!", "Goodbye! It was nice talking to you."]
],
[
r"(.*)",
["I'm sorry, I don't understand that. Can you please rephrase?", "Can you please clarify your question?"]
]
]
# Converse ChatBot
def chatbot():
print("Hi! I'm a chatbot created using NLTK. Type 'quit' to exit.")
chat = Chat(pairs, reflections)
chat.converse()
# Start ChatBot
if __name__ == "__main__":
chatbot()