gunthercox/chatterbot-corpus

Getting error: AttributeError: 'str' object has no attribute 'storage'

kbose02 opened this issue ยท 9 comments

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'

I am using the latest version of chatterbot
C:\Users\XXX>python -m chatterbot --version
1.0.0

Hi @kbose02, I made a few changes to your code, try this:

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

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

corpus_path = 'C:/Users/XXX/Desktop/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)

Also, please make sure to download the latest copy of the corpus data. I have made changes that fix a few lines of invalid data.

Thanks.. I am able to run the bot now.
However, the following line always keeps coming up "No value for search_text was available on the provided input". Any idea how to suppress this.
++++++++++++
You:Hi
Hi
No value for search_text was available on the provided input
ChatBot: How are you doing?
You:I am doing fine
I am doing fine
No value for search_text was available on the provided input
ChatBot: Good Morning
You:Hello
Hello
++++++++++++

Similar to @capaximperii's response in gunthercox/ChatterBot#1589, you can set the following logging level to suppress that warning.

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

Hi @kbose02, I made a few changes to your code, try this:

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

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

corpus_path = 'C:/Users/XXX/Desktop/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)

Also, please make sure to download the latest copy of the corpus data. I have made changes that fix a few lines of invalid data.

While im running your code im getting this error

[nltk_data] Downloading package averaged_perceptron_tagger to
[nltk_data] /home/devraj/nltk_data...
[nltk_data] Package averaged_perceptron_tagger is already up-to-
[nltk_data] date!
[nltk_data] Downloading package punkt to /home/devraj/nltk_data...
[nltk_data] Package punkt is already up-to-date!
[nltk_data] Downloading package stopwords to /home/devraj/nltk_data...
[nltk_data] Package stopwords is already up-to-date!
Traceback (most recent call last):
File "chatbot_train.py", line 11, in
trainer.train(corpus_path + file)
File "/usr/local/lib/python3.5/dist-packages/chatterbot/trainers.py", line 130, in train
from chatterbot.corpus import load_corpus, list_corpus_files
File "/usr/local/lib/python3.5/dist-packages/chatterbot/corpus.py", line 4, in
import yaml
File "/usr/local/lib/python3.5/dist-packages/yaml/init.py", line 2, in
from error import *
ImportError: No module named 'error'

why i am getting no module error?

import yaml
File "/usr/local/lib/python3.5/dist-packages/yaml/init.py", line 2, in
from error import *
ImportError: No module named 'error'

why i am getting no module error?

I am not sure, this is not an error that I have encountered before. However, I was able to Google the error message that you encountered, and I found this Sack Overflow answer that look like it might help explain the error that you are seeing: https://stackoverflow.com/a/50868994/1547223

I hope this helps.

hey @gunthercox

I'm getting an error " No module named 'chatterbot_corpus' " for the same code.

Hi @gopal-prasath This solution from a similar issue might resolve your error: #127 (comment)

hey @gunthercox

I'm getting an error " No module named 'chatterbot_corpus' " for the same code.

Try to install chatterbot-corpus manually using following command
pip3 install chatterbot-corpus