Last active
July 7, 2019 10:35
-
-
Save ivyleavedtoadflax/76206bf43f4ca31a798d000c431d0fd8 to your computer and use it in GitHub Desktop.
Get document vectors from spacy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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