docstr: Find alternatives to the decoded sentence in the logits.
  E.g. if a 'c' is decoded in the range 2 to 4, this algorithm will add all characters in the interval [2, 4] to
  the output if the confidence of the character is higher than the threshold, respectively.
  
  
  Parameters
  ----------
  probabilities : array_like
      Prediction of the neural net to decode or shape (length x character probability).
      The blank index must be 0.
  sentence : list of tuple (character index, start pos, end pos)
      The decoded sentence (depends on the CTCDecoder).
      The position refer to the character position in the logits.
  threshold : float
      Minimum confidence for alternative characters to be listed.
  Returns
  -------
      a Prediction object
docstr_tok: ["Find","alternatives","to","the","decoded","sentence","in","the","logits",".","E.g",".","if","a","'","c","'","is","decoded","in","the","range","2","to","4",",","this","algorithm","will","add","all","characters","in","the","interval","[","2",",","4","]","to","the","output","if","the","confidence","of","the","character","is","higher","than","the","threshold",",","respectively",".","Parameters","--","--","--","--","--","probabilities",":","array_like","Prediction","of","the","neural","net","to","decode","or","shape","(","length","x","character","probability",")",".","The","blank","index","must","be","0.","sentence",":","list","of","tuple","(","character","index",",","start","pos",",","end","pos",")","The","decoded","sentence","(","depends","on","the","CTCDecoder",")",".","The","position","refer","to","the","character","position","in","the","logits",".","threshold",":","float","Minimum","confidence","for","alternative","characters","to","be","listed",".","Returns","--","--","--","-","a","Prediction","object"]
code: def find_alternatives(
      self, probabilities, sentence, threshold
  ) -> Prediction:
      """
      Find alternatives to the decoded sentence in the logits.
      E.g. if a 'c' is decoded in the range 2 to 4, this algorithm will add all characters in the interval [2, 4] to
      the output if the confidence of the character is higher than the threshold, respectively.
  
  
      Parameters
      ----------
      probabilities : array_like
          Prediction of the neural net to decode or shape (length x character probability).
          The blank index must be 0.
      sentence : list of tuple (character index, start pos, end pos)
          The decoded sentence (depends on the CTCDecoder).
          The position refer to the character position in the logits.
      threshold : float
          Minimum confidence for alternative characters to be listed.
      Returns
      -------
          a Prediction object
  
      """
      # find alternatives
      pred = Prediction()
      pred.labels[:] = [c for c, _, _ in sentence]
      pred.is_voted_result = False
      pred.logits = probabilities
      pred.avg_char_probability = 0
      for c, start, end in sentence:
          p = probabilities[start:end]
          p = np.max(p, axis=0)
  
          pos = PredictionPosition(local_start=start, local_end=end - 1)
          pred.positions.append(pos)
  
          for label in reversed(
              sorted(range(len(p)), key=lambda v: p[v])
          ):
              if p[label] < threshold and len(pos.chars) > 0:
                  break
              else:
                  pos.chars.append(
                      PredictionCharacter(
                          label=label,
                          probability=p[label],
                      )
                  )
  
          if len(pos.chars) > 0:
              pred.avg_char_probability += pos.chars[0].probability
  
      pred.avg_char_probability /= (
          len(pred.positions) if len(pred.positions) > 0 else 1
      )
      return pred
  
file_path: calamari/calamari_ocr/ocr/model/ctcdecoder/ctc_decoder.py
imports: from abc import ABC, abstractmethod
  from dataclasses import field, dataclass
  from typing import List
  import numpy
  from paiargparse import pai_dataclass
  from tfaip.util.enum import StrEnum
  from calamari_ocr.ocr.predict.params import Prediction, PredictionPosition, PredictionCharacter
label_desc: Use image node_id 4 for calling the CTCDecoder obj's underlying member method code with example usage: obj.find_alternatives(probabilities, sentence, threshold) and returns: pred