code: def _decode_in_log_space(
      score, transition_params, use_start_and_end_states
  ):
      """Perform Viterbi decoding in log space."""
      trellis = np.zeros_like(score)
      backpointers = np.zeros_like(score, dtype=np.int32)
  
      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]
  
      # 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)
  
      # 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)
  
      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 2 for calling a global function with example usage: _decode_in_log_space(score, transition_params, use_start_and_end_states) and returns: viterbi,  viterbi_score