We know that margin loss is given as follows:
Compute the maximum value in the left and maximum value in the right:
max_left = tf.square(tf.maximum(0.,0.9 - v_length))
max_right = tf.square(tf.maximum(0., v_length - 0.1))
Set to :
T_k = y
lambda_ = 0.5
L_k = T_k * max_left + lambda_ * (1 - T_k) * max_right
The total margin loss is computed as follows:
margin_loss = tf.reduce_mean(tf.reduce_sum(L_k, axis=1))