code: def compute_wer(ref_uid_to_tra, hyp_uid_to_tra, g2p, g2p_dict):
      d_cnt = 0
      w_cnt = 0
      w_cnt_h = 0
      for uid in hyp_uid_to_tra:
          ref = ref_uid_to_tra[uid].split()
          if g2p_dict is not None:
              hyp = []
              for word in hyp_uid_to_tra[uid].split():
                  if word in g2p_dict:
                      hyp = hyp + g2p_dict[word]
                  else:
                      logger.warning(f"{word} not in g2p_dict")
          elif g2p is not None:
              hyp = g2p(hyp_uid_to_tra[uid])
              hyp = [p for p in hyp if p != "'" and p != " "]
              hyp = [p[:-1] if p[-1].isnumeric() else p for p in hyp]
          else:
              hyp = hyp_uid_to_tra[uid].split()
          logger.debug(
              (
                  f"======================\n"
                  f"HYP: {' '.join(hyp)}\n"
                  f"REF: {' '.join(ref)}"
              )
          )
          d_cnt += editdistance.eval(ref, hyp)
          w_cnt += len(ref)
          w_cnt_h += len(hyp)
      wer = float(d_cnt) / w_cnt
      logger.debug(
          (
              f"wer = {wer*100:.2f}%; num. of ref words = {w_cnt}; "
              f"num. of hyp words = {w_cnt_h}; num. of sentences = {len(ref_uid_to_tra)}"
          )
      )
      return wer
  
file_path: fairseq/examples/wav2vec/unsupervised/kaldi_self_train/st/local/unsup_select.py
imports: import argparse
  import logging
  import math
  import sys
  import kenlm
  import editdistance
  from g2p_en import G2p
label_desc: Use image node_id 4 for calling a global function with example usage: compute_wer(ref_uid_to_tra, hyp_uid_to_tra, g2p, g2p_dict) and returns: wer