Shortcuts

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 https://pytorch.org/docs/main/nn.html#torch.nn.CosineEmbeddingLoss 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.

Example:

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.

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources