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.1676
#> 0.0988
#> -0.1302
#> -0.1581
#> -0.0654
#> 0.0243
#> 0.0110
#> -0.0974
#> 0.0993
#> -0.0466
#> 0.0571
#> -0.0185
#> 0.0312
#> 0.0125
#> -0.0400
#> 0.1636
#> -0.1599
#> -0.0683
#> -0.0341
#> 0.0006
#> -0.0665
#> 0.0469
#> 0.0857
#> -0.0465
#> 0.0015
#> 0.0369
#> 0.0041
#> 0.1600
#> 0.1003
#> 0.0976
#> ... [the output was truncated (use n=-1 to disable)]
#> [ CPUFloatType{100} ]