Weight decay helps limit overfitting by discouraging large model weights. It does this by adding a cost for large weights to the loss function. In neural networks, weight decay is mathematically equivalent to L2 regularization; L1 regularization instead penalizes the absolute values of weights. section 5.4.4
A practical starting point is to add L2 regularization when an overfitting model needs better generalization. The example applies it to the kernels of two Dense layers in an IMDb review classifier. section 5.4.4
Listing 5.13 Adding L2 weight regularization to the model
from keras.regularizers import l2 model = keras.Sequential( [ layers.Dense(16, kernel_regularizer=l2(0.002), activation="relu"), layers.Dense(16, kernel_regularizer=l2(0.002), activation="relu"), layers.Dense(1, activation="sigmoid"), ] ) model.compile( optimizer="rmsprop", loss="binary_crossentropy", metrics=["accuracy"], ) history_l2_reg = model.fit( train_data, train_labels, epochs=20, batch_size=512, validation_split=0.4, )
Keras example adding an L2 regularizer to Dense-layer kernels before compiling and training the model. section 5.4.4








