CosineSimilarity#
- class torch.nn.modules.distance.CosineSimilarity(dim=1, eps=1e-08)[源]#
在 dim 维度上计算 和 之间的余弦相似度。
- 形状
Input1: 其中 D 是在 dim 位置上的维度。
Input2: ,其维度数与 x1 相同,在 dim 维度上与 x1 匹配,并在其他维度上与 x1 可广播。
Output:
示例
>>> input1 = torch.randn(100, 128) >>> input2 = torch.randn(100, 128) >>> cos = nn.CosineSimilarity(dim=1, eps=1e-6) >>> output = cos(input1, input2)