Coreference Resolution using NeuralCoref (SpaCy)
I faced few problems installing neuralcoref for coreference resolution using SpaCy but found the solution that fixes things for me. Follow the installation below and neuralcoref should work for you 🙂
How does NeuralCoref extracts mentions?
Using rule-based. Each mention can co-refer with various number of other mentions, resulting in more than one co-referring antecedent for each mention.
What’s the potential issues arise when training the model?
Firstly, since each mention has various potential antecedents, this would complicate the batching process as the size of the mention-pairs vary. Secondly, the size of table of mention-pairs increases with c, where c is the average number of mentions in each document of the dataset.
What’s the benefit of NeuralCoref from features perspective?
Once we have our mentions and pair-mentions, it’s time to derive features for each of them. Many coreference resolution systems have more than 100 features but NeuralCoref has reduced the number of features used significantly and the features being used in NeuralCoref doesn’t depend on external databases or parser which means they are fast and easy to compute.
What are the these features used by NeuralCoref?
The features consists of real-valued vectors (average word vectors), integers (word indices in dictionary), and booleans (nested?) and these features are stored in separate arrays.
What’s the neural network used in NeuralCoref?
The neural network has two components:
The embedding layer (classic)
Two parallel fully-connected layer
The first fully-connected layer takes in the word vectors, spans, and additional features of the mention to compute the score that the mention has no other co-referring mentions. The second fully-connected layer takes in the word vectors, spans, and additional features of the mention AND an antecedent and pair features to compute the score that the pair mentions are co-referring.
# These installations below allows me to run neuralcoref with no issues! # !pip uninstall spacy # !pip uninstall neuralcoref # !pip install spacy==2.1.0 # !pip install neuralcoref --no-binary neuralcoref
1. Import dependencies and load a simple English SpaCy model
import spacy import neuralcoref
nlp = spacy.load('en')
2. Add neuralcoref to the SpaCy pipeline
<spacy.lang.en.English at 0x10523fbd0>
3. Apply coreference resolution to generic sentences
doc2 = nlp('James loves pineapple because it tastes very good. Pineapple makes him happy.') for ent in doc2.ents: print(ent._.coref_cluster)
James: [James, him]