Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ChatterBot error- OSError: [E941] Can't find model 'en'

I tried running my first Chatterbot program (its from the PyPi page of Chatterbot), and when I run it, I get an error. The error is related to Spacy, but I am unable to find a solution.

Here is the code:

from chatterbot.trainers import ChatterBotCorpusTrainer

chatbot = ChatBot('Ron Obvious')

trainer = ChatterBotCorpusTrainer(chatbot)

trainer.train("chatterbot.corpus.english")

chatbot.get_response("Hello, how are you today?")

And here is the error:

Traceback (most recent call last):
  File "c:/users/USER/desktop/bot.py", line 77, in <module>
    chatbot = ChatBot('Ron Obvious')
  File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\chatterbot.py", line 28, in __init__
    self.storage = utils.initialize_class(storage_adapter, **kwargs)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\utils.py", line 33, in initialize_class
    return Class(*args, **kwargs)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\storage\sql_storage.py", line 20, in __init__
    super().__init__(**kwargs)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\storage\storage_adapter.py", line 21, in __init__
    'tagger_language', languages.ENG
  File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\tagging.py", line 13, in __init__
    self.nlp = spacy.load(self.language.ISO_639_1.lower())
  File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\spacy\__init__.py", line 47, in load
    return util.load_model(name, disable=disable, exclude=exclude, config=config)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\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")

It would be helpful if someone finds a solution for this. Thanks.

like image 899
su2187 Avatar asked Feb 07 '21 11:02

su2187


2 Answers

Make sure you actually have the right spacy model installed. For example, install en_core_web_sm with the python -m spacy download en_core_web_sm command in the terminal.

Next, fix this error:

File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\tagging.py", line 13, in __init__
    self.nlp = spacy.load(self.language.ISO_639_1.lower())

That is,

  1. Open the C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\tagging.py file
  2. Go to Line 13
  3. Replace self.nlp = spacy.load(self.language.ISO_639_1.lower()) with
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())

You will need to add more conditions for other languages you need to support.

like image 196
Wiktor Stribiżew Avatar answered Oct 07 '22 01:10

Wiktor Stribiżew


Check the version of spacy you are using.

Install spacy and download the language model, en_core_web_sm, in this case using

 python -m spacy download en_core_web_sm

If it is v3.0, you will need to load it using

nlp = spacy.load("en_core_web_sm")

If it is < v3.0, you can link the model creating a shortcut using

python -m spacy link en_core_web_sm en

and thus load it using nlp = spacy.load("en")

like image 20
Subigya Upadhyay Avatar answered Oct 07 '22 01:10

Subigya Upadhyay