问题
I'm trying to use the following spacy module in colab:
https://spacy.io/universe/project/neuralcoref
I install the following packages:
!pip install spacy
import spacy
!pip show spacy
!git clone https://github.com/huggingface/neuralcoref.git
import neuralcoref
I get the following output after installing:
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.
I then follow the instructions on the website:
nlp = spacy.load('en')
neuralcoref.add_to_pipe(nlp)
However, I get the following error:
---------------------------------------------------------------------------
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'
Does anybody know how to fix this?
EDIT
After (successfully) using the suggestion below, colab crashed on me when I tried to run the example provided (see details below).
Here is the code used:
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)
I've attached a screenshot with the original error message at the bottom left.
EDIT 2
I got the code to work on colab when changing the order of installing the modules (not sure why).
The following has worked for me now:
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)
回答1:
Update:
Since the previous helped solving the first problem but created another problem, I have updated the answer.
According to neuralcoref
page, for our version of Spacy, we need to manually install it from the source.
Also, try each of the following blocks in new cell in Colab, and Restart Runtime
after installation.
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)
回答2:
Neuralcoref just works with spacy Version
spacy>=2.1.0,<2.2.0 cython>=0.25 pytest
see requirements.txt
来源:https://stackoverflow.com/questions/61269954/attribute-error-using-neuralcoref-in-colab