spaCy NER: extraire des entités nommées
objectif
Expliquer et montrer comment détecter personnes, organisations, lieux avec spaCy.
code minimal
import spacy
# nlp = spacy.load("en_core_web_sm")
nlp = spacy.blank("en")
doc = nlp.make_doc("Apple is looking at buying U.K. startup for $1 billion")
[(ent.text, ent.label_) for ent in doc.ents]
utilisation
# pour de vraies entités, charger un modèle entraîné :
# nlp = spacy.load("en_core_web_sm")
# nlp("Apple is looking at buying a U.K. startup for $1 billion").ents
variante(s) utile(s)
# entraîner ou affiner le NER est complexe; voir la doc spaCy.
notes
- Sans modèle, .ents est vide; chargez un pipeline avec NER.
- Privilégiez ‘md’ ou ‘lg’ pour meilleure précision.