Skip to content

treex.regularizers.L2

Create a regularizer that applies an L2 regularization penalty.

The L2 regularization penalty is computed as:

\ell_2\,\,penalty =\ell_2\sum_{i=0}^nx_i^2 ```

Source code in treex/regularizers/l1l2.py
class L2(L1L2):
    r"""
    Create a regularizer that applies an L2 regularization penalty.

    The L2 regularization penalty is computed as:

    $$\ell_2\,\,penalty =\ell_2\sum_{i=0}^nx_i^2$$
    ```
    """

    def __init__(
        self,
        l: float = 0.01,
        reduction: tp.Optional[Reduction] = None,
        weight: tp.Optional[float] = None,
        on: tp.Optional[types.IndexLike] = None,
        name: tp.Optional[str] = None,
    ):
        super().__init__(l2=l, reduction=reduction, weight=weight, on=on, name=name)