import functools
import theano
import theano.tensor as T

fX = theano.config.floatX


def label_smoothing_categorical_crossentropy(pred, target, alpha, beta):
    if target.dtype == "int32":
        assert pred.ndim - 1 == target.ndim
        assert target.ndim == 1
        assert pred.dtype == fX
        assert pred.ndim == 2
        target = T.extra_ops.to_one_hot(target, nb_class=target, dtype=fX)
    return T.nnet.categorical_crossentropy(pred,
                                           T.clip(target, beta, alpha))


def label_smoothing_categorical_crossentropy_fn(alpha, beta):
    return functools.partial(label_smoothing_categorical_crossentropy,
                             alpha=alpha,
                             beta=beta)

@@ -133,28 +133,231 @@
 red,
- target, alpha, beta
+%0A                                             target,%0A                                             alpha,%0A                                             beta=None,%0A                                             num_classes=None
 ):%0A 
@@ -586,24 +586,99 @@
 ass=
-target, dtype=fX
+num_classes, dtype=fX)%0A    if beta is None:%0A        beta = (1.0 - alpha) / (num_classes - 1
 )%0A  
@@ -852,21 +852,140 @@
 n(alpha,
- beta
+%0A                                                beta=None,%0A                                                num_classes=None
 ):%0A    r
@@ -1130,10 +1130,64 @@
 eta=beta
+,%0A                             num_classes=num_classes
 )%0A

fix label smoothing