code: def test_loss_is_computed_correctly(self):
      batch_size = 5
      num_decoding_steps = 5
      num_classes = 10
      sample_logits = torch.randn(
          batch_size, num_decoding_steps - 1, num_classes
      )
      sample_targets = torch.from_numpy(
          numpy.random.randint(
              0, num_classes, (batch_size, num_decoding_steps)
          )
      )
      # Mask should be either 0 or 1
      sample_mask = torch.from_numpy(
          numpy.random.randint(0, 2, (batch_size, num_decoding_steps))
      )
      expected_loss = sequence_cross_entropy_with_logits(
          sample_logits,
          sample_targets[:, 1:].contiguous(),
          sample_mask[:, 1:].contiguous(),
      )
      # pylint: disable=protected-access
      actual_loss = self.model._get_loss(
          sample_logits, sample_targets, sample_mask
      )
      assert numpy.equal(
          expected_loss.data.numpy(), actual_loss.data.numpy()
      )
  
file_path: magnitude/pymagnitude/third_party/allennlp/tests/models/encoder_decoders/simple_seq2seq_test.py
imports: from __future__ import division
  from __future__ import absolute_import
  import numpy
  import torch
  from allennlp.common.testing import ModelTestCase
  from allennlp.nn.util import sequence_cross_entropy_with_logits
label_desc: Use image node_id 3 for calling the SimpleSeq2SeqWithoutAttentionTest obj's underlying member method code with example usage: obj.test_loss_is_computed_correctly() without return types