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

简介: (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', '.']
相关文章
|
5月前
|
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镜像,尝试了各个版本结果都是一样的。
286 5
|
7月前
|
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().
|
图形学
错误提示: "InfraWorks is unable to render your model" when trying to load a model
错误提示: "InfraWorks is unable to render your model" when trying to load a model
错误提示: "InfraWorks is unable to render your model" when trying to load a model
Re1:读论文 C&S (Correct and Smooth) Combining Label Propagation and Simple Models Out-performs Graph Ne
Re1:读论文 C&S (Correct and Smooth) Combining Label Propagation and Simple Models Out-performs Graph Ne
Re1:读论文 C&S (Correct and Smooth) Combining Label Propagation and Simple Models Out-performs Graph Ne
|
数据可视化
JavaFx - 史上最直观的 JavaFx 布局讲解(超多图)BorderPane、StackPane、GridPane、FlowPane、SplitPane、TabPane、AnchorPane等
JavaFx - 史上最直观的 JavaFx 布局讲解(超多图)BorderPane、StackPane、GridPane、FlowPane、SplitPane、TabPane、AnchorPane等
804 0
JavaFx - 史上最直观的 JavaFx 布局讲解(超多图)BorderPane、StackPane、GridPane、FlowPane、SplitPane、TabPane、AnchorPane等
|
自然语言处理 Python
解决spacy3.2报错:Can‘t find model ‘en‘.
(1)下载spacy一直没成功,把pip install spacy改成conda install spacy就可以了;
856 0
how to find the original page containing a given image
how to find the original page containing a given image
how to find the original page containing a given image
GET_PERS_LIST_4_CONFIG_ID (UI2CL_WD_CFG_UTILS)
Created by Wang, Jerry, last modified on Apr 21, 2015
108 0
GET_PERS_LIST_4_CONFIG_ID (UI2CL_WD_CFG_UTILS)
Cannot find source code based button in SE24
When you are logging on to customer system for incident handling, you want to switch to source code to perform some keyword search. However, you could not find button “Source code based builder” in toolbar, with following warning message: ———————————————— 版权声明:本文为CSDN博主「汪子熙」的原创文章,遵循CC 4.0 BY-SA版权协
Cannot find source code based button in SE24
GM6 pageset - Cache get scenario /ui2/cl_pfcg_utils
Created by Wang, Jerry, last modified on Apr 20, 2015
124 0
GM6 pageset - Cache get scenario /ui2/cl_pfcg_utils