class_docstr: A convenience class for calculating the Levenshtein edit distance.
  
  Class will cache some intermediate values to hasten the calculation. The implementation follows the implementation
  from https://github.com/mjpost/sacrebleu/blob/master/sacrebleu/metrics/lib_ter.py,
  where the most of this implementation is adapted and copied from.
  
  Args:
      reference_tokens: list of reference tokens
      op_insert: cost of insertion operation
      op_delete: cost of deletion operation
      op_substitute: cost of substitution operation
class_docstr_tok: ["A","convenience","class","for","calculating","the","Levenshtein","edit","distance",".","Class","will","cache","some","intermediate","values","to","hasten","the","calculation",".","The","implementation","follows","the","implementation","from","https",":","\/\/github.com\/mjpost\/sacrebleu\/blob\/master\/sacrebleu\/metrics\/lib_ter.py",",","where","the","most","of","this","implementation","is","adapted","and","copied","from",".","Args",":","reference_tokens",":","list","of","reference","tokens","op_insert",":","cost","of","insertion","operation","op_delete",":","cost","of","deletion","operation","op_substitute",":","cost","of","substitution","operation"]
docstr: Get a trace of executed operations from the edit distance matrix.
  
  Args:
      prediction_len: A length of a tokenized predicted sentence.
      edit_distance:
          A matrix of the Levenshtedin edit distance. The element part of the matrix is a tuple of an edit
          operation cost and an edit operation itself.
  
  Return:
      A trace of executed operations returned as a tuple of `_EDIT_OPERATIONS` enumerates.
  
  Raises:
      ValueError:
          If an unknown operation has been applied.
docstr_tok: ["Get","a","trace","of","executed","operations","from","the","edit","distance","matrix",".","Args",":","prediction_len",":","A","length","of","a","tokenized","predicted","sentence",".","edit_distance",":","A","matrix","of","the","Levenshtedin","edit","distance",".","The","element","part","of","the","matrix","is","a","tuple","of","an","edit","operation","cost","and","an","edit","operation","itself",".","Return",":","A","trace","of","executed","operations","returned","as","a","tuple","of","`","_EDIT_OPERATIONS","`","enumerates",".","Raises",":","ValueError",":","If","an","unknown","operation","has","been","applied","."]
code: def _get_trace(
      self,
      prediction_len: int,
      edit_distance: List[List[Tuple[int, _EditOperations]]],
  ) -> Tuple[_EditOperations, ...]:
      """Get a trace of executed operations from the edit distance matrix.
  
      Args:
          prediction_len: A length of a tokenized predicted sentence.
          edit_distance:
              A matrix of the Levenshtedin edit distance. The element part of the matrix is a tuple of an edit
              operation cost and an edit operation itself.
  
      Return:
          A trace of executed operations returned as a tuple of `_EDIT_OPERATIONS` enumerates.
  
      Raises:
          ValueError:
              If an unknown operation has been applied.
  
      """
      trace: Tuple[_EditOperations, ...] = ()
      i = prediction_len
      j = self.reference_len
  
      while i > 0 or j > 0:
          operation = edit_distance[i][j][1]
          trace = (operation, *trace)
          if operation in (
              _EditOperations.OP_SUBSTITUTE,
              _EditOperations.OP_NOTHING,
          ):
              i -= 1
              j -= 1
          elif operation == _EditOperations.OP_INSERT:
              j -= 1
          elif operation == _EditOperations.OP_DELETE:
              i -= 1
          else:
              raise ValueError(f"Unknown operation {operation!r}")
  
      return trace
  
file_path: torchmetrics/src/torchmetrics/functional/text/helper.py
imports: import math
  from enum import Enum, unique
  from typing import Dict, List, Sequence, Tuple, Union
label_desc: Use image node_id 4 for calling the _LevenshteinEditDistance obj's underlying member method code with example usage: obj._get_trace(prediction_len, edit_distance) and returns: trace