code: 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(" ")
          ]  # first char
          c2 = classes[childBeam.labeling[-1]]  # second char
          lmFactor = 0.01  # influence of language model
          bigramProb = (
              lm.getCharBigram(c1, c2) ** lmFactor
          )  # probability of seeing first and second char next to each other
          childBeam.prText = (
              parentBeam.prText * bigramProb
          )  # probability of char sequence
          childBeam.lmApplied = True
  
imports: import torch
  import pickle
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: applyLM(parentBeam, childBeam, classes, lm) without return types