Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 在Colab中使用NeuralRef时出现属性错误_Python 3.x_Google Colaboratory_Spacy - Fatal编程技术网

Python 3.x 在Colab中使用NeuralRef时出现属性错误

Python 3.x 在Colab中使用NeuralRef时出现属性错误,python-3.x,google-colaboratory,spacy,Python 3.x,Google Colaboratory,Spacy,我试图在colab中使用以下spacy模块: 我安装了以下软件包: !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 P

我试图在colab中使用以下spacy模块:

我安装了以下软件包:

!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'
我在左下角附上了一个屏幕截图,上面有原始的错误信息

编辑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)
更新:

由于上一个问题帮助解决了第一个问题,但又产生了另一个问题,因此我更新了答案

根据
neuralcref
page,对于我们的Spacy版本,我们需要从源代码手动安装它

另外,在Colab的新单元中尝试以下每个块,并在安装后重新启动运行时

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)


NeuralRef仅适用于spacy版本

间距>=2.1.0,=0.25 皮特斯特


参见

我也有类似的问题。经过大量调试后,我在google colab上实现了以下功能:

  • 安装Spacy的正确版本。我的google colab有2.2.4版本,但我重新安装时是这样的:
  • GoogleColab有正确的Cython版本,但要通过运行来再次检查:!皮普秀赛昂。如果没有,请使用以下设备安装:
  • 版本必须大于等于0.25

  • 像这样安装NeuralRef。确保您正在google colab中使用GPU:

  • 这应该可以解决问题。Spacy安装最有可能为您完成此任务,如果没有,请按照所有步骤操作。

    快速跟进问题-您是否能够在网站上运行此示例?我刚刚尝试了一下,但由于一个未知的错误,它使我的会话崩溃了?是的,我从Colab上截取了那个屏幕截图。等等,我会试试看,所以我一加上以下几行就崩溃了:doc1=nlp(“我妹妹有一条狗,她爱它。”)print(doc1.\uu.coref\u集群)你也是这样吗?啊,好的,谢谢-我刚刚发布了一个新问题,但现在会改变它,谢谢:-)我必须在colab中的cd命令前面添加一个%以使安装正常工作,但随后收到一条新的错误消息,其中找不到型号“en”。。。我想我必须为此提出一个新问题!谢谢你!
    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)
    
    pip install -U spacy==2.1.0 
    
    python -m spacy download en
    
    pip install Cython --install-option="--no-cython-compile"
    
    pip uninstall -y neuralcoref 
    
    pip install neuralcoref --no-binary neuralcoref