code: def test_sequence_cross_entropy_with_logits_smooths_labels_correctly(
      self,
  ):
      tensor = torch.rand([1, 3, 4])
      targets = torch.LongTensor(numpy.random.randint(0, 3, [1, 3]))
  
      weights = torch.ones([2, 3])
      loss = util.sequence_cross_entropy_with_logits(
          tensor, targets, weights, label_smoothing=0.1
      )
  
      correct_loss = 0.0
      for prediction, label in izip(
          tensor.squeeze(0), targets.squeeze(0)
      ):
          prediction = torch.nn.functional.log_softmax(
              prediction, dim=-1
          )
          correct_loss += prediction[label] * 0.9
          # incorrect elements
          correct_loss += prediction.sum() * 0.1 / 4
      # Average over sequence.
      correct_loss = -correct_loss / 3
      numpy.testing.assert_array_almost_equal(
          loss.data.numpy(), correct_loss.data.numpy()
      )
  
imports: from __future__ import with_statement
  from __future__ import division
  from __future__ import absolute_import
  import numpy
  from numpy.testing import assert_array_almost_equal, assert_almost_equal
  import torch
  import pytest
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.nn import util
label_desc: Use image node_id 23 for calling the TestNnUtil obj's underlying member method code with example usage: obj.test_sequence_cross_entropy_with_logits_smooths_labels_correctly() without return types