Skip to content

Instantly share code, notes, and snippets.

@ivyleavedtoadflax
Last active July 7, 2019 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivyleavedtoadflax/76206bf43f4ca31a798d000c431d0fd8 to your computer and use it in GitHub Desktop.
Save ivyleavedtoadflax/76206bf43f4ca31a798d000c431d0fd8 to your computer and use it in GitHub Desktop.
Get document vectors from spacy
# Need to run:
# python -m spacy download en
# from console first to get the model
import spacy
import pandas as pd
nlp = spacy.load("en")
docs = [
"This is doc 1",
"This is doc 2",
"This is doc 3",
"This is doc 4",
"This is doc 5",
]
foo = list(nlp.pipe(docs))
dict_comp = {i.text: i.vector for i in foo}
dict_df = pd.DataFrame(dict_comp)
print(dict_df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment