我有两个3维的张量:
tensor 1 (bs1, sent_len1, emb_dim)
tensor 2 (bs2, sent_len2, emb_dim)
bs1和bs2未知,它们不一定相等。
我想乘积这些张量以获得如下输出:
output (bs1, bs2, sent_len2, sent_len1)
答案 0 :(得分:0)
像这样使用K.dot():
t2t = K.permute_dimensions(tensor2, [0, 2, 1]) # (bs2, emb_dim, sent_len2)
output = K.dot(tensor1, t2t) # (bs1, sent_len1, bs2, sent_len2)