假设需要通过查找表访问的具有不可连接对象的列表.因此列表索引将是张量对象,但这是不可能的.
tf_look_up = tf.constant(np.array([3, 2, 1, 0, 4]))
index = tf.constant(2)
list = [0,1,2,3,4]
target = list[tf_look_up[index]]
Run Code Online (Sandbox Code Playgroud)
这将显示以下错误消息.
TypeError: list indices must be integers or slices, not Tensor
Run Code Online (Sandbox Code Playgroud)
是使用张量索引列表的方法/解决方法吗?
我想以批量方式从TensorFlow中的DNC实现中实现此公式.
使用批量密集张量,它非常简单.
# w [B, N], p [B, N], L [B, N, N], B=batch_size
dot_prod = tf.batch_matmul(tf.expand_dims(w, axis=2), tf.expand_dims(p, axis=1))
one_prod = 1 - tf.expand_dims(w, 1) - tf.expand_dims(w, 2)
L = one_prod * pre_L + dot_prod
Run Code Online (Sandbox Code Playgroud)
有没有办法用稀疏张量实现这个?w,p和L是稀疏的,但TensorFlow缺乏稀疏批处理matmul和稀疏索引.