Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'ChatBot' object has no attribute 'set_trainer' #1555

Closed
achingacham opened this issue Jan 9, 2019 · 18 comments
Closed

AttributeError: 'ChatBot' object has no attribute 'set_trainer' #1555

achingacham opened this issue Jan 9, 2019 · 18 comments
Labels

Comments

@achingacham
Copy link

achingacham commented Jan 9, 2019

Hi,
Just after installing ChatterBot ( version is 1.0.0a3.) , I tried to execute the following code snippet from quick start guide:

from chatterbot import ChatBot
chatbot = ChatBot("Ron Obvious")
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)

It failed to execute with the error, " AttributeError: 'ChatBot' object has no attribute 'set_trainer' ". I couldn't find any other post related to this attribute either.
I skimmed through the code of chatterbot.py and found ChatBot indeed has neither 'set_trainer' nor 'train' function.
Am I missing something here? I would really appreciate if anybody could help me here.
Thanks,

@achingacham achingacham changed the title AttributeError: 'ChatBot' object has no attribute 'train' AttributeError: 'ChatBot' object has no attribute 'set_trainer' Jan 9, 2019
@gunthercox
Copy link
Owner

gunthercox commented Jan 12, 2019

Hi @Chingcham, make sure you are viewing the latest version of the documentation for 1.0.0a3. The default (stable) will be for version 0.8.

https://chatterbot.readthedocs.io/en/latest/quickstart.html#training-your-chatbot

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."
]

trainer = ListTrainer(chatbot)

trainer.train(conversation)

@achingacham
Copy link
Author

Thank you! I suspected that, but I was unable to find version difference for documentation. The link helped.

@moiz7994
Copy link

moiz7994 commented Jan 16, 2019

This is my code

from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
from chatterbot.trainers import ChatterBotCorpusTrainer
import os

bot=ChatBot('Bot')
bot.set_trainer(ListTrainer)

for files in os.listdir('C:\chatterbot-corpus-1.2.0\chatterbot_corpus\data\english/'):
data= open('C:\chatterbot-corpus-1.2.0\chatterbot_corpus\data\english/' + files,'r').readlines()
bot.train(data)
while True:
message=input('you:')
if message.strip()!='bye':
reply= bot.get_response(message)
print('ChatBot :',reply)
if message.strip()=='bye':
print('ChatBot: bye')
break

@gunthercox can you please help me with the error(AttributeError: 'ChatBot' object has no attribute 'set_trainer')

@gunthercox
Copy link
Owner

@moiz7994 Please see the example in my code above (#1555 (comment)) You need to modify your code to match the new format.

@kbose02
Copy link

kbose02 commented Jan 23, 2019

I am running the below code:

from chatterbot import ChatBot #import the chatbot
from chatterbot.trainers import ListTrainer # Method to train chatterbot
from chatterbot.trainers import ChatterBotCorpusTrainer
import os

bot= ChatBot('Bot')
#bot.set_trainer(ListTrainer)
trainer = ListTrainer('Bot')

for files in os.listdir ('C:/Users/XXX/Desktop/chatterbot-corpus-master/chatterbot_corpus/data/english/'):
data = open ('C:/Users/XXX/Desktop/chatterbot-corpus-master/chatterbot_corpus/data/english/' +files, 'r').readlines()
trainer.train('Bot')

while True:
message =input('You:')
if message.strip() != 'Bye':
reply =bot.get_response(message)
print('ChatBot:',reply)
if message.strip() == 'Bye':
print('ChatBot: Bye')
break

I am getting the below error while running the code Test1.py:
C:\Users\XXX>C:/Users/XXX\AppData\Local\Programs\Python\Python37-32\python.exe C:/Users/XXX\Desktop\ABC\Test1.py
[nltk_data] Downloading package averaged_perceptron_tagger to
[nltk_data] C:\Users\XXX\AppData\Roaming\nltk_data...
[nltk_data] Package averaged_perceptron_tagger is already up-to-
[nltk_data] date!
[nltk_data] Downloading package punkt to
[nltk_data] C:\Users\XXX\AppData\Roaming\nltk_data...
[nltk_data] Package punkt is already up-to-date!
[nltk_data] Downloading package stopwords to
[nltk_data] C:\Users\XXX\AppData\Roaming\nltk_data...
[nltk_data] Package stopwords is already up-to-date!
List Trainer: [####### ] 33%Traceback (most recent call last):
File "C:/Users/XXX\Desktop\ABC\Test1.py", line 12, in
trainer.train('Bot')
File "C:\Users\XXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\chatterbot\trainers.py", line 103, in train
statement_search_text = self.chatbot.storage.tagger.get_bigram_pair_string(text)
AttributeError: 'str' object has no attribute 'storage'

@akash1998mittal
Copy link

akash1998mittal commented Jan 25, 2019

from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
import os

bot = ChatBot('Bot')

trainer = ChatterBotCorpusTrainer(ChatBot)
trainer.train("chatterbot.corpus.english")

for files in os.listdir('C:/Users/Dell/Downloads/chatterbot-corpus-master/chatterbot_corpus/data/english/'):
data = open('C:/Users/Dell/Downloads/chatterbot-corpus-master/chatterbot_corpus/data/english/' + files, 'r').readlines()
bot.train(data)

while True:
message = input('You:')
if message.strip() != 'Bye':
reply = bot.get_response(message)
print('ChatBot:',reply)

if message.strip() == 'Bye':
    print('ChatBot : bye')
    break

this error is showing...

[nltk_data] Downloading package averaged_perceptron_tagger to
[nltk_data] C:\Users\Dell\AppData\Roaming\nltk_data...
[nltk_data] Package averaged_perceptron_tagger is already up-to-
[nltk_data] date!
[nltk_data] Downloading package punkt to
[nltk_data] C:\Users\Dell\AppData\Roaming\nltk_data...
[nltk_data] Package punkt is already up-to-date!
[nltk_data] Downloading package stopwords to
[nltk_data] C:\Users\Dell\AppData\Roaming\nltk_data...
[nltk_data] Package stopwords is already up-to-date!
Training ai.yml: [ ] 1%Traceback (most recent call last):
File "C:\Users\Dell\Desktop\chatbot.py", line 9, in
trainer.train("chatterbot.corpus.english")
File "C:\Users\Dell\AppData\Local\Programs\Python\Python37-32\lib\site-packages\chatterbot\trainers.py", line 157, in train
statement_search_text = self.chatbot.storage.tagger.get_bigram_pair_string(text)
AttributeError: type object 'ChatBot' has no attribute 'storage'

@gunthercox
Copy link
Owner

@kbose02, @dilzeet100 I believe I have been able to answer your questions here: #1586 and here: gunthercox/chatterbot-corpus#112.
I hope those solutions work for you.

@dheerajnuka
Copy link

from chatterbot import ChatBot #import the chatbot
from chatterbot.trainers import ChatterBotCorpusTrainer
import os

bot= ChatBot('Bot')
trainer = ChatterBotCorpusTrainer(bot)

corpus_path='C:/Users/716926/Downloads/chatterbot-corpus-master/chatterbot-corpus-master/chatterbot_corpus/data/english/'

for file in os.listdir(corpus_path):
trainer.train(corpus_path + file)

while True:
message = input('You:')
print(message)
if message.strip() == 'Bye':
print('ChatBot: Bye')
break
else:
reply = bot.get_response(message)
print('ChatBot:', reply)

(base) C:\Users\716926\Documents\hello>D:/Development_Avecto/Anaconda3/python.exe c:/Users/716926/Documents/hello/bot.py
D:\Development_Avecto\Anaconda3\lib\site-packages\sklearn\feature_extraction\text.py:17: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Mapping, defaultdict
[nltk_data] Error loading averaged_perceptron_tagger: <urlopen error
[nltk_data] Tunnel connection failed: 407 Proxy Authorization
[nltk_data] Required>
[nltk_data] Error loading punkt: <urlopen error Tunnel connection
[nltk_data] failed: 407 Proxy Authorization Required>
[nltk_data] Error loading stopwords: <urlopen error Tunnel connection
[nltk_data] failed: 407 Proxy Authorization Required>
Training ai.yml: [####################] 100%
Training botprofile.yml: [####################] 100%
Training computers.yml: [####################] 100%
Training conversations.yml: [####################] 100%
Training emotion.yml: [####################] 100%
Training food.yml: [####################] 100%
Training gossip.yml: [####################] 100%
Training greetings.yml: [####################] 100%
Training health.yml: [####################] 100%
Training history.yml: [####################] 100%
Training humor.yml: [####################] 100%
Training literature.yml: [####################] 100%
Training money.yml: [####################] 100%
Training movies.yml: [####################] 100%
Training politics.yml: [####################] 100%
Training psychology.yml: [####################] 100%
Training science.yml: [####################] 100%
Training sports.yml: [####################] 100%
Training trivia.yml: [####################] 100%
You:hello
hello
No value for search_text was available on the provided input
ChatBot: Hi there!
You:what are you doing
what are you doing
No value for search_text was available on the provided input
ChatBot: I'm doing great.
You:what you ate
what you ate
No value for search_text was available on the provided input
ChatBot: I consume RAM, and binary digits.

I am getting an extra line That "No value for search_text was available on the provided input" can you help me with that

@gunthercox
Copy link
Owner

Sure, that output (No value for search_text was available on the provided input) is just logging information. The logging level can be changed like this:

import logging
logger = logging.getLogger()
logger.setLevel(logging.ERROR)

You can add these lines to the top of your program.

@bufferbox
Copy link

bufferbox commented Feb 13, 2019

This is my code:
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."
]

trainer = ListTrainer(chatbot)
trainer.train(conversation)

This is the error:
Traceback (most recent call last):
File "C:/Users/zarai/OneDrive/Documents/KACST/BobBot/newchatbot.py", line 13, in
trainer = ListTrainer(chatbot)
NameError: name 'chatbot' is not defined

Python version: 3.7.2
Chatterbot version: 0.8.7

Why does ListTrainer not work? I have tried many different solutions but nothing works. Sometimes ListTrainer downloads only 14% and then it quits with an error.

@bufferbox
Copy link

Thank you, solved.

@mady143
Copy link

mady143 commented Feb 20, 2019

HI,

I am facing an issue regarding set_trainer in chatterbot please check the bellow code if their is any error please let me know

from flask import Flask, render_template
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer

app = Flask(name)

english_bot = ChatBot("Chatterbot", storage_adapter="chatterbot.storage.SQLStorageAdapter")

english_bot.set_trainer(ListTrainer)
english_bot.train("./data")

@app.route("/")
def home():
return render_template("index.html")

@app.route("/get")
def get_bot_response():
userText = request.args.get('msg')
return str(english_bot.get_response(userText))

if name == "main":
app.run()

from flask import Flask, render_template, request

from chatterbot import ChatBot

from chatterbot.trainers import ChatterBotCorpusTrainer

app = Flask(name)

english_bot = ChatBot("Chatterbot", storage_adapter="chatterbot.storage.SQLStorageAdapter")

english_bot.set_trainer(ChatterBotCorpusTrainer)

english_bot.train("./data")

@app.route("/")

def home():

return render_template("index.html")

@app.route("/get")

def get_bot_response():

userText = request.args.get('msg')

return str(english_bot.get_response(userText))

if name == "main":

app.run()

Thank you in Advance

@gunthercox
Copy link
Owner

@mady143 Please see this comment for an example of how to change your training code:
#1555 (comment)

@Mourey2277
Copy link

This is my code

from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
from chatterbot.trainers import ChatterBotCorpusTrainer
import os

bot=ChatBot('Bot')
bot.set_trainer(ListTrainer)

for files in os.listdir('C:\chatterbot-corpus-1.2.0\chatterbot_corpus\data\english/'):
data= open('C:\chatterbot-corpus-1.2.0\chatterbot_corpus\data\english/' + files,'r').readlines()
bot.train(data)
while True:
message=input('you:')
if message.strip()!='bye':
reply= bot.get_response(message)
print('ChatBot :',reply)
if message.strip()=='bye':
print('ChatBot: bye')
break

@gunthercox can you please help me with the error(AttributeError: 'ChatBot' object has no attribute 'set_trainer')

from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
import os

bot = ChatBot('Bot')
#trainer = ChatterBotCorpusTrainer(ChatBot)
#trainer.train("chatterbot.corpus.english")

trainer = ListTrainer(bot)

for files in os.listdir('C:/Users/Era/Desktop/Chat/chatterbot-corpus-master/chatterbot-corpus-master/chatterbot_corpus/data/english/'):
data=open('C:/Users/Era/Desktop/Chat/chatterbot-corpus-master/chatterbot-corpus-master/chatterbot_corpus/data/english/' + files, 'r').readlines()
trainer.train(data)

while True:
message = input('You:')
if message.strip()!= 'Bye' :
reply = bot.get_response(message)
print('ChatBot :', reply)
if message.strip() == 'Bye':
print('ChatBot: Bye')
break

@pathapatisivayya
Copy link

Hi,
Just after installing ChatterBot ( version is 1.0.0a3.) , I tried to execute the following code snippet from quick start guide:

from chatterbot import ChatBot
chatbot = ChatBot("Ron Obvious")
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)

It failed to execute with the error, " AttributeError: 'ChatBot' object has no attribute 'set_trainer' ". I couldn't find any other post related to this attribute either.
I skimmed through the code of chatterbot.py and found ChatBot indeed has neither 'set_trainer' nor 'train' function.
Am I missing something here? I would really appreciate if anybody could help me here.
Thanks,

hi bro

i am also same issue facing but fix this error

please following solve error steps:
Flask==0.12.3
chatterbot==0.8.4
SQLAlchemy==1.1.11

install same version packages

issue is solved .....

@pathapatisivayya
Copy link

This is my code
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
from chatterbot.trainers import ChatterBotCorpusTrainer
import os
bot=ChatBot('Bot')
bot.set_trainer(ListTrainer)
for files in os.listdir('C:\chatterbot-corpus-1.2.0\chatterbot_corpus\data\english/'):
data= open('C:\chatterbot-corpus-1.2.0\chatterbot_corpus\data\english/' + files,'r').readlines()
bot.train(data)
while True:
message=input('you:')
if message.strip()!='bye':
reply= bot.get_response(message)
print('ChatBot :',reply)
if message.strip()=='bye':
print('ChatBot: bye')
break
@gunthercox can you please help me with the error(AttributeError: 'ChatBot' object has no attribute 'set_trainer')

from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
import os

bot = ChatBot('Bot')
#trainer = ChatterBotCorpusTrainer(ChatBot)
#trainer.train("chatterbot.corpus.english")

trainer = ListTrainer(bot)

for files in os.listdir('C:/Users/Era/Desktop/Chat/chatterbot-corpus-master/chatterbot-corpus-master/chatterbot_corpus/data/english/'):
data=open('C:/Users/Era/Desktop/Chat/chatterbot-corpus-master/chatterbot-corpus-master/chatterbot_corpus/data/english/' + files, 'r').readlines()
trainer.train(data)

while True:
message = input('You:')
if message.strip()!= 'Bye' :
reply = bot.get_response(message)
print('ChatBot :', reply)
if message.strip() == 'Bye':
print('ChatBot: Bye')
break

hi !

i am also same issue facing but fix this error

please following solve error steps:
Flask==0.12.3
chatterbot==0.8.4
SQLAlchemy==1.1.11

install same version packages

issue is solved .....

@pathapatisivayya
Copy link

Hi,
Just after installing ChatterBot ( version is 1.0.0a3.) , I tried to execute the following code snippet from quick start guide:

from chatterbot import ChatBot
chatbot = ChatBot("Ron Obvious")
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)

It failed to execute with the error, " AttributeError: 'ChatBot' object has no attribute 'set_trainer' ". I couldn't find any other post related to this attribute either.
I skimmed through the code of chatterbot.py and found ChatBot indeed has neither 'set_trainer' nor 'train' function.
Am I missing something here? I would really appreciate if anybody could help me here.
Thanks,

hi bro

i am also same issue facing but fix this error

please following solve error steps:
Flask==0.12.3
chatterbot==0.8.4
SQLAlchemy==1.1.11

install same version packages

issue is solved .....

@pathapatisivayya
Copy link

HI,

I am facing an issue regarding set_trainer in chatterbot please check the bellow code if their is any error please let me know

from flask import Flask, render_template
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer

app = Flask(name)

english_bot = ChatBot("Chatterbot", storage_adapter="chatterbot.storage.SQLStorageAdapter")

english_bot.set_trainer(ListTrainer)
english_bot.train("./data")

@app.route("/")
def home():
return render_template("index.html")

@app.route("/get")
def get_bot_response():
userText = request.args.get('msg')
return str(english_bot.get_response(userText))

if name == "main":
app.run()

from flask import Flask, render_template, request

from chatterbot import ChatBot

from chatterbot.trainers import ChatterBotCorpusTrainer

app = Flask(name)

english_bot = ChatBot("Chatterbot", storage_adapter="chatterbot.storage.SQLStorageAdapter")

english_bot.set_trainer(ChatterBotCorpusTrainer)

english_bot.train("./data")

@app.route("/")

def home():

return render_template("index.html")

@app.route("/get")

def get_bot_response():

userText = request.args.get('msg')

return str(english_bot.get_response(userText))

if name == "main":

app.run()

Thank you in Advance

hi bro

i am also same issue facing but fix this error

please following solve error steps:
Flask==0.12.3
chatterbot==0.8.4
SQLAlchemy==1.1.11

install same version packages

issue is solved .....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

11 participants