Skip to content

Instantly share code, notes, and snippets.

@khuangaf
Created February 16, 2018 11:01
Show Gist options
  • Save khuangaf/e72acfc1ba28808c37b819cd7abcc363 to your computer and use it in GitHub Desktop.
Save khuangaf/e72acfc1ba28808c37b819cd7abcc363 to your computer and use it in GitHub Desktop.
item_index = { str(i):i for i in range(931)}
embeddings_index={}
f = open( 'data/item_vectors.txt')
for line in f:
values = line.split()
word = values[0]
coefs = np.asarray(values[1:], dtype='float32')
embeddings_index[word] = coefs
f.close()
embedding_matrix = np.zeros((max_features, embed_size))
for word, i in item_index.items():
if i < max_features:
embedding_vector = embeddings_index.get(word)
if embedding_vector is not None:
embedding_matrix[i] = embedding_vector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment