Return all possible entity types from spaCy model?
Asked Answered
G

2

11

Is there a method to extract all possible named entity types from a model in spaCy? You can manually figure it out by running on sample text, but I imagine there is a more programmatic way to do this? For example:

import spacy
model=spacy.load("en_core_web_sm")
model.*returns_entity_types*
Gaza answered 1/12, 2021 at 13:33 Comment(0)
T
22

The statistical pipeline components like ner provide their labels under .labels:

import spacy
nlp = spacy.load("en_core_web_sm")
nlp.get_pipe("ner").labels
Tinker answered 1/12, 2021 at 17:14 Comment(0)
H
4

This might not be the most general answer, but for en_core_web_sm this returns the named entity types.

model = spacy.load("en_core_web_sm")
list(model.__dict__['_meta']['accuracy']['ents_per_type'].keys())

['ORG', 'CARDINAL', 'DATE', 'GPE', 'PERSON', 'MONEY', 'PRODUCT', 'TIME', 'PERCENT', 'WORK_OF_ART', 'QUANTITY', 'NORP', 'LOC', 'EVENT', 'ORDINAL', 'FAC', 'LAW', 'LANGUAGE']
Hither answered 1/12, 2021 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.