code: def read_spellmapper_predictions(
      filename: str,
  ) -> List[Tuple[str, List[Tuple[int, int, str, float]], List[int]]]:
      """Read results of SpellMapper inference from file.
      Args:
          filename: file with SpellMapper results
      Returns:
          list of tuples (sent, list of fragment predictions, list of letter predictions)
      One fragment prediction is a tuple (begin, end, replacement_text, prob)
      """
      results = []
      with open(filename, "r", encoding="utf-8") as f:
          for line in f:
              (
                  text,
                  candidate_str,
                  fragment_predictions_str,
                  letter_predictions_str,
              ) = line.strip().split("\t")
              text = text.replace(" ", "").replace("_", " ")
              candidate_str = candidate_str.replace(" ", "").replace(
                  "_", " "
              )
              candidates = candidate_str.split(";")
              letter_predictions = list(
                  map(int, letter_predictions_str.split())
              )
              if len(candidates) != 10:
                  raise IndexError(
                      "expect 10 candidates, got: ", len(candidates)
                  )
              if len(text) != len(letter_predictions):
                  raise IndexError(
                      "len(text)=",
                      len(text),
                      "; len(letter_predictions)=",
                      len(letter_predictions),
                  )
              replacements = []
              if fragment_predictions_str != "":
                  for prediction in fragment_predictions_str.split(";"):
                      begin, end, candidate_id, prob = prediction.split(
                          " "
                      )
                      begin = int(begin)
                      end = int(end)
                      candidate_id = int(candidate_id)
                      prob = float(prob)
                      replacements.append(
                          (
                              begin,
                              end,
                              candidates[candidate_id - 1],
                              prob,
                          )
                      )
                      replacements.sort()  # it will sort by begin, then by end
              results.append((text, replacements, letter_predictions))
      return results
  
imports: import json
  import math
  import random
  import re
  from collections import defaultdict, namedtuple
  from typing import Dict, List, Set, Tuple, Union
  import numpy
  from numba import jit
label_desc: Use image node_id 10 for calling a global function with example usage: read_spellmapper_predictions(filename) and returns: results