# tensor是输入张量
# id就是张量对那个的索引
tf.nn.embedding_lookup(tensor, id)
该函数的用法主要是选取一个张量里面索引对应的元素,例如:
# 示例
import tensorflow as tf
import numpy as np
c = np.random.random([10, 1])
b = tf.nn.embedding_lookup(c, [1, 3])
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
print("b\n" + str(sess.run(b)))
print("c\n" + str(c))
# 输出
b
[[0.16904814]
[0.45015154]]
c
[[0.40655617]
[0.16904814]
[0.61787992]
[0.45015154]
[0.01681443]
[0.46908087]
[0.84033554]
[0.92226145]
[0.11049313]
[0.0526304 ]]
参考自https://blog.csdn.net/UESTC_C2_403/article/details/72779417