Rate this Page

Struct CosineEmbeddingLossImpl#

Inheritance Relationships#

Base Type#

Struct Documentation#

structCosineEmbeddingLossImpl:publictorch::nn::Cloneable<CosineEmbeddingLossImpl>#

Creates a criterion that measures the loss given input tensorsinput1,input2, and aTensor labeltarget with values 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. Seehttps://pytorch.org/docs/main/nn.html#torch.nn.CosineEmbeddingLoss to learn about the exact behavior of this module.

See the documentation fortorch::nn::CosineEmbeddingLossOptions class to learn what constructor arguments are supported for this module.

Example:

CosineEmbeddingLossmodel(CosineEmbeddingLossOptions().margin(0.5));

Public Functions

explicitCosineEmbeddingLossImpl(CosineEmbeddingLossOptionsoptions_={})#
virtualvoidreset()override#

reset() must perform initialization of all members with reference semantics, most importantly parameters, buffers and submodules.

virtualvoidpretty_print(std::ostream&stream)constoverride#

Pretty prints theCosineEmbeddingLoss module into the givenstream.

Tensorforward(constTensor&input1,constTensor&input2,constTensor&target)#

Public Members

CosineEmbeddingLossOptionsoptions#

The options with which thisModule was constructed.