0

嗨,我正在 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"

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

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

我应该怎么办 ?

4

2 回答 2

0

安装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]]
于 2020-08-31T20:40:39.727 回答
-1

尝试像这样使用它:

import en_coref_md
nllp=en_coref_md.load()

我认为它应该有效。

于 2020-12-13T09:40:16.113 回答