code: def create_phone_lm(dir, tree_dir, run_opts, lm_opts=None):
      """Create a phone LM for chain training
  
      This method trains a phone LM for chain training using the alignments
      in "tree_dir"
      """
      try:
          f = open(tree_dir + "/num_jobs", "r")
          num_ali_jobs = int(f.readline())
          assert num_ali_jobs > 0
      except:
          raise Exception(
              """There was an error getting the number of alignment
                          jobs from {0}/num_jobs""".format(
                  tree_dir
              )
          )
  
      alignments = " ".join(
          [
              "{0}/ali.{1}.gz".format(tree_dir, job)
              for job in range(1, num_ali_jobs + 1)
          ]
      )
  
      common_lib.execute_command(
          """{command} {dir}/log/make_phone_lm.log \
              gunzip -c {alignments} \| \
              ali-to-phones {tree_dir}/final.mdl ark:- ark:- \| \
              chain-est-phone-lm {lm_opts} ark:- {dir}/phone_lm.fst""".format(
              command=run_opts.command,
              dir=dir,
              alignments=alignments,
              lm_opts=lm_opts if lm_opts is not None else "",
              tree_dir=tree_dir,
          )
      )
  
file_path: espnet/egs2/reazonspeech/asr1/steps/libs/nnet3/train/chain_objf/acoustic_model.py
imports: from __future__ import division
  from __future__ import print_function
  import logging
  import math
  import os
  import sys
  import libs.common
  import libs.nnet3.train.common
label_desc: Use image node_id 1 for calling a global function with example usage: create_phone_lm(dir, tree_dir, run_opts, lm_opts) without return types