解决spacy3.2报错:Can‘t find model ‘en‘.

本文涉及的产品
NLP自然语言处理_高级版,每接口累计50万次
NLP 自学习平台,3个模型定制额度 1个月
NLP自然语言处理_基础版,每接口每天50万次
简介: (1)下载spacy一直没成功,把pip install spacy改成conda install spacy就可以了;(2)在命令行输入 python3 -m spacy download en 来下载英语语言包(如果是其他语言则下载其他包了),不过en现在最好用全称en_core_web_sm,这一步也可以先下载tar再pip install en_core_web_md-2.2.5.tar.gz(但是注意把文件放对路径)。然后测试下代码:

(1)下载spacy一直没成功,把pip install spacy改成conda install spacy就可以了;

(2)在命令行输入 python3 -m spacy download en 来下载英语语言包(如果是其他语言则下载其他包了),不过en现在最好用全称en_core_web_sm,这一步也可以先下载tar再pip install en_core_web_md-2.2.5.tar.gz(但是注意把文件放对路径)。

然后测试下代码:

import spacy
import nltk
# load spacy's English-language models
en_nlp = spacy.load('en')
# instantiate nltk's Porter stemmer
stemmer = nltk.stem.PorterStemmer()
# define function to compare lemmatization in spacy with stemming in nltk
def compare_normalization(doc):
    # tokenize document in spacy
    doc_spacy = en_nlp(doc)
    # print lemmas found by spacy
    print("Lemmatization:")
    print([token.lemma_ for token in doc_spacy])
    # print tokens found by Porter stemmer
    print("Stemming:")
    print([stemmer.stem(token.norm_.lower()) for token in doc_spacy])

发现又报错:

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

是说上面load model的方法是spacy 3.0版本以前才这么用的,要改成nlp = spacy.load("en_core_web_sm"),然后就ok了,得到对应的spacy中的词形还原与nltk中的词干提取的对比结果:

Lemmatization:
['our', 'meeting', 'today', 'be', 'bad', 'than', 'yesterday', ',', 'I', 'be', 'scared', 'of', 'meet', 'the', 'client', 'tomorrow', '.']
Stemming:
['our', 'meet', 'today', 'wa', 'wors', 'than', 'yesterday', ',', 'i', 'am', 'scare', 'of', 'meet', 'the', 'client', 'tomorrow', '.']
相关文章
|
4月前
|
Python
【Python】解决Can‘t find model ‘en‘. It doesn‘t seem to be a shortcut link, a Python package or a valid
在使用以下代码时,报错Can’t find model ‘en’. It doesn’t seem to be a shortcut link, a Python package or a valid path to a data directory.
66 1
|
7月前
|
编解码 算法 Python
ImportError: cannot import name ‘_update_worker_pids’ from ‘torch._C’
ImportError: cannot import name ‘_update_worker_pids’ from ‘torch._C’
96 0
|
5月前
|
XML 移动开发 数据格式
【Python】已解决:bs4.FeatureNotFound: Couldn’t find a tree builder with the features you requested: html5
【Python】已解决:bs4.FeatureNotFound: Couldn’t find a tree builder with the features you requested: html5
492 1
|
Docker 容器
求助: 运行模型时报错module 'megatron_util.mpu' has no attribute 'get_model_parallel_rank'
运行ZhipuAI/Multilingual-GLM-Summarization-zh的官方代码范例时,报错AttributeError: MGLMTextSummarizationPipeline: module 'megatron_util.mpu' has no attribute 'get_model_parallel_rank' 环境是基于ModelScope官方docker镜像,尝试了各个版本结果都是一样的。
422 5
|
Python
Python报错ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Python报错ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
1728 1
|
API 数据格式
TensorFlow2._:model.summary() Output Shape为multiple解决方法
TensorFlow2._:model.summary() Output Shape为multiple解决方法
288 0
TensorFlow2._:model.summary() Output Shape为multiple解决方法
|
PyTorch 算法框架/工具 异构计算
Pytorch出现RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor)
这个问题的主要原因是输入的数据类型与网络参数的类型不符。
673 0
python报错bs4.FeatureNotFound: Couldn‘t find a tree builder with the features you requested: lxml.
python报错bs4.FeatureNotFound: Couldn‘t find a tree builder with the features you requested: lxml.
|
自然语言处理 Python
解决spacy3.2报错:Can‘t find model ‘en‘.
(1)下载spacy一直没成功,把pip install spacy改成conda install spacy就可以了;
921 0