-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
twitter_training_example.py
40 lines (32 loc) · 1.18 KB
/
twitter_training_example.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
from chatterbot import ChatBot
from settings import TWITTER
import logging
'''
This example demonstrates how you can train your chat bot
using data from Twitter.
To use this example, create a new file called settings.py.
In settings.py define the following:
TWITTER = {
"CONSUMER_KEY": "my-twitter-consumer-key",
"CONSUMER_SECRET": "my-twitter-consumer-secret",
"ACCESS_TOKEN": "my-access-token",
"ACCESS_TOKEN_SECRET": "my-access-token-secret"
}
'''
# Comment out the following line to disable verbose logging
logging.basicConfig(level=logging.INFO)
chatbot = ChatBot("TwitterBot",
logic_adapters=[
"chatterbot.adapters.logic.ClosestMatchAdapter"
],
input_adapter="chatterbot.adapters.input.TerminalAdapter",
output_adapter="chatterbot.adapters.output.TerminalAdapter",
database="./twitter-database.db",
twitter_consumer_key=TWITTER["CONSUMER_KEY"],
twitter_consumer_secret=TWITTER["CONSUMER_SECRET"],
twitter_access_token_key=TWITTER["ACCESS_TOKEN"],
twitter_access_token_secret=TWITTER["ACCESS_TOKEN_SECRET"],
trainer="chatterbot.trainers.TwitterTrainer"
)
chatbot.train()
chatbot.logger.info('Trained database generated successfully!')