whenitrains
whenitrains

Reputation: 498

Can you determine list of labels for existing EntityRecognizer (NER)?

I know in the past you could get the list of labels for an EntityRecognizer as follows:

nlp.entity.cfg[u'actions']

(From https://github.com/explosion/spaCy/issues/441)

But, it seems this had been disallowed. Is there any way to do this now?

Upvotes: 8

Views: 9034

Answers (3)

russhoppa
russhoppa

Reputation: 393

As of spaCy version 3.7

import spacy

nlp = spacy.load("en_core_web_sm")
ner = nlp.get_pipe("ner")
print(ner.labels)

Outputs:

('CARDINAL', 'DATE', 'EVENT', 'FAC', 'GPE', 'LANGUAGE', 'LAW', 'LOC', 'MONEY', 'NORP', 'ORDINAL', 'ORG', 'PERCENT', 'PERSON', 'PRODUCT', 'QUANTITY', 'TIME', 'WORK_OF_ART')

Upvotes: 1

jvdzwaan
jvdzwaan

Reputation: 264

In spaCy 3 do nlp.get_pipe('ner').labels.

Upvotes: 16

Palash Jhamb
Palash Jhamb

Reputation: 625

You can do the following :

nlp.entity.labels

It outputs the following tuple :

('CARDINAL', 'DATE', 'EVENT', 'FAC', 'GPE', 'LANGUAGE', 'LAW', 'LOC', 'MONEY', 'NORP', 'ORDINAL', 'ORG', 'PERCENT', 'PERSON', 'PRODUCT', 'QUANTITY', 'TIME', 'WORK_OF_ART')

Upvotes: 6

Related Questions