LpRegularizer

class LpRegularizer(*, weight: float = 1.0, apply_only_once: bool = False, dim: int | None = -1, normalize: bool = False, p: float = 2.0, **kwargs)[source]

Bases: Regularizer

A simple L_p norm based regularizer.

Initialize the regularizer.

Parameters:
  • weight (Tensor) – The relative weight of the regularization

  • apply_only_once (bool) – Should the regularization be applied more than once after reset?

  • dim (int | None) – the dimension along which to calculate the Lp norm, cf. lp_norm()

  • normalize (bool) – whether to normalize the norm by the dimension, cf. lp_norm()

  • p (float) – the parameter \(p\) of the Lp norm, cf. lp_norm()

  • kwargs – additional keyword-based parameters passed to Regularizer.__init__()

Methods Summary

forward(x)

Compute the regularization term for one tensor.

Methods Documentation

forward(x: Tensor) Tensor[source]

Compute the regularization term for one tensor.

Parameters:

x (Tensor)

Return type:

Tensor