问题
运行代码:
TEXT = data.Field(tokenize='spacy')
LABEL = data.LabelField(dtype=torch.float)
报错:
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")
原因:调用spacy的时候token_language默认是en,而需要的是en_core_web_sm,所以修改这个就好了。
解决办法
使用Anaconda Prompt (Anaconda3)终端,激活pytorch环境,安装en_core_web_sm。
1.如果尚未安装spacy,先安装spacy,执行如下命令:
pip install spacy
2.安装en_core_web_sm,“en_core_web_sm-3.0.0”后面的3.0.0是版本号。
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.修改代码,如下:
TEXT = data.Field(tokenize='spacy',tokenizer_language='en_core_web_sm')
LABEL = data.LabelField(dtype=torch.float)
完成如上命令,即可。