Skip to content

Can I store all word to vector mappings in a dictionary? Is this even plausible? #13569

Discussion options

You must be logged in to vote

Using guidance from https://stackoverflow.com/questions/55383604/how-to-extract-word-embedding-vectors-from-a-trained-spacy-model , I was able to figure it out!

Still not sure if this is a great idea, but I used the following code to create a dump of strings to embeddings

import spacy
nlp = spacy.load("en_core_web_lg")

word_vectors = dict()
for key, vector in list(nlp.vocab.vectors.items()):
    word_string = nlp.vocab.strings[key]
    word_vectors[word_string] = vector.tolist()

and saving it with

file = "spacy_version_330_lg__string_to_embedding_map.json"

with open(file, 'w') as fp:
    json.dump(word_vectors, fp)

Maybe there is another, much cleaner way to do this, but this seems t…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by OmegaTauPhi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant