Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

nn_hinge_embedding_loss

Hinge embedding loss


Description

Measures the loss given an input tensor x and a labels tensor y (containing 1 or -1).

Usage

nn_hinge_embedding_loss(margin = 1, reduction = "mean")

Arguments

margin

(float, optional): Has a default value of 1.

reduction

(string, optional): Specifies the reduction to apply to the output: 'none' | 'mean' | 'sum'. 'none': no reduction will be applied, 'mean': the sum of the output will be divided by the number of elements in the output, 'sum': the output will be summed. Note: size_average and reduce are in the process of being deprecated, and in the meantime, specifying either of those two args will override reduction. Default: 'mean'

Details

This is usually used for measuring whether two inputs are similar or dissimilar, e.g. using the L1 pairwise distance as x, and is typically used for learning nonlinear embeddings or semi-supervised learning. The loss function for n-th sample in the mini-batch is

l_n = \begin{array}{ll} x_n, & \mbox{if}\; y_n = 1,\\ \max \{0, Δ - x_n\}, & \mbox{if}\; y_n = -1, \end{array}

and the total loss functions is

\ell(x, y) = \begin{array}{ll} \mbox{mean}(L), & \mbox{if reduction} = \mbox{'mean';}\\ \mbox{sum}(L), & \mbox{if reduction} = \mbox{'sum'.} \end{array}

where L = \{l_1,…,l_N\}^\top.

Shape

  • Input: (*) where * means, any number of dimensions. The sum operation operates over all the elements.

  • Target: (*), same shape as the input

  • Output: scalar. If reduction is 'none', then same shape as the input


torch

Tensors and Neural Networks with 'GPU' Acceleration

v0.3.0
MIT + file LICENSE
Authors
Daniel Falbel [aut, cre, cph], Javier Luraschi [aut], Dmitriy Selivanov [ctb], Athos Damiani [ctb], Christophe Regouby [ctb], Krzysztof Joachimiak [ctb], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.