Regularizers
Mapping of Keras regularizers to DL4J regularization for model import in Eclipse Deeplearning4j 1.0.0-rewrite.
Keras allows L1 and L2 regularization penalties to be applied to layer kernels, biases, and activations. DL4J supports all standard Keras regularizers and maps them to equivalent regularization parameters in the layer configuration.
The mapping is implemented in KerasRegularizerUtils.
Supported Regularizers
l1
L1Regularization
L1 (Lasso) weight penalty
l2
L2Regularization
L2 (Ridge) weight penalty
l1_l2
L1L2Regularization
Combined L1 and L2 penalty (Elastic Net)
Regularizer Descriptions
l1
Adds the sum of the absolute values of the weights to the loss function, scaled by the regularization coefficient. L1 regularization encourages sparsity — many weights will be driven to exactly zero.
# Keras
from keras.regularizers import l1
layer = Dense(64, kernel_regularizer=l1(0.01))// DL4J equivalent (applied via layer configuration)
.l1(0.01)Keras parameter:
l
0.01
Regularization coefficient
l2
Adds the sum of the squared weights to the loss function, scaled by the regularization coefficient. L2 regularization (weight decay) penalises large weights and generally produces smoother, more generalisable models.
Keras parameter:
l
0.01
Regularization coefficient
l1_l2
Combines L1 and L2 penalties (Elastic Net regularization). Both coefficients can be set independently.
Keras parameters:
l1
0.01
L1 regularization coefficient
l2
0.01
L2 regularization coefficient
Regularization Targets
In Keras, regularization can be applied separately to kernels, biases, and activations:
DL4J maps kernel_regularizer and bias_regularizer directly to the layer's l1/l2 settings. activity_regularizer (applied to the layer output rather than the weights) is not currently supported during import.
Usage Example
Notes
Regularization affects the training loss, not inference. For inference-only import, the regularizer config is loaded but has no practical effect.
Custom Python regularizer classes cannot be imported.
activity_regularizeris not supported; a warning is logged if it is present.
Last updated
Was this helpful?