Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking whether an ID is in vocab #1868

Closed
danielhers opened this issue Jan 21, 2018 · 2 comments
Closed

Checking whether an ID is in vocab #1868

danielhers opened this issue Jan 21, 2018 · 2 comments
Labels
bug Bugs and behaviour differing from documentation

Comments

@danielhers
Copy link
Contributor

danielhers commented Jan 21, 2018

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)

Info about spaCy

  • spaCy version: 2.0.5
  • Platform: Linux-4.8.4-aufs-1-x86_64-with-debian-stretch-sid
  • Python version: 3.6.1
  • Models: en_core_web_lg, en_core_web_md
@honnibal honnibal added the bug Bugs and behaviour differing from documentation label Jan 21, 2018
@honnibal
Copy link
Member

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.

@lock
Copy link

lock bot commented May 8, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bugs and behaviour differing from documentation
Projects
None yet
Development

No branches or pull requests

2 participants