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: from __future__ import print_function
  import torch
  import pickle
  import numpy
  import math
  import cv2
  from PIL import Image, JpegImagePlugin
  from scipy import ndimage
  import hashlib
  import sys, os
  from zipfile import ZipFile
  from .imgproc import loadImage
label_desc: Use image node_id 3 for calling a global function with example usage: applyLM(parentBeam, childBeam, classes, lm) without return types