Instantly share code, notes, and snippets.

What would you like to do?
Understanding word vectors: A tutorial for "Reading and Writing Electronic Text," a class I teach at ITP. (Python 2.7) Code examples released under CC0, other text released under CC BY 4.0
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This comment has been minimized.

arielgamino commented Mar 2, 2018

Very nice tutorial!


This comment has been minimized.

carltoews commented Mar 2, 2018

Thanks, this is great!


This comment has been minimized.

tomnis commented Mar 2, 2018

awesome! very intuitive explanations


This comment has been minimized.

marcboeker commented Mar 2, 2018

Great tutorial, thanks!


This comment has been minimized.

vnhnhm commented Mar 8, 2018

Not sure why I'm getting the following error, working on macOS with Jupyter Lab, Python 2.7 and Spacy 2.0.9:

ValueError                                Traceback (most recent call last)
<ipython-input-2-090b6e832a74> in <module>()
      3 # It creates a list of unique words in the text
      4 tokens = list(set([w.text for w in doc if w.is_alpha]))
----> 5 print nlp.vocab['cheese'].vector

lexeme.pyx in spacy.lexeme.Lexeme.vector.__get__()

ValueError: Word vectors set to length 0. This may be because you don't have a model installed or loaded, or because your model doesn't include word vectors. For more info, see the documentation:

This comment has been minimized.

rgibson commented Mar 12, 2018

I was getting the same error. I fixed it by downloading a different language model for spaCy than what the instructions indicated (one that includes vectors). See spaCy documentation here:

So instead of running this from the command line:
python -m spacy download en
. . . and using this command in Jupyter:
nlp = spacy.load('en')

I ran this command in bash:
python -m spacy download en_core_web_md
. . . and did this in Jupyter
nlp = spacy.load('en_core_web_md')

Hope this helps!


This comment has been minimized.

razodactyl commented Mar 15, 2018

This write up is amazing, great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment