criterion = nn.CosineEmbeddingCriterion(margin)
Creates a criterion that measures the loss given an input
x
= {x1,x2}
, a table of two tensors, and a label y
(1 or -1):
This is used for measuring whether two inputs are similar
or dissimilar, using the cosine distance, and is typically used for
learning nonlinear embeddings or semi-supervised learning.
margin
should be a number from -1 to 1, 0 to 0.5 is suggested.
Forward and Backward have to be used alternately. If margin
is missing, the default value is 0.
The loss function is:
loss(x,y) = forward(x,y) = 1-cos(x1, x2), if y=1 = max(0,cos(x1, x2)-margin), if y=-1