Search code examples
pythonnlpspacy

How do I correlate the `int` hash value of a spaCy Token `ent_type` to a string?


Is there some way to decode the hash of spaCy token entity types without accessing the ent_type_ attribute?

For example:

for token in doc:
    hash_val = token.ent_type
    string_repr = some_map[hash_val]

Solution

  • It's stored in the vocab.

    nlp.vocab.strings[token.ent_type] == token.ent_type_
    

    Not sure why you would need to do that though.