Shortcuts

Struct CrossEntropyLossImpl

Inheritance Relationships

Base Type

Struct Documentation

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

Creates a criterion that computes cross entropy loss between input and target.

See https://pytorch.org/docs/main/nn.html#torch.nn.CrossEntropyLoss to learn about the exact behavior of this module.

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

Example:

CrossEntropyLoss
model(CrossEntropyLossOptions().ignore_index(-100).reduction(torch::kMean));

Public Functions

explicit CrossEntropyLossImpl(CrossEntropyLossOptions 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 CrossEntropyLoss module into the given stream.

Tensor forward(const Tensor &input, const Tensor &target)

Public Members

CrossEntropyLossOptions options

The options with which this Module was constructed.

Tensor weight

A manual rescaling weight given to to each class.

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