-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_chatbot.py
More file actions
66 lines (47 loc) · 1.69 KB
/
Copy pathbasic_chatbot.py
File metadata and controls
66 lines (47 loc) · 1.69 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
# -*- coding: utf-8 -*-
"""Basic_ChatBot.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1LAgyZtVNCJeNC9hS8y0eTxhfeCbsvF70
"""
pip install chatterbot
pip install chatterbot_corpus
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
my_Bot=ChatBot(name='PyBot',read_only=True,logic_adapters=['chatterbot.logic.MathematicalEvaluation','chatterbot.logic.BestMatch'])
#training over small data
small_talk=['hi there!',
'hi!',
'how are you?',
'i\'m cool.',
'fine,you?',
'always cool.',
'i\'m ok',
'glad to hear that.',
'i\'m fine',
'glad to hear that.',
'i feel awesome',
'excellent, glad to hear that',
'not so good',
'sorry to hear that.',
'what\'s your name?',
'i\'m PyBot. Ask me anything']
math_talk_1=['pythagorean theorem',
'a squared plus b squared equals c squared']
math_talk_2=['laws of cosines',
'c**2 = a**2 + b**2 - 2*a*b*cos(gamma)']
list_trainer=ListTrainer(my_Bot)
for item in (small_talk,math_talk_1,math_talk_2):
list_trainer.train(item)
#example
print(my_Bot.get_response('hi'))
#example
print(my_Bot.get_response('i feel awesome today'))
#example
print(my_Bot.get_response('do you know the law of cosines?'))
#Training PyBot with an existing corpus of data
from chatterbot.trainers import ChatterBotCorpusTrainer
corpus_trainer=ChatterBotCorpusTrainer(my_Bot)
corpus_trainer.train('chatterbot.corpus.english')
print(my_Bot.get_response('Hi...'))
print(my_Bot.get_response('What\'s your name?'))