python-3.x - 如何在 Spacy 中使用神经核函数

标签 python-3.x ubuntu spacy coreference-resolution

我一直在尝试使用库 neuralcoref :基于神经网络和 spaCy 的最先进的共指解析。我在 conda 1.9.7 和 Spacy 2.2.4 中使用 Ubuntu 16.04、Python 3.7.3。
我的代码(来自 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?

最佳答案

对于 neuralcoref要工作,您需要使用 spaCy 版本 2.1.0和 python 版本 3.7 .这是在 Ubuntu 16.04 和 Mac 上唯一适用于神经核的组合。

  • 在你的机器上安装 python 3.7,见 here
  • 确保选择的 python 版本是 3.7
  • 创建您的项目文件夹
  • 创建python virtual environment在你给定的项目文件夹中,python -m venv ./venv ,
  • 像这样安装 spaCy 2.1.0 python -m pip install spacy==2.1.0 .
  • 安装neuralcoref python -m pip install neuralcoref

  • 希望这可以帮助。

    运行上面的代码后,我得到以下输出:
    [My sister: [My sister, She], a dog: [a dog, him]]
    Angela: [Angela, She]
    Boston: [Boston, that city]
    

    关于python-3.x - 如何在 Spacy 中使用神经核函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62781349/

    相关文章:

    python - pytorch中的一项热门编码文本数据

    r - 使用 Quanteda 语料库识别名词

    python - Cx-卡住错误 - Python 34

    python - NER 训练循环中的损失不会在空间中减少

    python - 网络浏览器 'directory not found' 错误

    php - PHP 7.0 FastCGI 进程管理器启动失败

    ubuntu - sudo Kill 导致权限被拒绝

    linux - 在 Ubuntu 终端上使用 SHIFT+箭头(向左或向右)选择文本不起作用

    python - 在 PyQt5 中显示和隐藏多个窗口

    django - 如何使用用于日志记录的 Django 设置配置正确地使用 unittest 进行 assertLogs 测试?