regularization_penalty
- opennmt.utils.regularization_penalty(regularization_type, scale, weights)[source]
Computes the weights regularization penalty.
- Parameters
regularization_type – The regularization type:
l1,l2, orl1_l2.scale – The regularization multiplier. If
regularization_typeisl1_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_typeis invalid or isl1_l2butscaleis not a sequence.