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

chatterbot 1.0.8 incompatible with spacy 3.0.0 #2120

Open
carpediemmlf opened this issue Feb 14, 2021 · 14 comments
Open

chatterbot 1.0.8 incompatible with spacy 3.0.0 #2120

carpediemmlf opened this issue Feb 14, 2021 · 14 comments

Comments

@carpediemmlf
Copy link

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 carpediemmlf changed the title chatterbot 1.0.8 imcompatible with spacy 3.0.0 chatterbot 1.0.8 incompatible with spacy 3.0.0 Feb 14, 2021
@intercontoni
Copy link

intercontoni commented Feb 15, 2021

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
Copy link

intercontoni commented Feb 15, 2021

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 .

@fccoelho
Copy link

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

@intercontoni
Copy link

intercontoni commented Feb 24, 2021

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

@sugizo
Copy link

sugizo commented Feb 28, 2021

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

@andre0shazam
Copy link

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.

@thpereiras
Copy link

thpereiras commented Mar 21, 2021

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': "...",
    },
...

@camilacastrillongh
Copy link

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

@karthicraghupathi
Copy link

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

@xloem
Copy link

xloem commented Oct 14, 2021

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

@Diego448
Copy link

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

@rubenhorn
Copy link

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? 🤔

@Diego448
Copy link

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.

@xloem
Copy link

xloem commented Nov 20, 2022

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.

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

No branches or pull requests