Created
July 24, 2020 08:10
-
-
Save akash-ch2812/94fce61eb3d0b2a9197aa8d499abc8a7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# create word embeddings | |
import spacy | |
nlp = spacy.load('en_core_web_lg') | |
# create word embeddings | |
embedding_dimension = 300 | |
embedding_matrix = np.zeros((vocab_len, embedding_dimension)) | |
# travel through every word in vocabulary and get its corresponding vector | |
for word, index in tokenizer.word_index.items(): | |
doc = nlp(word) | |
embedding_vector = np.array(doc.vector) | |
embedding_matrix[index] = embedding_vector | |
# adding embeddings to model | |
predictive_model.layers[2] | |
predictive_model.layers[2].set_weights([embedding_matrix]) | |
predictive_model.layers[2].trainable = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment