Struct CosineEmbeddingLossImpl

Inheritance Relationships

Base Type

Struct Documentation

struct CosineEmbeddingLossImpl : public torch::nn::Cloneable<CosineEmbeddingLossImpl>

Creates a criterion that measures the loss given input tensors input1, input2, and a Tensor label target 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. See to learn about the exact behavior of this module.

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


CosineEmbeddingLoss model(CosineEmbeddingLossOptions().margin(0.5));

Public Functions

explicit CosineEmbeddingLossImpl(CosineEmbeddingLossOptions options_ = {})
virtual void reset() override

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

virtual void pretty_print(std::ostream &stream) const override

Pretty prints the CosineEmbeddingLoss module into the given stream.

Tensor forward(const Tensor &input1, const Tensor &input2, const Tensor &target)

Public Members

CosineEmbeddingLossOptions options

The options with which this Module was constructed.


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources