首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Colab中使用NeuralCoref的属性错误

Colab中使用NeuralCoref的属性错误
EN

Stack Overflow用户
提问于 2020-04-17 10:56:59
回答 4查看 3.5K关注 0票数 3

我试图在colab中使用以下spacy模块:

https://spacy.io/universe/project/neuralcoref

我安装了以下软件包:

代码语言:javascript
运行
复制
!pip install spacy
import spacy 
!pip show spacy

!git clone https://github.com/huggingface/neuralcoref.git
import neuralcoref

安装后得到以下输出:

代码语言:javascript
运行
复制
Name: spacy
Version: 2.2.4
Summary: Industrial-strength Natural Language Processing (NLP) in Python
Home-page: https://spacy.io
Author: Explosion
Author-email: contact@explosion.ai
License: MIT
Location: /usr/local/lib/python3.6/dist-packages
Requires: thinc, murmurhash, preshed, blis, srsly, cymem, setuptools, plac, requests, tqdm, numpy, wasabi, catalogue
Required-by: fastai, en-core-web-sm
Cloning into 'neuralcoref'...
remote: Enumerating objects: 48, done.
remote: Counting objects: 100% (48/48), done.
remote: Compressing objects: 100% (44/44), done.
remote: Total 739 (delta 14), reused 10 (delta 1), pack-reused 691
Receiving objects: 100% (739/739), 67.86 MiB | 30.25 MiB/s, done.
Resolving deltas: 100% (368/368), done.

然后,我按照网站上的说明:

代码语言:javascript
运行
复制
nlp = spacy.load('en')
neuralcoref.add_to_pipe(nlp)

但是,我得到以下错误:

代码语言:javascript
运行
复制
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-8-fe99e1a1a10f> in <module>()
      1 nlp = spacy.load('en')
----> 2 neuralcoref.add_to_pipe(nlp)
      3 #coref = neuralcoref.NeuralCoref(nlp.vocab)
      4 #nlp.add_pipe(coref, name='neuralcoref')

AttributeError: module 'neuralcoref' has no attribute 'add_to_pipe'

有人知道怎么解决这个问题吗?

编辑

在(成功地)使用了下面的建议之后,当我尝试运行所提供的示例时,colab在我身上崩溃了(参见下面的详细信息)。

下面是使用的代码:

代码语言:javascript
运行
复制
from google.colab import drive
drive.mount('/content/gdrive')

!pip install neuralcoref

import spacy
import neuralcoref

nlp = spacy.load('en') # this is the line where it crashes
neuralcoref.add_to_pipe(nlp)

doc1 = nlp('My sister has a dog. She loves him.')
print(doc1._.coref_clusters)

我附上了一个屏幕截图与原来的错误信息,在左下角。

编辑2

当更改安装模块的顺序时,我得到了colab上的代码(不知道为什么)。

以下几点对我来说是有效的:

代码语言:javascript
运行
复制
from google.colab import drive
drive.mount('/content/gdrive')

!git clone https://github.com/huggingface/neuralcoref.git
!pip install -U spacy
!python -m spacy download en

import spacy
nlp = spacy.load('en')

%cd neuralcoref

!pip install -r requirements.txt
!pip install -e .

import neuralcoref
neuralcoref.add_to_pipe(nlp)

doc1 = nlp('My sister has a dog. She loves him.')
print(doc1._.coref_clusters)
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2020-04-17 11:43:06

更新:

自从以前的帮助解决了第一个问题,但创造了另一个问题,我已经更新了答案。

根据neuralcoref页面,对于我们的Spacy版本,我们需要从源代码手动安装它。

此外,在Colab中的新单元格中尝试以下每一个块,并在安装后使用Restart Runtime

代码语言:javascript
运行
复制
mkdir temp

cd temp

!git clone https://github.com/huggingface/neuralcoref.git
!pip install -U spacy
!python -m spacy download en

cd neuralcoref

!pip install -r requirements.txt
!pip install -e .


import neuralcoref
import spacy

nlp = spacy.load('en')
neuralcoref.add_to_pipe(nlp)

doc1 = nlp('My sister has a dog. She loves him.')
print(doc1._.coref_clusters)

票数 3
EN

Stack Overflow用户

发布于 2021-04-08 15:03:40

我也有过类似的问题。经过大量调试之后,我在google上完成了以下工作:

  1. 安装正确版本的Spacy。我的google有2.2.4,但是我像这样重新安装了它:
代码语言:javascript
运行
复制
pip install -U spacy==2.1.0 

python -m spacy download en
  1. Google拥有正确版本的Cython,但是通过运行:!pip显示cython进行双重检查。如果没有,请用以下方式安装:
代码语言:javascript
运行
复制
pip install Cython --install-option="--no-cython-compile"

版本需要是>=0.25

  1. 像这样安装神经壁虎。确保在google中使用GPU:
代码语言:javascript
运行
复制
pip uninstall -y neuralcoref 

pip install neuralcoref --no-binary neuralcoref

这应该能解决问题。最有可能的是,Spacy安装将为您做,如果没有,遵循所有的步骤。

票数 2
EN

Stack Overflow用户

发布于 2020-07-07 08:57:35

Neuralcoref只适用于spacy版本

spacy>=2.1.0,<2.2.0 cython>=0.25 pytest

请参阅requirements.txt

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61269954

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档