Cosine_similarity
Source:R/gen-namespace-docs.R
, R/gen-namespace-examples.R
, R/gen-namespace.R
torch_cosine_similarity.Rd
Cosine_similarity
cosine_similarity(x1, x2, dim=1, eps=1e-8) -> Tensor
Returns cosine similarity between x1 and x2, computed along dim.
Examples
if (torch_is_installed()) {
input1 = torch_randn(c(100, 128))
input2 = torch_randn(c(100, 128))
output = torch_cosine_similarity(input1, input2)
output
}
#> torch_tensor
#> -0.0109
#> 0.1864
#> 0.1400
#> 0.1101
#> -0.0260
#> 0.0457
#> -0.0791
#> -0.0797
#> 0.0573
#> 0.1426
#> -0.0411
#> -0.0690
#> 0.0023
#> -0.2670
#> -0.0099
#> 0.0596
#> -0.0527
#> 0.0587
#> 0.0378
#> -0.0902
#> -0.0113
#> 0.0550
#> -0.0705
#> 0.0101
#> -0.1094
#> -0.0458
#> 0.1526
#> -0.0457
#> -0.0750
#> 0.0340
#> ... [the output was truncated (use n=-1 to disable)]
#> [ CPUFloatType{100} ]