如何解决en_coref_lg 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 en_coref_lg
安装-m spacy download en_coref_lg
,则会显示
"✘ No compatible model found for 'en_coref_lg' (spaCy v2.3.2)."
我该怎么办?
解决方法
安装neuralcoref
和spacy==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]]
请注意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]]
,
尝试像这样使用它:
import en_coref_md
nllp=en_coref_md.load()
我认为应该可以。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。