3
votes

In Named Entity Recognition (NER), does the previous sentence have any influence on the current sentence? Is the result the same if you apply NER on every sentence separately compared to applying NER on articles consisting of multiple sentences?

More specifically, I'm using Spacy NER. This is approach one:

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

sentences = "My name is Bruce and I come from New York. Pete is my best friend from Amsterdam."

nlp_object = nlp(sentences)
print([(y.text, y.label_) for y in nlp_object.ents])

which yields this result:

[('Bruce', 'PERSON'), ('New York', 'GPE'), ('Pete', 'PERSON'), ('Amsterdam', 'GPE')]

But instead of the last two lines, you could also split the sentences and apply NER on every sentence:

for s in sentences.split("."):
    nlp_object = nlp(s)
    print([(y.text, y.label_) for y in nlp_object.ents])

Which returns the same result (but instead in two separate lines):

[('Bruce', 'PERSON'), ('New York', 'GPE')]
[('Pete', 'PERSON'), ('Amsterdam', 'GPE')]

In this example, running the code gives the same extracted entities. But how does the underlying model do this? Is there any influence of the previous sentence in NER? And is there any difference between different implementations of NER?

1

1 Answers

4
votes

Spacy NER system uses a deep neural network to train millions of examples of word-entity pairs. The pairs are usually trained as separate sentences if you look at their sample training codes here..

While I do not know how exactly the pre-trained model that spacy provides is trained, I can assume that they are also trained using single sentences. Even if they aren't, previous sentences should not have any influence, because the training data is not given to deep learning system as words, but as vector representations, learned from other samples of text. Take a look at this article to understand how contextual words affect the prediction.