我有两个三维的张量:
tensor 1 (bs1, sent_len1, emb_dim) tensor 2 (bs2, sent_len2, emb_dim)
bs1和bs2是未知的,并且它们不一定相等。
我想对这些张量进行乘积操作,得到如下输出:
output (bs1, bs2, sent_len2, sent_len1)
回答:
使用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)