import numpy as np
import paddle

from pptb.nn import LabelSmoothingLoss


def test_label_smoothing_loss():
    batch_size = 5
    num_classes = 24
    label_smooth_epision = 0.1
    loss_function = LabelSmoothingLoss(paddle.nn.CrossEntropyLoss(soft_label=True), num_classes, label_smooth_epision)
    predicts_data = paddle.uniform([batch_size, num_classes], dtype=paddle.float32)
    labels_data = np.random.randint(0, num_classes, size=(batch_size)).astype(np.int64)

    predicts = paddle.to_tensor(predicts_data)
    labels = paddle.to_tensor(labels_data)

    output = loss_function(predicts, labels)
