View source: R/gen-namespace.R
torch_cosine_similarity | R Documentation |
Cosine_similarity
torch_cosine_similarity(x1, x2, dim = 2L, eps = 1e-08)
x1 |
(Tensor) First input. |
x2 |
(Tensor) Second input (of size matching x1). |
dim |
(int, optional) Dimension of vectors. Default: 1 |
eps |
(float, optional) Small value to avoid division by zero. Default: 1e-8 |
Returns cosine similarity between x1 and x2, computed along dim.
\mbox{similarity} = \frac{x_1 \cdot x_2}{\max(\Vert x_1 \Vert _2 \cdot \Vert x_2 \Vert _2, \epsilon)}
if (torch_is_installed()) {
input1 = torch_randn(c(100, 128))
input2 = torch_randn(c(100, 128))
output = torch_cosine_similarity(input1, input2)
output
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.