def compute_pp(text, lm, order):
    # Working in log space
    pp = 0.0

    n = 0
    for utt in text:
        # Skip p(<s> | []) = -inf
        for k in range(1, len(utt)):
            c = utt[k]
            seq = utt[max(0, order+1-k):k]
            #print c, seq
            # Work w/ reversed context due to srilm
            seq = seq[::-1]
            pp = pp + -1 * lm.logprob_strings(c, seq)
            n += 1

    pp = pp / n

    # NOTE Assumes probs given back in log10
    pp = 10 ** pp

    return pp
dataset/ETHPy150Open amaas/stanford-ctc/ctc_fast/clm/clm_pp.py/compute_pp/swapped operands of `-`