-
-
Save stjordanis/21811acd9bb87978bd7d7bbfae25382d 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
# Load in embeddings | |
glove_vectors = '/home/ubuntu/.keras/datasets/glove.6B.100d.txt' | |
glove = np.loadtxt(glove_vectors, dtype='str', comments=None) | |
# Extract the vectors and words | |
vectors = glove[:, 1:].astype('float') | |
words = glove[:, 0] | |
# Create lookup of words to vectors | |
word_lookup = {word: vector for word, vector in zip(words, vectors)} | |
# New matrix to hold word embeddings | |
embedding_matrix = np.zeros((num_words, vectors.shape[1])) | |
for i, word in enumerate(word_idx.keys()): | |
# Look up the word embedding | |
vector = word_lookup.get(word, None) | |
# Record in matrix | |
if vector is not None: | |
embedding_matrix[i + 1, :] = vector |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment