Pytorch nmt中注意解码器的余弦相似性 我正在实施一个神经机器翻译模型,对于解码器部分(带有注意机制),我想计算余弦相似度来找到分数。 以下是函数:

Pytorch nmt中注意解码器的余弦相似性 我正在实施一个神经机器翻译模型,对于解码器部分(带有注意机制),我想计算余弦相似度来找到分数。 以下是函数:,pytorch,cosine-similarity,machine-translation,Pytorch,Cosine Similarity,Machine Translation,分数(a,b)=/| a | | | | | b | 就我而言: a = htilde_t (N, H) b = h (S, N, H) the output should be (S, N) 我的困惑在于它们的尺寸,我不知道如何在pytorch中解决这个问题 参见此处: 您需要取消查询以添加重影标注,以使两个输入具有相同的尺寸标注: Input1: (∗1,D,∗2) where D is at position dim

分数(a,b)=/| a | | | | | b |

就我而言:

        a = htilde_t (N, H)

        b = h (S, N, H)

        the output should be (S, N)
我的困惑在于它们的尺寸,我不知道如何在pytorch中解决这个问题

参见此处:

您需要取消查询以添加重影标注,以使两个输入具有相同的尺寸标注:

    Input1: (∗1,D,∗2) where D is at position dim

    Input2: (∗1,D,∗2) , same shape as the Input1

    Output: (∗1,∗2)
请看这里:

您需要取消查询以添加重影标注,以使两个输入具有相同的尺寸标注:

    Input1: (∗1,D,∗2) where D is at position dim

    Input2: (∗1,D,∗2) , same shape as the Input1

    Output: (∗1,∗2)