PyTorch
torch / nn / torch.nn
CosineSimilarity¶
-
class
torch.nn.
CosineSimilarity
(dim: int = 1, eps: float = 1e-08)[source]¶ Returns cosine similarity between x1 and x2 , computed along dim.
similarity=max(∥x1∥2⋅∥x2∥2,ϵ)x1⋅x2.- Parameters
- Shape:
Input1: (∗1,D,∗2) where D is at position dim
Input2: (∗1,D,∗2) , same shape as the Input1
Output: (∗1,∗2)
- Examples::
>>> input1 = torch.randn(100, 128) >>> input2 = torch.randn(100, 128) >>> cos = nn.CosineSimilarity(dim=1, eps=1e-6) >>> output = cos(input1, input2)
此页内容是否对您有帮助
感谢反馈!