如何在Spacy中使用Neursiref [英] How to use neuralcoref in Spacy
本文介绍了如何在Spacy中使用Neursiref的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试使用neuralcoref
库neuralcoref
:基于神经网络和Spacy的最先进的共指解析。我使用的是Ubuntu 16.04、Conda 1.9.7中的Python 3.7.3和Spacy 2.2.4。
我的代码(来自https://spacy.io/universe/project/neuralcoref):
import spacy
import neuralcoref
nlp = spacy.load('en_core_web_sm')
neuralcoref.add_to_pipe(nlp)
doc1 = nlp('My sister has a dog. She loves him.')
print(doc1._.coref_clusters)
doc2 = nlp('Angela lives in Boston. She is quite happy in that city.')
for ent in doc2.ents:
print(ent._.coref_cluster)
我收到此错误
/home/daniel/anaconda3/lib/python3.7/importlib/_bootstrap.py:219: RuntimeWarning: spacy.morphology.Morphology size changed, may indicate binary incompatibility. Expected 104 from C header, got 112 from PyObject
return f(*args, **kwds)
/home/daniel/anaconda3/lib/python3.7/importlib/_bootstrap.py:219: RuntimeWarning: spacy.vocab.Vocab size changed, may indicate binary incompatibility. Expected 96 from C header, got 104 from PyObject
return f(*args, **kwds)
/home/daniel/anaconda3/lib/python3.7/importlib/_bootstrap.py:219: RuntimeWarning: spacy.tokens.span.Span size changed, may indicate binary incompatibility. Expected 72 from C header, got 80 from PyObject
return f(*args, **kwds)
我已尝试按照link的建议将Spacy的版本降级到2.1.0:
conda config --append channels conda-forge
conda install spacy=2.1.0
但是,我无法
PackagesNotFoundError: The following packages are not available from current channels:
- spacy=2.1.0
Current channels:
- https://conda.anaconda.org/conda-forge/linux-64
- https://conda.anaconda.org/conda-forge/noarch
- https://repo.anaconda.com/pkgs/main/linux-64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/r/linux-64
- https://repo.anaconda.com/pkgs/r/noarch
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
我如何才能在不降级的情况下解决此问题?是否有新的更新版本?
推荐答案
要使neuralcoref
正常工作,您需要使用Spacy版本2.1.0
和python版本3.7
。这是在Ubuntu 16.04和Mac上唯一可以使用的组合。
- 在您的机器上安装Python3.7,请参阅here
- 确保所选的Python版本为3.7
- 创建项目文件夹
- 在给定的项目文件夹中创建一个pythonvirtual environment,
python -m venv ./venv
, - 按如下方式安装Spacy 2.1.0
python -m pip install spacy==2.1.0
。 - 安装神经参考
python -m pip install neuralcoref
希望这能有所帮助。
运行上面的代码后,我得到以下输出:
[My sister: [My sister, She], a dog: [a dog, him]]
Angela: [Angela, She]
Boston: [Boston, that city]
这篇关于如何在Spacy中使用Neursiref的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文