Skip to content

Instantly share code, notes, and snippets.

@akash-ch2812
Created July 24, 2020 08:10
Show Gist options
  • Save akash-ch2812/94fce61eb3d0b2a9197aa8d499abc8a7 to your computer and use it in GitHub Desktop.
Save akash-ch2812/94fce61eb3d0b2a9197aa8d499abc8a7 to your computer and use it in GitHub Desktop.
# 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