def METHOD_NAME(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