You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know how to check whether a string is in the vocab, but is there a way to check if an ID is? This is for a use case similar to #1822. The example given alongside Vocab.__contains__ allegedly demonstrates this, but running this example results in an exception:
>>> import spacy
>>> nlp = spacy.load("en_core_web_md")
>>> apple = nlp.vocab.strings['apple']
>>> oov = nlp.vocab.strings['dskfodkfos']
>>> assert apple in nlp.vocab
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Argument 'string' has incorrect type (expected str, got int)
>>> assert oov not in nlp.vocab
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Argument 'string' has incorrect type (expected str, got int)
Thanks, it looks like there's a bug in Vocab.__contains__. It should accept both strings and ints, but currently only supports strings. You could check whether the int is in vocab.strings, and if it is, decode it to the string to look it up. We'll have the error fixed in the next version.
I know how to check whether a string is in the vocab, but is there a way to check if an ID is? This is for a use case similar to #1822.
The example given alongside
Vocab.__contains__
allegedly demonstrates this, but running this example results in an exception:Info about spaCy
The text was updated successfully, but these errors were encountered: