gpt4 book ai didi

python-3.x - 在 Colab 中使用 NeuralCoref 的属性错误

转载 作者:行者123 更新时间:2023-12-05 02:08:04 26 4
gpt4 key购买 nike

我正在尝试在 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)

我在左下角附上了带有原始错误消息的屏幕截图。

enter image description here

编辑 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 的新单元格中尝试以下每个 block ,并在安装后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)


Solved

关于python-3.x - 在 Colab 中使用 NeuralCoref 的属性错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61269954/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com