Create a gist now

Instantly share code, notes, and snippets.

Embed
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 https://creativecommons.org/choose/zero/, other text released under CC BY 4.0 https://creativecommons.org/licenses/by/4.0/
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@arielgamino

This comment has been minimized.

Show comment
Hide comment
@arielgamino

arielgamino Mar 2, 2018

Very nice tutorial!

Very nice tutorial!

@carltoews

This comment has been minimized.

Show comment
Hide comment
@carltoews

carltoews Mar 2, 2018

Thanks, this is great!

Thanks, this is great!

@tomnis

This comment has been minimized.

Show comment
Hide comment
@tomnis

tomnis Mar 2, 2018

awesome! very intuitive explanations

tomnis commented Mar 2, 2018

awesome! very intuitive explanations

@marcboeker

This comment has been minimized.

Show comment
Hide comment
@marcboeker

marcboeker Mar 2, 2018

Great tutorial, thanks!

Great tutorial, thanks!

@vnhnhm

This comment has been minimized.

Show comment
Hide comment
@vnhnhm

vnhnhm 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: 
https://spacy.io/usage/models

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: 
https://spacy.io/usage/models
@rgibson

This comment has been minimized.

Show comment
Hide comment
@rgibson

rgibson Mar 12, 2018

@vnhnhm
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: https://spacy.io/usage/models

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!

rgibson commented Mar 12, 2018

@vnhnhm
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: https://spacy.io/usage/models

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!

@razodactyl

This comment has been minimized.

Show comment
Hide comment
@razodactyl

razodactyl Mar 15, 2018

This write up is amazing, great work!

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