7. Optimization of Training in Deep Learning (Design Robust Bi-Tempered Logistic Loss)
AIM: Design a Deep learning Network for Robust Bi-Tempered Logistic Loss
Theory:
The Robust Bi-Tempered Logistic Loss is a loss function designed for training deep neural networks, particularly in the context of classification tasks. It addresses some of the limitations of traditional loss functions like the standard cross-entropy loss, which can suffer from issues like vanishing gradients and sensitivity to outliers. The Robust Bi-Tempered Logistic Loss aims to provide better convergence properties and improved robustness to noisy or mislabeled data.
Program:
import tensorflow as tf
import numpy as np
# Define the Robust Bi-Tempered Logistic Loss
def robust_bi_tempered_logistic_ loss(y_true, y_pred, t1=0.8, t2=1.2, label_smoothing=0.1):
y_true = tf.cast(y_true, dtype=tf.float32)
y_pred = tf.math.softmax(y_pred, axis=-1)
temp1 = (1 - y_true) * tf.math.maximum(y_pred - t1, 0)
temp2 = (1 - y_true) * tf.math.maximum(y_pred - t2, 0) + tf.math.log(1 + tf.exp(-tf.abs(y_pred - t2)))
loss_value = - (1 - label_smoothing) * tf.reduce_sum(temp1 + temp2) - label_smoothing * tf.reduce_sum(y_true * tf.math.log(y_pred + 1e-10))
return loss_value
# Create a simple noisy dataset
X_train = np.random.rand(100, 10)
y_train = np.random.randint(0, 10, size=(100,))
# Define a simple model
model = tf.keras.Sequential([
tf.keras.layers.Dense(64, activation='relu', input_shape=(10,)),
tf.keras.layers.Dense(10)
])
# Compile the model with the custom loss function
model.compile(optimizer='adam' , loss=robust_bi_tempered_ logistic_loss)
# Train the model
model.fit(X_train, y_train, epochs=10)
Output:
Output:
Epoch 1/10 4/4 [==============================] - 1s 4ms/step - loss: 252.8754 Epoch 2/10 4/4 [============================= =] - 0s 5ms/step - loss: 245.7204 Epoch 3/10 4/4 [============================= =] - 0s 3ms/step - loss: 253.1844 Epoch 4/10 4/4 [============================= =] - 0s 3ms/step - loss: 255.6411 Epoch 5/10 4/4 [============================= =] - 0s 3ms/step - loss: 240.7367 Epoch 6/10 4/4 [============================= =] - 0s 3ms/step - loss: 247.8149 Epoch 7/10 4/4 [============================= =] - 0s 7ms/step - loss: 245.1912 Epoch 8/10 4/4 [============================= =] - 0s 6ms/step - loss: 248.3541 Epoch 9/10 4/4 [============================= =] - 0s 5ms/step - loss: 246.3749 Epoch 10/10 4/4 [============================= =] - 0s 3ms/step - loss: 247.6301
<keras.callbacks.History at 0x79425fd40ac0>
Comments
Post a Comment