Created
December 7, 2017 10:33
-
-
Save rajeshmr/7cad546aabdcfed25e22c474e8424748 to your computer and use it in GitHub Desktop.
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
from keras.layers import Embedding | |
word_index = tokenizer.word_index | |
nb_words = min(MAX_NB_WORDS, len(word_index))+1 | |
embedding_matrix = np.zeros((nb_words, EMBEDDING_DIM)) | |
for word, i in word_index.items(): | |
if word in word2vec.vocab: | |
embedding_matrix[i] = word2vec.word_vec(word) | |
print('Null word embeddings: %d' % np.sum(np.sum(embedding_matrix, axis=1) == 0)) | |
embedding_layer = Embedding(embedding_matrix.shape[0], # or len(word_index) + 1 | |
embedding_matrix.shape[1], # or EMBEDDING_DIM, | |
weights=[embedding_matrix], | |
input_length=MAX_SEQUENCE_LENGTH, | |
trainable=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment