pythonpython-3.xnlppos-taggerspacy-3

Retrieve a list of model-specific POS tags using spaCy


I am looking for a way to get a list of all possibly usable POS tags for a specific language model in spaCy.

In an answer to another question, spaCy's TAG_MAP has been referenced to, but I am not sure how to access this. The documentation of spaCy says that this attribute has been replaced. Since spaCy only uses a specific subset of all POS tags for a specific language, I would like to retrieve a list of all POS tags that are currently used with the initialized language model.

I did currently just set up a model this way:

import spacy

tagger = spacy.load("de_dep_news_trf")

# TODO print(pos_tags)

Now, how do I print a list of all possible pos tags for this model?


Solution

  • For pretrained pipelines, you can check the labels on the model page, under the "Label Scheme" entry.

    If your pipeline has a tagger, like the German one does, you can do this:

    tagger = nlp.get_pipe("tagger")
    print(tagger.labels)