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

Fix the problem of loading spacy model #2260

Closed
wants to merge 1 commit into from
Closed

Fix the problem of loading spacy model #2260

wants to merge 1 commit into from

Conversation

hikariyo
Copy link

When I run the simple demo on our website:

from chatterbot import ChatBot
chatbot = ChatBot("Ron Obvious")

I will get this exception trace:

Traceback (most recent call last):
  File "main.py", line 2, in <module>
    chatbot = ChatBot("Ron Obvious")
  File "C:\local\tools\python37\lib\site-packages\chatterbot\chatterbot.py", line 28, in __init__
    self.storage = utils.initialize_class(storage_adapter, **kwargs)
  File "C:\local\tools\python37\lib\site-packages\chatterbot\utils.py", line 33, in initialize_class
    return Class(*args, **kwargs)
  File "C:\local\tools\python37\lib\site-packages\chatterbot\storage\sql_storage.py", line 20, in __init__
    super().__init__(**kwargs)
  File "C:\local\tools\python37\lib\site-packages\chatterbot\storage\storage_adapter.py", line 21, in __init__
    "tagger_language", languages.ENG
  File "C:\local\tools\python37\lib\site-packages\chatterbot\tagging.py", line 18, in __init__
    self.nlp = spacy.load(self.language.ISO_639_1.lower())
  File "C:\local\tools\python37\lib\site-packages\spacy\__init__.py", line 60, in load
    config=config,
  File "C:\local\tools\python37\lib\site-packages\spacy\util.py", line 435, in load_model
    raise IOError(Errors.E941.format(name=name, full=OLD_MODEL_SHORTCUTS[name]))  # type: ignore[index]
OSError: [E941] Can"t find model "en". It looks like you"re trying to load a model from a shortcut, which is obsolete 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")

According to https://spacy.io/models, using model shortcuts like "en" is obsolete as of spaCy v3.0.
And the solution is adding a postfix "_core_web_sm" after the language name.
So I simply fix this bug by adding a except block:

name = self.language.ISO_639_1.lower()
try:
    self.nlp = spacy.load(name)
except:
    self.nlp = spacy.load(name + "_core_web_sm")

There are already solution under issue #2194 #2139, but they can only fix the errors when using English.

@hikariyo hikariyo closed this by deleting the head repository Nov 2, 2022
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

Successfully merging this pull request may close these issues.

1 participant