code: def load_ngram_mappings_for_dp(
      input_name: str,
  ) -> Tuple[defaultdict, defaultdict, defaultdict, int]:
      """Loads n-gram mapping vocabularies in form required by dynamic programming
      Args:
          input_name: file with n-gram mappings
      Returns:
          joint_vocab: dict where key=(original_ngram, misspelled_ngram), value=frequency
          orig_vocab: dict where key=original_ngram, value=frequency
          misspelled_vocab: dict where key=misspelled_ngram, value=frequency
          max_len: maximum n-gram length seen in vocabulary
  
      Input format: original \t misspelled \t joint_freq \t original_freq \t misspelled_freq
          u t o	u+i t o	49	8145	114
          u t o	<DELETE> t e	63	8145	16970
          u t o	o+_ t o	42	8145	1807
      """
      joint_vocab = defaultdict(int)
      orig_vocab = defaultdict(int)
      misspelled_vocab = defaultdict(int)
      max_len = 0
      with open(input_name, "r", encoding="utf-8") as f:
          for line in f:
              orig, misspelled, joint_freq, _, _ = line.strip().split(
                  "\t"
              )
              if orig == "" or misspelled == "":
                  raise ValueError(
                      "Emty n-gram: orig="
                      + orig
                      + "; misspelled="
                      + misspelled
                  )
              misspelled = misspelled.replace("<DELETE>", " ").replace(
                  "+", " "
              )
              misspelled = " ".join(misspelled.split())
              if (
                  misspelled == ""
              ):  # skip if resulting ngram doesn't contain any real character
                  continue
              max_len = max(
                  max_len,
                  orig.count(" ") + 1,
                  misspelled.count(" ") + 1,
              )
              joint_vocab[(orig, misspelled)] += int(joint_freq)
              orig_vocab[orig] += int(joint_freq)
              misspelled_vocab[misspelled] += int(joint_freq)
      return joint_vocab, orig_vocab, misspelled_vocab, max_len
  
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 3 for calling a global function with example usage: load_ngram_mappings_for_dp(input_name) and returns: joint_vocab,  orig_vocab,  misspelled_vocab,  max_len