code: def test_crf_log_norm(dtype):
      transition_params = np.array(
          [[-3, 5, -2], [3, 4, 1], [1, 2, 1]], dtype=dtype
      )
      # Test both the length-1 and regular cases.
      sequence_lengths_list = [
          np.array(3, dtype=np.int32),
          np.array(1, dtype=np.int64),
      ]
      inputs_list = [
          np.array(
              [[4, 5, -3], [3, -1, 3], [-1, 2, 1], [0, 0, 0]],
              dtype=dtype,
          ),
          np.array([[3, -1, 3]], dtype=dtype),
      ]
      tag_indices_list = [
          np.array([1, 2, 1, 0], dtype=np.int32),
          np.array([2], dtype=np.int32),
      ]
  
      for sequence_lengths, inputs, tag_indices in zip(
          sequence_lengths_list, inputs_list, tag_indices_list
      ):
          num_words = inputs.shape[0]
          num_tags = inputs.shape[1]
          all_sequence_scores = []
  
          # Compare the dynamic program with brute force computation.
          for tag_indices in itertools.product(
              range(num_tags), repeat=sequence_lengths
          ):
              tag_indices = list(tag_indices)
              tag_indices.extend([0] * (num_words - sequence_lengths))
              all_sequence_scores.append(
                  text.crf_sequence_score(
                      inputs=tf.expand_dims(inputs, 0),
                      tag_indices=tf.expand_dims(tag_indices, 0),
                      sequence_lengths=tf.expand_dims(
                          sequence_lengths, 0
                      ),
                      transition_params=tf.constant(transition_params),
                  )
              )
  
          brute_force_log_norm = tf.reduce_logsumexp(
              all_sequence_scores
          )
          log_norm = text.crf_log_norm(
              inputs=tf.expand_dims(inputs, 0),
              sequence_lengths=tf.expand_dims(sequence_lengths, 0),
              transition_params=tf.constant(transition_params),
          )
          log_norm = tf.squeeze(log_norm, [0])
  
          test_utils.assert_allclose_according_to_type(
              log_norm, brute_force_log_norm
          )
  
imports: import itertools
  from packaging.version import Version
  import pytest
  import numpy
  import tensorflow
  from tensorflow_addons import text
  from tensorflow_addons.utils import test_utils
  from numpy.testing import assert_array_equal
label_desc: Use image node_id 8 for calling a global function with example usage: test_crf_log_norm(dtype) without return types