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

Advanced Spacy Course: Bowie is a word #127

Open
breadstand opened this issue Mar 31, 2022 · 4 comments
Open

Advanced Spacy Course: Bowie is a word #127

breadstand opened this issue Mar 31, 2022 · 4 comments

Comments

@breadstand
Copy link

How to reproduce the behaviour

Your Environment

  • Operating System:
  • Python Version Used:
  • spaCy Version Used:
  • Environment Information:
@breadstand
Copy link
Author

breadstand commented Mar 31, 2022

It can be reproduced on any platform. The problem is that "Bowie" is a valid English word, and also a hash can't be used in a different nlp object with a different vocabulary.

>>> # Create an English and German nlp object
>>> nlp = spacy.blank("en")
>>> nlp_de = spacy.blank("de")
>>> 
>>> # Get the ID for the string 'Bowie'
>>> bowie_id = nlp.vocab.strings["Bowie"]
>>> print(bowie_id)
2644858412616767388
>>> 
>>> # Look up the ID for "Bowie" in the vocab
>>> print(nlp_de.vocab.strings[bowie_id])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "spacy/strings.pyx", line 132, in spacy.strings.StringStore.__getitem__
KeyError: "[E018] Can't retrieve string for hash '2644858412616767388'. This usually refers to an issue with the `Vocab` or `StringStore`."
>>> 

@adrianeboyd
Copy link
Collaborator

Sorry, I'm not sure exactly what you're asking? Looking at this example (in chapter 2, section 3 under "Vocab, hashes and lexemes") this example code is supposed to throw an error.

@breadstand
Copy link
Author

breadstand commented Mar 31, 2022 via email

@adrianeboyd
Copy link
Collaborator

Maybe we're not looking at the same version of the course? Here's the current version:

https://course.spacy.io/en/chapter2

The correct answer is: "The string "Bowie" isn’t in the German vocab, so the hash can’t be resolved in the string store."

Where does the documentation indicate that this particular line should throw an error?


You can always hash any string with nlp.vocab.strings["Bowie"] and you'll get the same hash for "Bowie" from every spacy pipeline, so you'll also get the same value from nlp_de.vocab.strings["Bowie"].

This question is about the other direction: you can only convert hash -> string for strings that have already been added to that pipeline's string store. Usually this happens automatically when you process texts, but you can also add any string explicitly with nlp.vocab.strings.add("Bowie").

@adrianeboyd adrianeboyd transferred this issue from explosion/spaCy Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants