在Colab中使用NeuralCoref时出现属性错误 [英] Attribute Error using NeuralCoref in Colab
本文介绍了在Colab中使用NeuralCoref时出现属性错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用CoLab中的以下Spacy模块:
https://spacy.io/universe/project/neuralcoref
我安装以下软件包:
!pip install spacy
import spacy
!pip show spacy
!git clone https://github.com/huggingface/neuralcoref.git
import neuralcoref
安装后得到以下输出:
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.
然后我按照网站上的说明操作:
nlp = spacy.load('en')
neuralcoref.add_to_pipe(nlp)
但是,我收到以下错误:
---------------------------------------------------------------------------
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崩溃了(请参见下面的详细信息)。以下是使用的代码:
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上工作的代码。
以下内容现在对我有效:
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)
推荐答案
更新:
由于上一个帮助解决了第一个问题,但产生了另一个问题,因此我已更新了答案。
根据neuralcoref
页,对于我们的Spacy版本,需要从源手动安装。
另外,请在Colab的新单元格中尝试以下每个块,并在安装后Restart Runtime
。
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)
这篇关于在Colab中使用NeuralCoref时出现属性错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文