在 Colab 中使用 NeuralCoref 的属性错误
Attribute Error using NeuralCoref in Colab
我正在尝试在 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)
Neuralcoref 仅适用于 spacy 版本
spacy>=2.1.0,<2.2.0
cython>=0.25
测试
我遇到了类似的问题。经过大量的调试之后,我做了什么让它在 google colab:
上工作
- 安装正确版本的 Spacy。我的 google colab 有 2.2.4,但我像这样重新安装它:
pip install -U spacy==2.1.0
python -m spacy download en
- Google colab 拥有正确版本的 Cython,但请仔细检查 运行:!pip show cython。如果没有,请安装它:
pip install Cython --install-option="--no-cython-compile"
版本需要>=0.25
- 像这样安装 neuralcoref。确保您在 google colab:
中使用 GPU
pip uninstall -y neuralcoref
pip install neuralcoref --no-binary neuralcoref
这应该可以解决问题。 Spacy 安装很可能会为您完成,如果没有,请按照所有步骤操作。
这对我有用。测试于 2022 年 3 月 20 日。另外,请确保您将运行时恢复出厂设置,以便它删除所有以前安装的 spacy 和其他依赖项。
from google.colab import drive
drive.mount('/content/drive')
!git clone https://github.com/huggingface/neuralcoref.git
%cd neuralcoref
!pip install -r requirements.txt
!pip install -e .
import spacy
import neuralcoref
nlp = spacy.load('en')
neuralcoref.add_to_pipe(nlp)
doc1 = nlp('My sister has a dog. She loves him.')
print(doc1._.coref_clusters)
我正在尝试在 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)
Neuralcoref 仅适用于 spacy 版本
spacy>=2.1.0,<2.2.0 cython>=0.25 测试
我遇到了类似的问题。经过大量的调试之后,我做了什么让它在 google colab:
上工作- 安装正确版本的 Spacy。我的 google colab 有 2.2.4,但我像这样重新安装它:
pip install -U spacy==2.1.0
python -m spacy download en
- Google colab 拥有正确版本的 Cython,但请仔细检查 运行:!pip show cython。如果没有,请安装它:
pip install Cython --install-option="--no-cython-compile"
版本需要>=0.25
- 像这样安装 neuralcoref。确保您在 google colab: 中使用 GPU
pip uninstall -y neuralcoref
pip install neuralcoref --no-binary neuralcoref
这应该可以解决问题。 Spacy 安装很可能会为您完成,如果没有,请按照所有步骤操作。
这对我有用。测试于 2022 年 3 月 20 日。另外,请确保您将运行时恢复出厂设置,以便它删除所有以前安装的 spacy 和其他依赖项。
from google.colab import drive
drive.mount('/content/drive')
!git clone https://github.com/huggingface/neuralcoref.git
%cd neuralcoref
!pip install -r requirements.txt
!pip install -e .
import spacy
import neuralcoref
nlp = spacy.load('en')
neuralcoref.add_to_pipe(nlp)
doc1 = nlp('My sister has a dog. She loves him.')
print(doc1._.coref_clusters)