'Applies a label smoothing regularization.
Uses the same method as in https://arxiv.org/abs/1512.00567.
Args:
chars_labels: ground truth ids of charactes,
shape=[batch_size, seq_length];
weight: label-smoothing regularization weight.
Returns:
A sensor with the same shape as the input.'

def label_smoothing_regularization(self, chars_labels, weight=0.1):

    one_hot_labels = tf.one_hot(chars_labels, depth=self._params.num_char_classes, axis=(-1))
    pos_weight = (1.0 - weight)
    neg_weight = (weight / self._params.num_char_classes)
    return ((one_hot_labels * pos_weight) + neg_weight)
