tf.nn.embedding_lookup函数的用法

tf.nn.embedding_lookup(params,ids)是用于查找在params中取出下标为ids的各个项

import numpy as np
import tensorflow as tf

x = np.array([[1,2,3],[4,5,6],[7,8,9]])
id1 = tf.Variable([1,2], tf.int32)
id2 = tf.Variable([[1,2],[1,0]], tf.int32)
a = tf.nn.embedding_lookup(x,id1)
b = tf.nn.embedding_lookup(x,id2)
init = tf.global_variables_initializer()
with tf.Session() as session:
    session.run(init)
    print(session.run(a))
    print('---------------------')
    print(session.run(b))
#输出
[[4 5 6]
 [7 8 9]]
---------------------
[[[4 5 6]
  [7 8 9]]

 [[4 5 6]
  [1 2 3]]]

你可能感兴趣的:(tensorflow)