huggingface / neuralcoref

✨Fast Coreference Resolution in spaCy with Neural Networks
https://huggingface.co/coref/
MIT License
2.85k stars 477 forks source link

core dumped #222

Closed astariul closed 4 years ago

astariul commented 4 years ago

I'm trying to use neuralcoref. But when I try to run the example from README, I get a core dumped error.

Here is the code I tried :

import spacy
import neuralcoref
nlp = spacy.load('en')
neuralcoref.add_to_pipe(nlp)
doc1 = nlp('My sister has a dog. She loves him.')     # > Crash !

Any idea where the problem come from ?


Note : when I import neuralcoref (import neuralcoref), I receive following warnings :

/home/user/.venv/test/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: spacy.morphology.Morphology size changed, may indicate binary incompatibility. Expected 104 from C header, got 112 from PyObject return f(*args, kwds) /home/user/.venv/test/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: spacy.vocab.Vocab size changed, may indicate binary incompatibility. Expected 96 from C header, got 104 from PyObject return f(*args, *kwds) /home/user/.venv/test/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: spacy.tokens.span.Span size changed, may indicate binary incompatibility. Expected 72 from C header, got 80 from PyObject return f(args, kwds)

svlandeg commented 4 years ago

I'm assuming this is a version incompatibility issue, please see https://github.com/huggingface/neuralcoref/issues/197#issuecomment-534028423. Hope that solves it!

victoriastuart commented 4 years ago

I get exactly the same error as @Colanim ... I am using

(py3.7) [victoria@victoria spacy]$ pip list | egrep 'spacy|neuralcoref'
  neuralcoref                     4.0
  scispacy                        0.2.4
  spacy                           2.2.3
  spacy-stanfordnlp               0.1.3
  spacy-transformers              0.5.1
(py3.7) [victoria@victoria spacy]$ python
    Python 3.7.4 (default, Nov 20 2019, 11:36:53) 
    [GCC 9.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import spacy
    >>> nlp = spacy.load('en')

    >>> import neuralcoref

    /usr/local/lib/python3.7/importlib/_bootstrap.py:219: \
    RuntimeWarning: spacy.morphology.Morphology size changed, \
    may indicate binary incompatibility. Expected 104 from C header, \
    got 112 from PyObject
    return f(*args, **kwds)

    /usr/local/lib/python3.7/importlib/_bootstrap.py:219: \
    RuntimeWarning: spacy.vocab.Vocab size changed, \
    may indicate binary incompatibility. Expected 96 from C header, \
    got 104 from PyObject
    return f(*args, **kwds)

    /usr/local/lib/python3.7/importlib/_bootstrap.py:219: RuntimeWarning: \
    spacy.tokens.span.Span size changed, may indicate binary incompatibility. \
    Expected 72 from C header, got 80 from PyObject
    return f(*args, **kwds)

>>> import neuralcoref    ## again

>>> neuralcoref.add_to_pipe(nlp)
    <spacy.lang.en.English object at 0x7fd5618becd0>

>>> doc = nlp(u'My sister has a dog. She loves him.')
    Segmentation fault (core dumped)

(py3.7) [victoria@victoria spacy]$ 

As I also got the binary incompatibility segfault, I installed neuralcoref using pip install neuralcoref --no-binary neuralcoref.

victoriastuart commented 4 years ago

Solution

tl/dr:

BASH:

pip uninstall neuralcoref
git clone https://github.com/huggingface/neuralcoref.git
cd neuralcoref
pip install -r requirements.txt
pip install -e .
pip uninstall spacy
pip install spacy
python -m spacy download en

PYTHON:

import spacy
nlp = spacy.load('en')
import neuralcoref      ## ignore RuntimeWarning(s)
neuralcoref.add_to_pipe(nlp)
doc = nlp(u'My sister has a dog. She loves him.')
doc._.has_coref         ## True
doc._.coref_clusters    ## [My sister: [My sister, She], a dog: [a dog, him]]
doc._.coref_resolved    ## 'My sister has a dog. My sister loves a dog.'

details:

$ date; pwd
  Thu 23 Jan 2020 04:50:58 PM PST
  /mnt/Vancouver/apps

$ pip uninstall neuralcoref
  ...

$ git clone https://github.com/huggingface/neuralcoref.git
  ...

$ cd neuralcoref

$ pwd
  /mnt/Vancouver/apps/neuralcoref

$ pip install -r requirements.txt
  Collecting spacy<2.2.0,>=2.1.0
  ...
  ERROR: scispacy 0.2.4 has requirement spacy>=2.2.1, but \
  you'll have spacy 2.1.9 which is incompatible.
  ...

$ pip install -e .
  ...

$ pip list | egrep -w 'spacy|neuralcoref'
  neuralcoref                     4.0         /mnt/Vancouver/apps/neuralcoref
  spacy                           2.1.9
  spacy-stanfordnlp               0.1.3
  spacy-transformers              0.5.1

## GET BACK MY MORE RECENT spaCy !

$ pip uninstall spacy
  Found existing installation: spacy 2.1.9
  Uninstalling spacy-2.1.9:
  ...

$ pip install spacy
  ...

$ pip list | egrep -w 'spacy|neuralcoref'
  neuralcoref                     4.0         /mnt/Vancouver/apps/neuralcoref
  spacy                           2.2.3
  spacy-stanfordnlp               0.1.3
  spacy-transformers              0.5.1

## Re-download spaCy version-compatible pretrained model:

$ python -m spacy download en
  ...
$ python
  Python 3.7.4 (default, Nov 20 2019, 11:36:53)
  [GCC 9.2.0] on linux
  Type "help", "copyright", "credits" or "license" for more information.

>>> import spacy
>>> nlp = spacy.load('en')

## You can now ignore this error:

>>> import neuralcoref

  /usr/local/lib/python3.7/importlib/_bootstrap.py:219: RuntimeWarning: \
  spacy.morphology.Morphology size changed, may indicate binary incompatibility. \
  Expected 104 from C header, got 112 from PyObject
  return f(*args, **kwds)

  /usr/local/lib/python3.7/importlib/_bootstrap.py:219: RuntimeWarning: \
  spacy.vocab.Vocab size changed, may indicate binary incompatibility. \
  Expected 96 from C header, got 104 from PyObject
  return f(*args, **kwds)

>>> neuralcoref.add_to_pipe(nlp)
  <spacy.lang.en.English object at 0x7f418e4b89d0>

>>> doc = nlp(u'My sister has a dog. She loves him.')

>>> doc._.has_coref
  True
>>> doc._.coref_clusters
  [My sister: [My sister, She], a dog: [a dog, him]]
>>> doc._.coref_resolved
  'My sister has a dog. My sister loves a dog.'
RanaBan commented 4 years ago

Thanks victoriastuart!! I faced the same problem and your solution worked.

superbug74 commented 4 years ago

Thanks victoriastuart - you saved me a bit of headache!

ayokha commented 4 years ago

It does'nt work for me - when l install "pip intstall -e .", I got this error = Running setup.py develop for neuralcoref ERROR: Command errored out with exit status 1

Yukyin commented 3 years ago

Thanks victoriastuart!! It works for me!!