Skip to content

Instantly share code, notes, and snippets.

@joeyism
Last active September 27, 2018 20:58
Show Gist options
  • Save joeyism/d306cef8709f9a6b25f2fe319282966d to your computer and use it in GitHub Desktop.
Save joeyism/d306cef8709f9a6b25f2fe319282966d to your computer and use it in GitHub Desktop.
import tensorflow_hub as hub
import tensorflow as tf
word_to_embed = "dog"
elmo = hub.Module("https://tfhub.dev/google/elmo/2")
embedding_tensor = elmo([word_to_embed], as_dict=True)["word_emb"] # Use as_dict because I want the whole dict, then I select "word_emb"
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
embedding = sess.run(embedding_tensor)
print(embedding.shape)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment