Skip to content

treex.regularizers.L1

Create a regularizer that applies an L1 regularization penalty.

The L1 regularization penalty is computed as:

\ell_1\,\,penalty =\ell_1\sum_{i=0}^n|x_i|
Source code in treex/regularizers/l1l2.py
class L1(L1L2):
    r"""
    Create a regularizer that applies an L1 regularization penalty.

    The L1 regularization penalty is computed as:

    $$\ell_1\,\,penalty =\ell_1\sum_{i=0}^n|x_i|$$
    """

    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__(l1=l, reduction=reduction, weight=weight, on=on, name=name)