code: def test_label_smoothing(label_shape, alpha, from_logits, hybridize):
      def _np_label_smoothing(pred, labels, alpha, from_logits):
          flatten_pred = pred.reshape((-1, pred.shape[-1]))
          flatten_labels = labels.reshape((-1,))
          smoothed_labels = np.full_like(
              flatten_pred, fill_value=alpha / flatten_pred.shape[-1]
          )
          smoothed_labels[
              np.arange(flatten_pred.shape[0]), flatten_labels
          ] = (1 - alpha + alpha / flatten_pred.shape[-1])
          if not from_logits:
              flatten_logits = np.log(
                  sspecial.softmax(flatten_pred, axis=-1)
              )
          else:
              flatten_logits = flatten_pred
          # Calculate cross-entropy
          loss = -(smoothed_labels * flatten_logits).sum(axis=-1)
          return loss.reshape(labels.shape)
  
      label_num = 5
      loss = LabelSmoothCrossEntropyLoss(
          num_labels=label_num, alpha=alpha, from_logits=from_logits
      )
      if hybridize:
          loss.hybridize()
      if from_logits:
          pred = mx.np.random.uniform(
              -10, -1, label_shape + (label_num,)
          )
      else:
          pred = mx.np.random.normal(0, 1, label_shape + (label_num,))
      labels = mx.np.random.randint(0, label_num, label_shape)
      out = loss(pred, labels)
      np_out = _np_label_smoothing(
          pred.asnumpy(), labels.asnumpy(), alpha, from_logits
      )
      assert_allclose(np_out, out.asnumpy(), 1e-4, 1e-4)
  
imports: import mxnet
  import numpy
  import pytest
  from numpy.testing import assert_allclose
  import scipy.special
  from gluonnlp.loss import LabelSmoothCrossEntropyLoss
label_desc: Use image node_id 1 for calling a global function with example usage: test_label_smoothing(label_shape, alpha, from_logits, hybridize) and returns: loss