空间中的en_-coref_-lg模型

2024-09-28 22:21:41 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我正在用python尝试一个简单的coref解析代码

import spacy
nlp = spacy.load('en_coref_md')
doc = nlp(u'Phone area code will be valid only when all the below conditions are met. It cannot be left blank. It should be numeric. It cannot be less than 200. Minimum number of digits should be 3. ')
print(doc._.coref_clusters)
print(doc._.coref_resolved)

它显示以下错误:

"OSError: [E050] Can't find model 'en_coref_lg'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data"

如果我尝试使用python安装en_coref_lg,那么它会显示

"✘ No compatible model found for 'en_coref_lg' (spaCy v2.3.2)."

我该怎么办


Tags: to代码docmodelnlpspacyitbe
2条回答

安装neuralcorefspacy==2.1.0

pip uninstall spacy 
pip uninstall neuralcoref
pip install spacy==2.1.0 
pip install neuralcoref  no-binary neuralcoref

运行您的代码:

import spacy
import neuralcoref
nlp = spacy.load('en_core_web_md')
neuralcoref.add_to_pipe(nlp)
doc = nlp(u'Phone area code will be valid only when all the below conditions are met. It cannot be left blank. It should be numeric. It cannot be less than 200. Minimum number of digits should be 3.')
print(doc._.has_coref)
print(doc._.coref_clusters)
True
[Phone area code: [Phone area code, It, It, It]]

请注意spacy==2.1.0的版本。如果要使用pip安装,则需要此选项

或者,从源代码生成:

git clone https://github.com/huggingface/neuralcoref.git
cd neuralcoref
pip install -r requirements.txt # check for the desired spacy version
python setup.py install

证明:

import spacy
import neuralcoref
nlp = spacy.load('en_core_web_md')
neuralcoref.add_to_pipe(nlp)
print(spacy.__version__)
doc = nlp(u'Phone area code will be valid only when all the below conditions are met. It cannot be left blank. It should be numeric. It cannot be less than 200. Minimum number of digits should be 3.')
print(doc._.has_coref)
print(doc._.coref_clusters)
2.3.2
True
[Phone area code: [Phone area code, It, It, It]]

试着像这样使用它:

import en_coref_md
nllp=en_coref_md.load()

我觉得应该行得通

相关问题 更多 >