def applyLM(parentBeam, childBeam, classes, lm):
    """calculate LM score of child beam by taking score from parent beam and bigram probability of last two chars"""
    if lm and not childBeam.lmApplied:
        c1 = classes[parentBeam.labeling[-1] if parentBeam.labeling else
            classes.index(' ')]
        c2 = classes[childBeam.labeling[-1]]
        lmFactor = 0.01
        bigramProb = lm.getCharBigram(c1, c2) ** lmFactor
        childBeam.prText = parentBeam.prText * bigramProb
        childBeam.lmApplied = True
