我试图在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)
发布于 2020-04-17 11:43:06
更新:
自从以前的帮助解决了第一个问题,但创造了另一个问题,我已经更新了答案。
根据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)
发布于 2021-04-08 15:03:40
我也有过类似的问题。经过大量调试之后,我在google上完成了以下工作:
pip install -U spacy==2.1.0
python -m spacy download en
pip install Cython --install-option="--no-cython-compile"
版本需要是>=0.25
pip uninstall -y neuralcoref
pip install neuralcoref --no-binary neuralcoref
这应该能解决问题。最有可能的是,Spacy安装将为您做,如果没有,遵循所有的步骤。
发布于 2020-07-07 08:57:35
https://stackoverflow.com/questions/61269954
复制相似问题