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(
                  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 = 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])
  
          np.testing.assert_allclose(log_norm, brute_force_log_norm)
  
file_path: rasa/tests/utils/tensorflow/test_crf.py
imports: import itertools
  import pytest
  import numpy
  import tensorflow
  from rasa.utils.tensorflow.crf import crf_sequence_score, crf_unary_score, crf_binary_score, crf_log_norm, crf_log_likelihood
label_desc: Use image node_id 6 for calling a global function with example usage: test_crf_log_norm(dtype) without return types