Professional Documents
Culture Documents
Chat Bot
Chat Bot
Chatbot 2
# importing the required modules
1. from chatterbot import ChatBot
2. from chatterbot.trainers import ListTrainer
3. from chatterbot.trainers import ChatterBotCorpusTrainer
4.
5. # creating a chatbot
6. myBot = ChatBot(
7. name = 'Sakura',
8. read_only = True,
9. logic_adapters = [
10. 'chatterbot.logic.MathematicalEvaluation',
11. 'chatterbot.logic.BestMatch'
12. ]
13. )
14.
15. # training the chatbot
16. small_convo = [
17. 'Hi there!',
18. 'Hi',
19. 'How do you do?',
20. 'How are you?',
21. 'I\'m cool.',
22. 'Always cool.',
23. 'I\'m Okay',
24. 'Glad to hear that.',
25. 'I\'m fine',
26. 'I feel awesome',
27. 'Excellent, glad to hear that.',
28. 'Not so good',
29. 'Sorry to hear that.',
30. 'What\'s your name?',
31. ' I\'m Sakura. Ask me a math question, please.'
32. ]
33.
34. math_convo_1 = [
35. 'Pythagorean theorem',
36. 'a squared plus b squared equals c squared.'
37. ]
38.
39. math_convo_2 = [
40. 'Law of Cosines',
41. 'c**2 = a**2 + b**2 - 2*a*b*cos(gamma)'
42. ]
43.
44. # using the ListTrainer class
45. list_trainee = ListTrainer(myBot)
46. for i in (small_convo, math_convo_1, math_convo_2):
47. list_trainee.train(i)
48.
49. # using the ChatterBotCorpusTrainer class
50. corpus_trainee = ChatterBotCorpusTrainer(myBot)
51. corpus_trainee.train('chatterbot.corpus.english')