关于此函数的计算流程,详解如下:
input1 = torch.tensor([[1, 2],[1,2]],dtype=torch.float) input2 = torch.tensor([[2, 4],[3,4]],dtype=torch.float) cos = nn.CosineSimilarity(dim=0, eps=1e-6) output = cos(input1, input2)
(dim=0)计算流程是:(1*1+1*3)/根号(1的平方+1的平方)/根号(2的平方+3的平方)=5/根号2/根号13=0.9806,另外一个输出计算方式一样;
input1 = torch.tensor([[1, 2],[1,2]],dtype=torch.float) input2 = torch.tensor([[2, 4],[3,4]],dtype=torch.float) cos = nn.CosineSimilarity(dim=1, eps=1e-6) output = cos(input1, input2)
(dim=1)计算流程是:(1*2+2*4)/根号(1的平方+2的平方)/根号(2的平方+4的平方)=10/根号5/根号20=1,另外一个输出计算方式一样;
标签:CosineSimilarity,input2,平方,input1,nn,torch,根号 From: https://www.cnblogs.com/littlePower/p/16769084.html