An error occurred when using the spacy library OSError: [E941] Can't find model 'en'.

question

Run the code:

TEXT = data.Field(tokenize='spacy')
LABEL = data.LabelField(dtype=torch.float)

Error:

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

Reason: When calling spacy, the token_language defaults to en , but en_core_web_sm is needed , so just modify this.

Solution

Use the Anaconda Prompt (Anaconda3) terminal to activate the pytorch environment and install en_core_web_sm.

1. If spacy has not been installed, install spacy first and execute the following command:

pip install spacy

2. Install en_core_web_sm, 3.0.0 after "en_core_web_sm-3.0.0" is the version number.

pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.0.0/en_core_web_sm-3.0.0.tar.gz

3. Modify the code as follows:

TEXT = data.Field(tokenize='spacy',tokenizer_language='en_core_web_sm')
LABEL = data.LabelField(dtype=torch.float)

Complete the above command, you can.

Guess you like

Origin blog.csdn.net/cxzgood/article/details/124800670