Regularizations

built_regularizer

built_regularizer(fct, collect)

Builds the regularizer function.

  • Args:
    • fct: the metric function to build.
    • collect: whether to collect this metric under the metric collection.

l2_regularizer

l2_regularizer(scale=0.001, name='l2Regularizer', collect=True)

Returns a function that can be used to apply L2 regularization to a tensor.

Computes half the L2 norm of a tensor without the sqrt:

output = sum(t ** 2) / 2 * wd

  • Args:

    • x: Tensor. The tensor to apply regularization.
    • scale: float. A scalar multiplier Tensor. 0.0 disables the regularizer.
    • name: str name of the app.
    • collect: add to regularization losses
  • Returns: The regularization Tensor.


l1_regularizer

l1_regularizer(scale=0.001, name='l1Regularizer', collect=True)

Returns a function that can be used to apply L1 regularization to a tensor.

Computes the L1 norm of a tensor:

output = sum(|t|) * scale

  • Args:

    • scale: float. A scalar multiplier Tensor. 0.0 disables the regularizer.
    • name: name of the app.
    • collect: add to regularization losses
  • Returns: The regularization Tensor.


l2_l1_regularizer

l2_l1_regularizer(scale_l1=0.001, scale_l2=0.001, name='l2l1Regularizer', collect=True)

Returns a function that can be used to apply L2 L1 regularization to a tensor.

Computes the L2 and L1 norm of a tensor:

  • Args:

    • scale_l1: float. A scalar multiplier Tensor. 0.0 disables the regularizer.
    • scale_l2: float. A scalar multiplier Tensor. 0.0 disables the regularizer.
    • name: name of the app.
    • collect: add to regularization losses
  • Returns: The regularization Tensor.