class_docstr: Beam search 
class_docstr_tok: ["Beam","search"]
docstr: Update beam status and check if finished or not.
docstr_tok: ["Update","beam","status","and","check","if","finished","or","not","."]
code: def advance(self, word_prob):
      "Update beam status and check if finished or not."
      num_words = word_prob.shape[1]
  
      # Sum the previous scores.
      if len(self.prev_ks) > 0:
          beam_lk = word_prob + self.scores.unsqueeze(1).expand_as(
              word_prob
          )
      else:
          beam_lk = word_prob[0]
  
      flat_beam_lk = beam_lk.reshape([-1])
      best_scores, best_scores_id = flat_beam_lk.topk(
          self.size, 0, True, True
      )  # 1st sort
      self.all_scores.append(self.scores)
      self.scores = best_scores
      # bestScoresId is flattened as a (beam x word) array,
      # so we need to calculate which word and beam each score came from
      prev_k = best_scores_id // num_words
      self.prev_ks.append(prev_k)
      self.next_ys.append(best_scores_id - prev_k * num_words)
      # End condition is when top-of-beam is EOS.
      if self.next_ys[-1][0] == 3:
          self._done = True
          self.all_scores.append(self.scores)
  
      return self._done
  
imports: import math
  import paddle
  from paddle import nn
  import paddle.nn.functional
  from paddle.nn import LayerList
  from paddle.nn import Dropout, Linear, LayerNorm
  import numpy
  from ppocr.modeling.backbones.rec_svtrnet import Mlp, zeros_, ones_
  from paddle.nn.initializer import XavierNormal
label_desc: Use image node_id 5 for calling the Beam obj's underlying member method code with example usage: obj.advance(word_prob) and returns: self