code: def crf_sequence_score(
      inputs: TensorLike,
      tag_indices: TensorLike,
      sequence_lengths: TensorLike,
      transition_params: TensorLike,
  ) -> tf.Tensor:
      """Computes the unnormalized score for a tag sequence.
  
      Args:
        inputs: A [batch_size, max_seq_len, num_tags] tensor of unary potentials
            to use as input to the CRF layer.
        tag_indices: A [batch_size, max_seq_len] matrix of tag indices for which
            we compute the unnormalized score.
        sequence_lengths: A [batch_size] vector of true sequence lengths.
        transition_params: A [num_tags, num_tags] transition matrix.
      Returns:
        sequence_scores: A [batch_size] vector of unnormalized sequence scores.
      """
      tag_indices = tf.cast(tag_indices, dtype=tf.int32)
      sequence_lengths = tf.cast(sequence_lengths, dtype=tf.int32)
  
      # If max_seq_len is 1, we skip the score calculation and simply gather the
      # unary potentials of the single tag.
      def _single_seq_fn():
          batch_size = tf.shape(inputs, out_type=tf.int32)[0]
          batch_inds = tf.reshape(tf.range(batch_size), [-1, 1])
          indices = tf.concat(
              [batch_inds, tf.zeros_like(batch_inds)], axis=1
          )
  
          tag_inds = tf.gather_nd(tag_indices, indices)
          tag_inds = tf.reshape(tag_inds, [-1, 1])
          indices = tf.concat([indices, tag_inds], axis=1)
  
          sequence_scores = tf.gather_nd(inputs, indices)
  
          sequence_scores = tf.where(
              tf.less_equal(sequence_lengths, 0),
              tf.zeros_like(sequence_scores),
              sequence_scores,
          )
          return sequence_scores
  
      def _multi_seq_fn():
          # Compute the scores of the given tag sequence.
          unary_scores = crf_unary_score(
              tag_indices, sequence_lengths, inputs
          )
          binary_scores = crf_binary_score(
              tag_indices, sequence_lengths, transition_params
          )
          sequence_scores = unary_scores + binary_scores
          return sequence_scores
  
      return tf.cond(
          tf.equal(tf.shape(inputs)[1], 1),
          _single_seq_fn,
          _multi_seq_fn,
      )
  
imports: import warnings
  import numpy
  import tensorflow
  from tensorflow_addons.rnn.abstract_rnn_cell import AbstractRNNCell
  from tensorflow_addons.utils.types import TensorLike
  from typeguard import typechecked
  from typing import Optional, Tuple
label_desc: Use image node_id 2 for calling a global function with example usage: crf_sequence_score(inputs, tag_indices, sequence_lengths, transition_params) and returns: tf, sequence_scores, sequence_scores