# opennmt.utils.regularization_penalty¶

opennmt.utils.regularization_penalty(regularization_type, scale, weights)[source]

Computes the weights regularization penalty.

Parameters
• regularization_type – The regularization type: l1, l2, or l1_l2.

• scale – The regularization multiplier. If regularization_type is l1_l2, this should be a list or tuple containing the L1 regularization scale and the L2 regularization scale.

• weights – The list of weights.

Returns

The regularization penalty.

Raises

ValueError – if regularization_type is invalid or is l1_l2 but scale is not a sequence.