创建随机可训练索引以从张量流中的一个 2_D 张量构建两个 2_D 张量
Create random trainable indices to build two 2_D tensor from one 2_D tensor in tensorflow
我正在尝试从一个张量 AAA[=22= 创建两个形状为 shape=(30, 4200) 的张量] 形状=(30, 4201) 类型= float32.
此错误在运行代码有几处不同的更改后会再次出现。
如何 select 正确的张量形状?
这就是您将 tf.gather_nd
用于您的案例的方式:
# If V1_emb and V2_emb have different shapes you need to take the shape of each one
s = tf.shape(V1, out_type=V1_emb.dtype)
batch_idx = tf.tile(tf.expand_dims(tf.range(s[0]), 1), [1, s[1]])
V1 = tf.gather_nd(params=AAA, indices=tf.stack([batch_idx, V1_emb], axis=-1))
V2 = tf.gather_nd(params=AAA, indices=tf.stack([batch_idx, V2_emb], axis=-1))
我正在尝试从一个张量 AAA[=22= 创建两个形状为 shape=(30, 4200) 的张量] 形状=(30, 4201) 类型= float32.
此错误在运行代码有几处不同的更改后会再次出现。
如何 select 正确的张量形状?
这就是您将 tf.gather_nd
用于您的案例的方式:
# If V1_emb and V2_emb have different shapes you need to take the shape of each one
s = tf.shape(V1, out_type=V1_emb.dtype)
batch_idx = tf.tile(tf.expand_dims(tf.range(s[0]), 1), [1, s[1]])
V1 = tf.gather_nd(params=AAA, indices=tf.stack([batch_idx, V1_emb], axis=-1))
V2 = tf.gather_nd(params=AAA, indices=tf.stack([batch_idx, V2_emb], axis=-1))