code: def create_H(
      kaldi_root: Path,
      fst_dir: Path,
      disambig_out_units_file: Path,
      in_labels: str,
      vocab: Dictionary,
      blk_sym: str,
      silence_symbol: Optional[str],
  ) -> (Path, Path, Path):
      h_graph = (
          fst_dir
          / f"H.{in_labels}{'_' + silence_symbol if silence_symbol else ''}.fst"
      )
      h_out_units_file = fst_dir / f"kaldi_dict.h_out.{in_labels}.txt"
      disambig_in_units_file_int = Path(
          str(h_graph) + "isym_disambig.int"
      )
      disambig_out_units_file_int = Path(
          str(disambig_out_units_file) + ".int"
      )
      if (
          not h_graph.exists()
          or not h_out_units_file.exists()
          or not disambig_in_units_file_int.exists()
      ):
          logger.info(f"Creating {h_graph}")
          eps_sym = "<eps>"
  
          num_disambig = 0
          osymbols = []
  
          with open(disambig_out_units_file, "r") as f, open(
              disambig_out_units_file_int, "w"
          ) as out_f:
              for line in f:
                  symb, id = line.rstrip().split()
                  if line.startswith("#"):
                      num_disambig += 1
                      print(id, file=out_f)
                  else:
                      if len(osymbols) == 0:
                          assert symb == eps_sym, symb
                      osymbols.append((symb, id))
  
          i_idx = 0
          isymbols = [(eps_sym, 0)]
  
          imap = {}
  
          for i, s in enumerate(vocab.symbols):
              i_idx += 1
              isymbols.append((s, i_idx))
              imap[s] = i_idx
  
          fst_str = []
  
          node_idx = 0
          root_node = node_idx
  
          special_symbols = [blk_sym]
          if silence_symbol is not None:
              special_symbols.append(silence_symbol)
  
          for ss in special_symbols:
              fst_str.append(
                  "{} {} {} {}".format(
                      root_node, root_node, ss, eps_sym
                  )
              )
  
          for symbol, _ in osymbols:
              if symbol == eps_sym or symbol.startswith("#"):
                  continue
  
              node_idx += 1
              # 1. from root to emitting state
              fst_str.append(
                  "{} {} {} {}".format(
                      root_node, node_idx, symbol, symbol
                  )
              )
              # 2. from emitting state back to root
              fst_str.append(
                  "{} {} {} {}".format(
                      node_idx, root_node, eps_sym, eps_sym
                  )
              )
              # 3. from emitting state to optional blank state
              pre_node = node_idx
              node_idx += 1
              for ss in special_symbols:
                  fst_str.append(
                      "{} {} {} {}".format(
                          pre_node, node_idx, ss, eps_sym
                      )
                  )
              # 4. from blank state back to root
              fst_str.append(
                  "{} {} {} {}".format(
                      node_idx, root_node, eps_sym, eps_sym
                  )
              )
  
          fst_str.append("{}".format(root_node))
  
          fst_str = "\n".join(fst_str)
          h_str = str(h_graph)
          isym_file = h_str + ".isym"
  
          with open(isym_file, "w") as f:
              for sym, id in isymbols:
                  f.write("{} {}\n".format(sym, id))
  
          with open(h_out_units_file, "w") as f:
              for sym, id in osymbols:
                  f.write("{} {}\n".format(sym, id))
  
          with open(disambig_in_units_file_int, "w") as f:
              disam_sym_id = len(isymbols)
              for _ in range(num_disambig):
                  f.write("{}\n".format(disam_sym_id))
                  disam_sym_id += 1
  
          fstcompile = kaldi_root / "tools/openfst-1.6.7/bin/fstcompile"
          fstaddselfloops = kaldi_root / "src/fstbin/fstaddselfloops"
          fstarcsort = kaldi_root / "tools/openfst-1.6.7/bin/fstarcsort"
  
          try:
              with open(h_graph, "wb") as out_f:
                  res = subprocess.run(
                      [
                          fstcompile,
                          f"--isymbols={isym_file}",
                          f"--osymbols={h_out_units_file}",
                          "--keep_isymbols=false",
                          "--keep_osymbols=false",
                      ],
                      input=str.encode(fst_str),
                      capture_output=True,
                      check=True,
                  )
                  res = subprocess.run(
                      [
                          fstaddselfloops,
                          disambig_in_units_file_int,
                          disambig_out_units_file_int,
                      ],
                      input=res.stdout,
                      capture_output=True,
                      check=True,
                  )
                  res = subprocess.run(
                      [fstarcsort, "--sort_type=olabel"],
                      input=res.stdout,
                      capture_output=True,
                      check=True,
                  )
                  out_f.write(res.stdout)
          except subprocess.CalledProcessError as e:
              logger.error(
                  f"cmd: {e.cmd}, err: {e.stderr.decode('utf-8')}"
              )
              os.remove(h_graph)
              raise
      return h_graph, h_out_units_file, disambig_in_units_file_int
  
imports: from dataclasses import dataclass
  import hydra
  from hydra.core.config_store import ConfigStore
  import logging
  from omegaconf import MISSING, OmegaConf
  import os
  import os.path
  from pathlib import Path
  import subprocess
  from typing import Optional
  from fairseq.data.dictionary import Dictionary
  from fairseq.dataclass import FairseqDataclass
label_desc: Use image node_id 6 for calling a global function with example usage: create_H(kaldi_root, fst_dir, disambig_out_units_file, in_labels, vocab, blk_sym, silence_symbol) and returns: h_graph,  h_out_units_file,  disambig_in_units_file_int