Skip to content

Instantly share code, notes, and snippets.

@hccho2
Created July 29, 2019 10:16
Show Gist options
  • Save hccho2/4bf4fbdd44ef9bf04c3a060bd946ac13 to your computer and use it in GitHub Desktop.
Save hccho2/4bf4fbdd44ef9bf04c3a060bd946ac13 to your computer and use it in GitHub Desktop.
import numpy as np
import tensorflow as tf
tf.reset_default_graph()
x_data= tf.placeholder(tf.int32,shape=[None,6])
vocab_size=5
init = np.arange(5*3).reshape(vocab_size,-1)
embedding = tf.get_variable("embedding", initializer=init.astype(np.float32),dtype = tf.float32)
inputs = tf.nn.embedding_lookup(embedding, x_data)
sess= tf.Session()
sess.run(tf.global_variables_initializer())
x = sess.run(inputs,feed_dict={x_data:[[0,1,2,3,5,7]]})
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment