en_coref_lg spacy 中的模型

en_coref_lg model in spacy

您好,我正在 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 -m spacy download en_coref_lg 安装 en_coref_lg 然后它显示

"✘ No compatible model found for 'en_coref_lg' (spaCy v2.3.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()

我觉得应该可以。