torch.nn.functional.cosine_similarity¶
-
torch.nn.functional.
cosine_similarity
(x1, x2, dim=1, eps=1e-8) → Tensor¶ Returns cosine similarity between x1 and x2, computed along dim.
- Parameters
- Shape:
Input: where D is at position dim.
Output: where 1 is at position dim.
Example:
>>> input1 = torch.randn(100, 128) >>> input2 = torch.randn(100, 128) >>> output = F.cosine_similarity(input1, input2) >>> print(output)