小编wal*_*mid的帖子

有没有办法将pytorch张量转换为tensorflow张量

https://github.com/taoshen58/BiBloSA/blob/ec67cbdc411278dd29e8888e9fd6451695efc26c/context_fusion/self_attn.py#L29

我需要使用上述链接中的 multi_Dimension_attention,该链接是在 TensorFlow 中实现的,但我使用的是 PyTorch,所以我可以将 Pytorch 张量转换为 TensorFlow 张量,还是必须在 PyTorch 中实现它。

我试图在这里使用的代码我必须将“rep_tensor”作为 TensorFlow 张量类型传递,但我有 PyTorch 张量

def multi_dimensional_attention(rep_tensor, rep_mask=None, scope=None,
                                keep_prob=1., is_train=None, wd=0., activation='elu',
                                tensor_dict=None, name=None):

    # bs, sl, vec = tf.shape(rep_tensor)[0], tf.shape(rep_tensor)[1], tf.shape(rep_tensor)[2]

    ivec = rep_tensor.shape[2]
    with tf.variable_scope(scope or 'multi_dimensional_attention'):
        map1 = bn_dense_layer(rep_tensor, ivec, True, 0., 'bn_dense_map1', activation,
                              False, wd, keep_prob, is_train)
        map2 = bn_dense_layer(map1, ivec, True, 0., 'bn_dense_map2', 'linear',
                              False, wd, keep_prob, is_train)
        # map2_masked = exp_mask_for_high_rank(map2, rep_mask)

        soft = tf.nn.softmax(map2, 1)  # bs,sl,vec
        attn_output = tf.reduce_sum(soft …
Run Code Online (Sandbox Code Playgroud)

attention-model pytorch mindsdb

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

attention-model ×1

mindsdb ×1

pytorch ×1