实际上tf.nn.embedding_lookup的作用就是找到要寻找的embedding data中的对应的行下的vector
例如:
import numpy as np
import tensorflow as tf
params = np.identity(5)
print(params)
[[1. 0. 0. 0. 0.]
[0. 1. 0. 0. 0.]
[0. 0. 1. 0. 0.]
[0. 0. 0. 1. 0.]
[0. 0. 0. 0. 1.]]
ids = [1,2,3] out = tf.nn.embedding_lookup(params,ids) sess = tf.InteractiveSession() print(sess.run(out))
[[0. 1. 0. 0. 0.]
[0. 0. 1. 0. 0.]
[0. 0. 0. 1. 0.]]
根据ids从params里寻找对应的下标的值。即从params中取出下标为1,2,3的数据。