Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. def get_embedded_matrix(max_words,embedding_dim,vocab,embeddings_index):
  2.     counter = 0
  3.     total_ct = 0
  4.     embedding_matrix = np.zeros((max_words, embedding_dim))
  5.     for word,index in vocab.items():
  6.         total_ct += 1
  7.         embedding_vector = embeddings_index.get(word)
  8.         if embedding_vector is not None:
  9.             embedding_matrix[index] = embedding_vector
  10.             counter += 1
  11.         else:
  12.             embedding_matrix[index] = np.random.uniform(-0.25, 0.25, embedding_dim)
  13.     print('Total ',total_ct,' gasit ',counter)
  14.     return embedding_matrix
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement