1st thing 1st: I'm new to SpaCy and just started to test it. I have to say that I'm impressed by its simplicity and the doc quality. Thanks!
Now, I'm trying to identify PER in a French text. It seems to work pretty well for most but I saw a recurring incorrect pattern: names with a hyphen are not correctly recognized (ex: Pierre-Louis Durand will appear as two PER: "Pierre" and "Louis Durand").
See example:
import spacy
# nlp = spacy.load('fr')
nlp = spacy.load('fr_core_news_md')
description = ('C\'est Jean-Sébastien Durand qui leur a dit. Pierre Dupond n\'est pas venu à Boston comme attendu. '
'Louis-Jean s\'est trompé. Claire a bien choisi.')
text = nlp(description)
labels = set([w.label_ for w in text.ents])
for label in labels:
entities = [e.string for e in text.ents if label==e.label_]
entities = list(entities)
print(label, entities)
output is:
LOC ['Boston ']
PER ['Jean', 'Sébastien Durand ', 'Pierre Dupond ', 'Louis', 'Jean ', 'Claire ']
It should be: "Jean-Sébastien Durand" and "Louis-Jean".
I'm not sure what to do here:
- change the way tokens are extracted (I'm wondering about the side effect for non PER) - I don't think this is the issue as a PER can be an aggregation of multiple tokens
- apply a magic setting somewhere so that hyphen can be used in NER for PER
- train the model
- go back to school ;-)
Thanks for your help (and yes I'm investigating by reading more, I love it)!
-TC