allennlp.nn.regularizers

This module contains classes representing regularization schemes as well as a class for applying regularization to parameters.

class allennlp.nn.regularizers.regularizer.Regularizer[source]

Bases: allennlp.common.registrable.Registrable

An abstract class representing a regularizer. It must implement call, returning a scalar tensor.

default_implementation: str = 'l2'
class allennlp.nn.regularizers.regularizers.L1Regularizer(alpha: float = 0.01)[source]

Bases: allennlp.nn.regularizers.regularizer.Regularizer

Represents a penalty proportional to the sum of the absolute values of the parameters

class allennlp.nn.regularizers.regularizers.L2Regularizer(alpha: float = 0.01)[source]

Bases: allennlp.nn.regularizers.regularizer.Regularizer

Represents a penalty proportional to the sum of squared values of the parameters

class allennlp.nn.regularizers.regularizer_applicator.RegularizerApplicator(regularizers: Sequence[Tuple[str, allennlp.nn.regularizers.regularizer.Regularizer]] = ())[source]

Bases: object

Applies regularizers to the parameters of a Module based on regex matches.

classmethod from_params(params: Iterable[Tuple[str, allennlp.common.params.Params]] = ()) → Union[ForwardRef('RegularizerApplicator'), NoneType][source]

Converts a List of pairs (regex, params) into an RegularizerApplicator. This list should look like

[[“regex1”, {“type”: “l2”, “alpha”: 0.01}], [“regex2”, “l1”]]

where each parameter receives the penalty corresponding to the first regex that matches its name (which may be no regex and hence no penalty). The values can either be strings, in which case they correspond to the names of regularizers, or dictionaries, in which case they must contain the “type” key, corresponding to the name of a regularizer. In addition, they may contain auxiliary named parameters which will be fed to the regularizer itself. To determine valid auxiliary parameters, please refer to the torch.nn.init documentation.

Parameters
paramsParams, required.

A Params object containing a “regularizers” key.

Returns
A RegularizerApplicator containing the specified Regularizers,
or None if no Regularizers are specified.