code: def crf_decode_backward(
      backpointers: TensorLike, scores: TensorLike, state: TensorLike
  ) -> Tuple[tf.Tensor, tf.Tensor]:
      """Computes backward decoding in a linear-chain CRF.
  
      Args:
        backpointers: A [batch_size, num_tags] matrix of backpointer of next step
              (in time order).
        scores: A [batch_size, num_tags] matrix of scores of next step (in time order).
        state: A [batch_size, 1] matrix of tag index of next step.
  
      Returns:
        new_tags: A [batch_size, num_tags] tensor containing the new tag indices.
        new_scores: A [batch_size, num_tags] tensor containing the new score values.
      """
      backpointers = tf.transpose(backpointers, [1, 0, 2])
      scores = tf.transpose(scores, [1, 0, 2])
  
      def _scan_fn(
          _state: TensorLike, _inputs: TensorLike
      ) -> tf.Tensor:
          _state = tf.cast(tf.squeeze(_state, axis=[1]), dtype=tf.int32)
          idxs = tf.stack(
              [tf.range(tf.shape(_inputs)[0]), _state], axis=1
          )
          return tf.expand_dims(tf.gather_nd(_inputs, idxs), axis=-1)
  
      output_tags = tf.scan(_scan_fn, backpointers, state)
      # the dtype of the input parameters of tf.scan need to match
      # convert state to float32 to match the type of scores
      state = tf.cast(state, dtype=tf.float32)
      output_scores = tf.scan(_scan_fn, scores, state)
  
      return tf.transpose(output_tags, [1, 0, 2]), tf.transpose(
          output_scores, [1, 0, 2]
      )
  
imports: import tensorflow
  from tensorflow import TensorShape
  from tensorflow.types.experimental import TensorLike
  from typing import Tuple, Any, List, Union, Optional
label_desc: Use image node_id 2 for calling a global function with example usage: crf_decode_backward(backpointers, scores, state) and returns: tf,  tf, tf