code: def test_sequence_loss(
      average_across_timesteps, average_across_batch, zero_weights
  ):
      (
          batch_size,
          sequence_length,
          _,
          logits,
          targets,
          weights,
          expected_loss,
      ) = get_test_data()
  
      if zero_weights:
          weights = [
              tf.constant(0.0, shape=[batch_size])
              for _ in range(sequence_length)
          ]
          weights = tf.stack(weights, axis=1)
  
      computed = loss.sequence_loss(
          logits,
          targets,
          weights,
          average_across_timesteps=average_across_timesteps,
          average_across_batch=average_across_batch,
      )
      computed = computed.numpy()
      if (
          average_across_timesteps
          and average_across_batch
          and zero_weights
      ):
          expected = 0.0
      elif (
          not average_across_timesteps
          and average_across_batch
          and zero_weights
      ):
          expected = np.zeros(sequence_length)
      elif (
          average_across_timesteps
          and not average_across_batch
          and zero_weights
      ):
          expected = np.zeros(batch_size)
      elif (
          not average_across_timesteps
          and not average_across_batch
          and zero_weights
      ):
          expected = np.zeros((batch_size, sequence_length))
      elif (
          average_across_timesteps
          and average_across_batch
          and not zero_weights
      ):
          expected = expected_loss
      elif (
          not average_across_timesteps
          and average_across_batch
          and not zero_weights
      ):
          expected = np.full(sequence_length, expected_loss)
      elif (
          average_across_timesteps
          and not average_across_batch
          and not zero_weights
      ):
          expected = np.full(batch_size, expected_loss)
      else:
          expected = np.full(
              (batch_size, sequence_length), expected_loss
          )
  
      np.testing.assert_allclose(
          computed, expected, rtol=1e-6, atol=1e-6
      )
  
file_path: addons/tensorflow_addons/seq2seq/tests/loss_test.py
imports: import pytest
  import numpy
  import tensorflow
  from tensorflow_addons.seq2seq import loss
label_desc: Use image node_id 2 for calling a global function with example usage: test_sequence_loss(average_across_timesteps, average_across_batch, zero_weights) without return types