ChatterBot icon indicating copy to clipboard operation
ChatterBot copied to clipboard

chatterbot 1.0.8 incompatible with spacy 3.0.0

Open carpediemmlf opened this issue 4 years ago • 14 comments

Python 3.7.3 (default, Jul 25 2020, 13:03:44) File "test.py", line 4, in chatbot = ChatBot('Ron Obvious') File "/home/pi/.local/lib/python3.7/site-packages/chatterbot/chatterbot.py", line 28, in init self.storage = utils.initialize_class(storage_adapter, **kwargs) File "/home/pi/.local/lib/python3.7/site-packages/chatterbot/utils.py", line 33, in initialize_class return Class(*args, **kwargs) File "/home/pi/.local/lib/python3.7/site-packages/chatterbot/storage/sql_storage.py", line 20, in init 'tagger_language', languages.ENG File "/home/pi/.local/lib/python3.7/site-packages/chatterbot/tagging.py", line 13, in init self.nlp = spacy.load(self.language.ISO_639_1.lower()) File "/home/pi/.local/lib/python3.7/site-packages/spacy/init.py", line 47, in load return util.load_model(name, disable=disable, exclude=exclude, config=config) File "/home/pi/.local/lib/python3.7/site-packages/spacy/util.py", line 328, in load_model raise IOError(Errors.E941.format(name=name, full=OLD_MODEL_SHORTCUTS[name])) OSError: [E941] Can't find model 'en'. It looks like you're trying to load a model from a shortcut, which is deprecated as of spaCy v3.0. To load the model, use its full name instead:

nlp = spacy.load("en_core_web_sm")

For more details on the available models, see the models directory: https://spacy.io/models. If you want to create a blank model, use spacy.blank: nlp = spacy.blank("en")

carpediemmlf avatar Feb 14 '21 23:02 carpediemmlf

Well... I talk whit spacy and tell me that. .

The problem here seems to be that Chatterbot hard-codes spacy.load("en") in its code, specifically in chatterbot/tagging.py. In spaCy v3, loading a model from a shortcut like en is deprecated, because this usage is misleading: there are many different en or es models, so it should always be clear which package is being loaded. For example, en_core_web_sm or es_core_web_sm.

So this is something that needs to be updated by Chatterbot in the future to support the new spaCy v3.

In the meantime, you can install spaCy v2 that still supports the shortcuts:

pip install spacy==2.3.5

I install... but not response my chatterbot in the web... suposly is work this.... the problem is I am novato no programer... I am musician...

intercontoni avatar Feb 15 '21 01:02 intercontoni

Look...

Loaded compatibility table =====================
Installed models (spaCy v2.3.5
======================  
spaCy instalación

/home/xxxxx/virtualenv/toni/3.7/lib/python3.7/site-packages/spacy
TYPE      NAME              MODEL             VERSION             

package   es-core-news-sm
es_core_news_sm  2.3.1   ✔
package   en-core-web_sm
en_core_web_sm   2.3.1   ✔ 
link      en 
en_core_web_sm   2.3.1   ✔ 
link      es  
es_core_news_sm  2.3.1   ✔

I uses in ssh this..

for english

pip install spacy==2.3.5 pip install spacy en_core_web_sm --force

for spanish

pip install spacy==2.3.5 pip install spacy es_core_news_sm --force

But not instaled 2.3.5 is 2.3.1...--circe .

intercontoni avatar Feb 15 '21 03:02 intercontoni

2.3.1 still gives the same error for me. I guess it would easier to change the way chatterbot loads the corpus

fccoelho avatar Feb 24 '21 21:02 fccoelho

See first what spacy do you have whit...

python -m spacy validate

If have 3.0 used

pip install spacy==2.3.5 pip install spacy en_core_web_sm --force

And...

pip install spacy==2.3.5

intercontoni avatar Feb 24 '21 22:02 intercontoni

pip install spacy==2.3.5 en_core_web_sm
Collecting spacy==2.3.5
  Downloading spacy-2.3.5-cp36-cp36m-manylinux2014_x86_64.whl (10.4 MB)
     |████████████████████████████████| 10.4 MB 27 kB/s  eta 0:00:01
ERROR: Could not find a version that satisfies the requirement en_core_web_sm (from versions: none)
ERROR: No matching distribution found for en_core_web_sm

can't install en_core_web_sm via pip must install spacy first then run python -m spacy download en_core_web_sm

sugizo avatar Feb 28 '21 00:02 sugizo

Hey, dude try install spacy with >> pip install -U spacy

Before that, go to C:\python37\Lib\site-packages\chatterbot and open the file tagging.py and change the code self.nlp = spacy.load(self.language.ISO_639_1.lower())

To

if self.language.ISO_639_1.lower() == 'en': self.nlp = spacy.load('en_core_web_sm') else: self.nlp = spacy.load(self.language.ISO_639_1.lower())

try that ant tell me if work.

andre0shazam avatar Mar 18 '21 19:03 andre0shazam

Install with:

pip install spacy==2.1.8
python -m spacy download es

Since class PosLemmaTagger loads spacy from self.language and StorageAdapter creates an instance of PosLemmaTagger with tagger_language:

class PosLemmaTagger(object):
    def __init__(self, language=None):
        self.language = language or languages.ENG
        ...
        self.nlp = spacy.load(self.language.ISO_639_1.lower())
...

class StorageAdapter(object):
    ...
    def __init__(self, *args, **kwargs):
        ...
        self.tagger = PosLemmaTagger(language=kwargs.get(
            'tagger_language', languages.ENG
        ))
...

You can load the chatbot by passing the language as a parameter to the Storage adapter, like this:

chatbot = ChatBot(
    "MyBot",
    storage_adapter={
        'tagger_language': languages.SPA,
        'import_path': 'chatterbot.storage.SQLStorageAdapter',
        'database_uri': "...",
    },
...

thpereiras avatar Mar 21 '21 19:03 thpereiras

@andre0shazam gracias, tu solución funciono para mi.

camilacastrillongh avatar Mar 23 '21 20:03 camilacastrillongh

I ran into the same problem when I was trying the tutorial. I'm new to ChatterBot so I'm not sure exactly what is the best way to solve the problem.

However, I wanted to approach working around this issue without messing around with the source code until a fix is in place. After reviewing the code, it was as simple as setting up a custom language class with the new model naming convention so here is my take at a workaround:

from chatterbot import ChatBot


# adding language for compatibility with spacy 3.0
class ENGSM:
    ISO_639_1 = 'en_core_web_sm'


# Create a new instance of a ChatBot
bot = ChatBot(
    "MyTestBot",
    tagger_language=ENGSM     # <-- pass this new language here
)

print("Type something to begin...")

# The following loop will execute each time the user enters input
while True:
    try:
        user_input = input()
        bot_response = bot.get_response(user_input)
        print(bot_response)

    # Press ctrl-c or ctrl-d on the keyboard to exit
    except (KeyboardInterrupt, EOFError, SystemExit):
        break

karthicraghupathi avatar May 21 '21 20:05 karthicraghupathi

It would be great for somebody to slap together a pull request for this

xloem avatar Oct 14 '21 18:10 xloem

I have fixed the issue on pull request, please take a look on it and if everything seems okay, proceed with supporting this code to be included in next releases, and of course leave any suggestion or comment there so I can improve or fix anything you find

Diego448 avatar Nov 24 '21 23:11 Diego448

It's been over a year, the issue still persists in the latest version, and the PR is waiting for checks. What's up with the pipeline? :thinking:

rubenhorn avatar Nov 16 '22 18:11 rubenhorn

It's been over a year, the issue still persists in the latest version, and the PR is waiting for checks. What's up with the pipeline? thinking

I have lost track of the documentation on how to setup and run the checks, if someone can point me to them I will gladly run those checks to submit the merge request.

Diego448 avatar Nov 20 '22 22:11 Diego448

Please fork this project if there is no progress here. There is so much free tech out there to make smart chatbots; people will need a place to integrate it.

xloem avatar Nov 20 '22 23:11 xloem