Hey Cameron,
Guess you would have already figured it out by now, but just in case you didnt, here you go:
------------------------------
--------------------------------------------------------------
model = gensim.models.Word2Vec.load(pathToTrainedModel)
# store the embeddings in a numpy array
embedding_matrix = np.zeros((len(model.wv.vocab) + 1, EMBEDDING_DIM))
for i in range(len(model.wv.vocab)):
embedding_vector = model.wv[model.wv.index2word[i]]
if embedding_vector is not None:
embedding_matrix[i] = embedding_vector
#free memory
del(model)
# memory efficient way to load the embeddings(avoids several copies of embeddings) in tf
embedding_weights = tf.Variable(tf.constant(0.0, shape=[len(model.wv.vocab) + 1, EMBEDDING_DIM]),
trainable=False, name="embedding_weights") #embedding layer weights are
frozen to avoid updating embeddings while training
embedding_placeholder = tf.placeholder(tf.float32, [len(model.wv.vocab) + 1, EMBEDDING_DIM])
embedding_init = embedding_weights.assign(embedding_placeholder)
with tf.Session() as sess:
sess.run(embedding_init, feed_dict={embedding_placeholder: embedding_matrix})
-----------------------------------------------------------------------------------
Regards,
Shiva.