Documentation
¶
Overview ¶
Package loss provides various loss functions for neural networks.
Index ¶
- type CrossEntropyLoss
- func (cel *CrossEntropyLoss[T]) Backward(ctx context.Context, dOut *tensor.Tensor[T], inputs ...*tensor.Tensor[T]) ([]*tensor.Tensor[T], error)
- func (cel *CrossEntropyLoss[T]) Forward(ctx context.Context, inputs ...*tensor.Tensor[T]) (*tensor.Tensor[T], error)
- func (cel *CrossEntropyLoss[T]) OutputShape(inputShapes ...[]int) ([]int, error)
- func (cel *CrossEntropyLoss[T]) Parameters() []graph.Parameter[T]
- type Loss
- type MSE
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CrossEntropyLoss ¶
CrossEntropyLoss computes the cross-entropy loss.
func NewCrossEntropyLoss ¶
func NewCrossEntropyLoss[T tensor.Numeric](engine compute.Engine[T]) *CrossEntropyLoss[T]
NewCrossEntropyLoss creates a new CrossEntropyLoss layer.
func (*CrossEntropyLoss[T]) Backward ¶
func (cel *CrossEntropyLoss[T]) Backward(ctx context.Context, dOut *tensor.Tensor[T], inputs ...*tensor.Tensor[T]) ([]*tensor.Tensor[T], error)
Backward computes the gradients for CrossEntropyLoss. dOut is typically a scalar (1.0) for loss functions.
func (*CrossEntropyLoss[T]) Forward ¶
func (cel *CrossEntropyLoss[T]) Forward(ctx context.Context, inputs ...*tensor.Tensor[T]) (*tensor.Tensor[T], error)
Forward computes the cross-entropy loss. Inputs: predictions (logits), targets (int labels).
func (*CrossEntropyLoss[T]) OutputShape ¶
func (cel *CrossEntropyLoss[T]) OutputShape(inputShapes ...[]int) ([]int, error)
OutputShape returns the output shape of the loss (a scalar).
func (*CrossEntropyLoss[T]) Parameters ¶
func (cel *CrossEntropyLoss[T]) Parameters() []graph.Parameter[T]
Parameters returns an empty slice as CrossEntropyLoss has no trainable parameters.
type Loss ¶
type Loss[T tensor.Numeric] interface { // Forward computes the loss and its gradient. Forward(predictions, targets *tensor.Tensor[T]) (T, *tensor.Tensor[T]) }
Loss defines the interface for loss functions.
Click to show internal directories.
Click to hide internal directories.