2

I'm trying to use chatterbot to create a chatbot in telegram and use the function train() to generate the ChatBot but visual code(my editor) and atom can't recognize the library. Before I use pip install chatterbot in cmd and launched:

Successfully installed PyYAML-3.13 chatterbot-1.0.4 chatterbot-corpus-1.2.0 mathparse-0.1.2 nltk-3.4 pint-0.9 pymongo-3.7.2 singledispatch-3.4.0.3 sqlalchemy-1.2.18

I tried to re-install the library from cmd in visual code. But don't run the code. The error that show me is:

[nltk_data] Downloading package averaged_perceptron_tagger to
[nltk_data]     C:\Users\KatiusKa\AppData\Roaming\nltk_data...
[nltk_data]   Unzipping taggers\averaged_perceptron_tagger.zip.
[nltk_data] Downloading package punkt to
[nltk_data]     C:\Users\KatiusKa\AppData\Roaming\nltk_data...
[nltk_data]   Unzipping tokenizers\punkt.zip.
[nltk_data] Downloading package stopwords to
[nltk_data]     C:\Users\KatiusKa\AppData\Roaming\nltk_data...
[nltk_data]   Unzipping corpora\stopwords.zip.
[nltk_data] Downloading package wordnet to
[nltk_data]     C:\Users\KatiusKa\AppData\Roaming\nltk_data...
[nltk_data]   Unzipping corpora\wordnet.zip.
Traceback (most recent call last):
  File "C:\Users\KatiusKa\Documents\Python\chbot.py", line 8, in <module>
    chatbot.train(
AttributeError: 'ChatBot' object has no attribute 'train'

This is the code in visual code:

from chatterbot import ChatBot

chatbot = ChatBot(
    "Ejemplo Bot",
    trainer = "chatterbot.trainers.ChatterBotCorpusTrainer"
)

chatbot.train(
    "chatterbot.corpus.spanish"
)

This is the code that I tried run from visual code

eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

6

The error is correct - the chatbot class does not have an attribute train. If you check out the docs, it's the ChatterBotCorpusTrainer class that you're supposed to train, and which does, indeed, have a train() function.

Check out the basic usage of chatterbot here: https://github.com/gunthercox/ChatterBot#basic-usage

from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer

chatbot = ChatBot('Ron Obvious')

# Create a new trainer for the chatbot
trainer = ChatterBotCorpusTrainer(chatbot)

# Train the chatbot based on the english corpus
trainer.train("chatterbot.corpus.english")
Danielle M.
  • 3,607
  • 1
  • 14
  • 31
  • If someone wants to use multiple corpus, you can use, trainer.train( "chatterbot.corpus.english.greetings", "chatterbot.corpus.english.conversations" ) – Gaurav Bahadur Apr 28 '19 at 13:50