def compute_q(dict_q, tag, prev_tag, prev_prev_tag, lr1=0.90, lr2=0.09, lr3=0.01): if lr1 + lr2 + lr3 != 1.0: raise Exception('summing factors should be 1 !!!') prob1 = MathUtils.calc_fraction(DictUtils.get_value(dict_q, (tag, prev_tag, prev_prev_tag)), DictUtils.get_value(dict_q, (prev_tag, prev_prev_tag))) prob2 = MathUtils.calc_fraction(DictUtils.get_value(dict_q, (tag, prev_tag)), DictUtils.get_value(dict_q, prev_tag)) prob3 = MathUtils.calc_fraction(DictUtils.get_value(dict_q, tag), DictUtils.get_value(dict_q, 'ALL')) return lr1 * prob1 + lr2 * prob2 + lr3 * prob3
def compute_e(word, tag, dict_q, dict_e): counter = DictUtils.get_value(dict_e, (word, tag)) denominator = DictUtils.get_value(dict_q, tag) return MathUtils.calc_fraction(counter, denominator)