code: def _decode_in_exp_space(
      score, transition_params, use_start_and_end_states
  ):
      """Perform Viterbi decoding in exp space."""
      if np.any(transition_params < 0):
          raise ValueError(
              "Transition params must be non-negative in exp space."
          )
      trellis = np.zeros_like(score)
      backpointers = np.zeros_like(score, dtype=np.int32)
      max_scores = np.zeros(score.shape[0])
  
      if use_start_and_end_states:
          start_potentials = transition_params[-1, :-1]
          end_potentials = transition_params[:-1, -1]
          transition_potentials = transition_params[:-1, :-1]
      else:
          transition_potentials = transition_params
  
      # Calculate the start value.
      if use_start_and_end_states:
          trellis[0] = score[0] * start_potentials
      else:
          trellis[0] = score[0]
  
      max_scores[0] = np.max(trellis[0])
      trellis[0] = trellis[0] / max_scores[0]
  
      # Calculate intermediate values.
      for t in range(1, score.shape[0]):
          v = np.expand_dims(trellis[t - 1], 1) * transition_potentials
          trellis[t] = score[t] * np.max(v, 0)
          backpointers[t] = np.argmax(v, 0)
          max_scores[t] = np.max(trellis[t])
          trellis[t] = trellis[t] / max_scores[t]
  
      # If we are using explicit start and end states, change the final scores
      # based on the final state's potentials.
      if use_start_and_end_states:
          final_scores = trellis[-1] * end_potentials
      else:
          final_scores = trellis[-1]
  
      viterbi = [np.argmax(final_scores)]
      for bp in reversed(backpointers[1:]):
          viterbi.append(bp[viterbi[-1]])
      viterbi.reverse()
  
      viterbi_score = np.max(final_scores) * np.prod(max_scores)
      return viterbi, viterbi_score
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
label_desc: Use image node_id 3 for calling a global function with example usage: _decode_in_exp_space(score, transition_params, use_start_and_end_states) and returns: viterbi,  viterbi_score