-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatbot.py
More file actions
131 lines (90 loc) · 3 KB
/
Copy pathchatbot.py
File metadata and controls
131 lines (90 loc) · 3 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from chatterbot import ChatBot
chatbot = ChatBot("mybot",
logic_adapters=[
{
"import_path": "chatterbot.logic.BestMatch",
"statement_comparison_function": "chatterbot.comparisons.levenshtein_distance",
"response_selection_method": "chatterbot.response_selection.get_first_response"
},
{
'import_path': 'chatterbot.logic.LowConfidenceAdapter',
'threshold': 0.65,
'default_response': 'I am sorry, but I do not understand.'
}
],
trainer='chatterbot.trainers.ListTrainer')
########################################
### TRAINING - run this just one time
########################################
chatbot.train([
'Good morning!',
'Good morning!',
'How are you today?',
'I am fine',
'Do you like machine learning?',
'Yes, I like machine learning'
])
chatbot.train([
'Good morning!',
'Good morning!'
])
chatbot.train([
'Hello',
'Hi there!'
])
chatbot.train([
'Let us talk about current activities',
'What are you working on now?',
'I am just browsing Internet for news',
'What a waste of time! Dont you have any other things to do?',
'I am working on python script to make new chatbot',
'This is great. Keep working on this'
])
chatbot.train(
"chatterbot.corpus.english.greetings"
)
chatbot.train(
"chatterbot.corpus.english.conversations"
)
from chatterbot.trainers import ListTrainer
conversation = [
"Hello",
"Hi there!",
"How are you doing?",
"I'm doing great.",
"That is good to hear",
"Thank you.",
"You're welcome."
]
chatbot.set_trainer(ListTrainer)
chatbot.train(conversation)
########################################
### END of TRAINING
########################################
print ("USER: How are you doing?")
response = chatbot.get_response("How are you doing?")
print("BOT:" + str(response))
print ("USER: Hello")
response = chatbot.get_response("Hello")
print("BOT:" + str(response))
print ("USER: Good morning!")
response = chatbot.get_response("Good morning!")
print("BOT:" + str(response))
print ("USER: Do you like machine learning?")
response = chatbot.get_response("Do you like machine learning?")
print ("BOT:" + str(response))
print ("USER: How do I make a neural network?")
response = chatbot.get_response('How do I make a neural network?')
print("BOT" + str(response))
print ("USER: Let us talk about current activities")
response = chatbot.get_response("Let us talk about current activities")
print("BOT:"+str(response))
print ("USER: I am just browsing Internet for news")
response = chatbot.get_response("BOT: I am just browsing Internet for news")
print("BOT:" + str(response))
print ("USER: I am working on python script to make new chatbot")
response = chatbot.get_response("I am working on python script to make new chatbot")
print("BOT:"+str(response))
print ("USER: Bye")
response = chatbot.get_response("Bye")
print("BOT:" + str(response))