code: def crf_unary_score(
      tag_indices: TensorLike,
      sequence_lengths: TensorLike,
      inputs: TensorLike,
  ) -> tf.Tensor:
      """Computes the unary scores of tag sequences.
  
      Args:
        tag_indices: A [batch_size, max_seq_len] matrix of tag indices.
        sequence_lengths: A [batch_size] vector of true sequence lengths.
        inputs: A [batch_size, max_seq_len, num_tags] tensor of unary potentials.
      Returns:
        unary_scores: A [batch_size] vector of unary scores.
      """
      tag_indices = tf.cast(tag_indices, dtype=tf.int32)
      sequence_lengths = tf.cast(sequence_lengths, dtype=tf.int32)
  
      batch_size = tf.shape(inputs)[0]
      max_seq_len = tf.shape(inputs)[1]
      num_tags = tf.shape(inputs)[2]
  
      flattened_inputs = tf.reshape(inputs, [-1])
  
      offsets = tf.expand_dims(
          tf.range(batch_size) * max_seq_len * num_tags, 1
      )
      offsets += tf.expand_dims(tf.range(max_seq_len) * num_tags, 0)
      # Use int32 or int64 based on tag_indices' dtype.
      if tag_indices.dtype == tf.int64:
          offsets = tf.cast(offsets, tf.int64)
      flattened_tag_indices = tf.reshape(offsets + tag_indices, [-1])
  
      unary_scores = tf.reshape(
          tf.gather(flattened_inputs, flattened_tag_indices),
          [batch_size, max_seq_len],
      )
  
      masks = tf.sequence_mask(
          sequence_lengths,
          maxlen=tf.shape(tag_indices)[1],
          dtype=unary_scores.dtype,
      )
  
      unary_scores = tf.reduce_sum(unary_scores * masks, 1)
      return unary_scores
  
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 6 for calling a global function with example usage: crf_unary_score(tag_indices, sequence_lengths, inputs) and returns: unary_scores