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

9

10

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 import ChatBot
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.

Chickadee answered 7/2, 2021 at 11:41 Comment(2)
One of the possible solutions is to downgrade spacy to a version 2.x, like pip install -U spacy==2.1.3Erythema
You may need to do python -m spacy download en_core_web_sm before using it.Sunglasses
C
17

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.

Cusped answered 7/2, 2021 at 12:32 Comment(2)
Gracias gran ayuda!Wooster
@EzequielMiceli De nada!Erythema
R
4

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")

Ranna answered 11/2, 2021 at 2:1 Comment(1)
I'm still having this same issue. I think the best thing to do [as of time of writing] is to downgrade to a lower version of spacy (maybe to version 2.1.3). Then redownload en_core_web_sm by using this command python -m spacy download en_core_web_sm. This should give you en_core_web_sm==2.1.0 and then you can apply the linking (i.e python -m spacy link en_core_web_sm en)Immanuel
C
4

In addition to the other comments, please be aware of an issue with SpaCy 3.0.3 and Python 3.8 - if these are the versions you're using, you may have to download the language model via Python shell, ex.:

import spacy
from spacy.cli.download import download
download(model="en_core_web_sm")

For these versions, downloading via python -m spacy download en_core_web_sm may result in exceptions - as described ex. here.

Calculus answered 9/3, 2021 at 10:44 Comment(0)
P
0

First, you need to download en_core_web_sm by running: python -m spacy download en_core_web_sm

You need to modify the following code.

enter image description here

Pyszka answered 27/2, 2021 at 10:14 Comment(0)
R
0

Try just install the spacy with >>pip install -U spacy

And change the code

self.nlp = spacy.load(self.language.ISO_639_1.lower()) 

in "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\tagging.py" 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()) 

Get work for me here and I had the same problem

Revivify answered 18/3, 2021 at 18:58 Comment(0)
U
0

For Linux and Mac users :

To the above top-voted answer I will add that the location of tagging.py is :

/usr/local/lib/python3.7/site-packages/chatterbot

To be more precise :

<Install_path_of_Python>/site-packages/chatterbot

( The install path could be your virtual environment path as well )

Unguent answered 27/2, 2022 at 17:16 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Leasia
W
0

Try just install the spacy with pip install -U spacy

And change the code

self.nlp = spacy.load(self.language.ISO_639_1.lower()) 

in C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\tagging.py 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()) 
Woodchuck answered 16/8, 2022 at 16:46 Comment(0)
P
0

if downloading the package doesn't work as follows:

python -m spacy download en_core_web_sm

then you don't need to change the code in the package, just change the cause.

from chatterbot import languages

languages.ENG.ISO_639_1 = "en_core_web_sm"

it will change "en" to "en_core_web_sm" for spacy

Pneumatics answered 13/11, 2022 at 15:37 Comment(0)
B
0

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.

It is working for me, I recommended this!

Bainbridge answered 4/6, 2023 at 16:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.