code: def _test_label_smoothing():
      smooth_loss = LabelSmoothingLoss(5, 0, 0.4)
      predict = torch.tensor(
          [
              [0, 0.2, 0.7, 0.1, 0],
              [0, 0.2, 0.7, 0.1, 0],
              [0, 0.2, 0.7, 0.1, 0],
          ],
          dtype=torch.float,
      )
      _ = smooth_loss(
          predict.log(), torch.tensor([2, 1, 0], dtype=torch.long)
      )
  
      # Show the target distributions expected by the system.
      plt.imshow(smooth_loss.true_dist)
      plt.show()
  
      smooth_loss = LabelSmoothingLoss(5, 0, 0.1)
  
      def loss_sample(x):
          d = x + 3 * 1
          predict2 = torch.tensor(
              [
                  [0, x / d, 1 / d, 1 / d, 1 / d],
              ],
              dtype=torch.float,
          )
          # print(predict)
          return smooth_loss(
              predict2.log(), torch.tensor([1], dtype=torch.long)
          ).item()
  
      plt.plot(
          np.arange(1, 100), [loss_sample(x) for x in range(1, 100)]
      )
      plt.show()
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/transformers/label_smoothing_loss.py
imports: import matplotlib.pyplot
  import numpy
  import torch
  import torch.nn
  from labml_helpers.module import Module
label_desc: Use image node_id 1 for calling a global function with example usage: _test_label_smoothing() and returns: smooth_loss