class_docstr: A complete encoder-decoder model, with optional attention.
  
  A parent class which makes use of the contextual_embedding (such as a charlm)
  can make use of unsaved_modules when saving.
class_docstr_tok: ["A","complete","encoder-decoder","model",",","with","optional","attention",".","A","parent","class","which","makes","use","of","the","contextual_embedding","(","such","as","a","charlm",")","can","make","use","of","unsaved_modules","when","saving","."]
docstr: Predict with beam search. 
docstr_tok: ["Predict","with","beam","search","."]
code: def predict(self, src, src_mask, pos=None, beam_size=5, raw=None):
      """Predict with beam search."""
      if beam_size == 1:
          return self.predict_greedy(src, src_mask, pos, raw)
  
      enc_inputs, batch_size, src_lens, src_mask = self.embed(
          src, src_mask, pos, raw
      )
  
      # (1) encode source
      h_in, (hn, cn) = self.encode(enc_inputs, src_lens)
  
      if self.edit:
          edit_logits = self.edit_clf(hn)
      else:
          edit_logits = None
  
      # (2) set up beam
      with torch.no_grad():
          h_in = h_in.data.repeat(
              beam_size, 1, 1
          )  # repeat data for beam search
          src_mask = src_mask.repeat(beam_size, 1)
          # repeat decoder hidden states
          hn = hn.data.repeat(beam_size, 1)
          cn = cn.data.repeat(beam_size, 1)
      device = self.SOS_tensor.device
      beam = [Beam(beam_size, device) for _ in range(batch_size)]
  
      def update_state(states, idx, positions, beam_size):
          """Select the states according to back pointers."""
          for e in states:
              br, d = e.size()
              s = e.contiguous().view(beam_size, br // beam_size, d)[
                  :, idx
              ]
              s.data.copy_(s.data.index_select(0, positions))
  
      # (3) main loop
      for i in range(self.max_dec_len):
          dec_inputs = (
              torch.stack([b.get_current_state() for b in beam])
              .t()
              .contiguous()
              .view(-1, 1)
          )
          dec_inputs = self.embedding(dec_inputs)
          log_probs, (hn, cn) = self.decode(
              dec_inputs, hn, cn, h_in, src_mask, src=src
          )
          log_probs = (
              log_probs.view(beam_size, batch_size, -1)
              .transpose(0, 1)
              .contiguous()
          )  # [batch, beam, V]
  
          # advance each beam
          done = []
          for b in range(batch_size):
              is_done = beam[b].advance(log_probs.data[b])
              if is_done:
                  done += [b]
              # update beam state
              update_state(
                  (hn, cn), b, beam[b].get_current_origin(), beam_size
              )
  
          if len(done) == batch_size:
              break
  
      # back trace and find hypothesis
      all_hyp, all_scores = [], []
      for b in range(batch_size):
          scores, ks = beam[b].sort_best()
          all_scores += [scores[0]]
          k = ks[0]
          hyp = beam[b].get_hyp(k)
          hyp = utils.prune_hyp(hyp)
          hyp = [i.item() for i in hyp]
          all_hyp += [hyp]
  
      return all_hyp, edit_logits
  
imports: import logging
  import torch
  from torch import nn
  import torch.nn.functional
  import numpy
  import stanza.models.common.seq2seq_constant
  from stanza.models.common import utils
  from stanza.models.common.seq2seq_modules import LSTMAttention
  from stanza.models.common.beam import Beam
label_desc: Use image node_id 11 for calling the Seq2SeqModel obj's underlying member method code with example usage: obj.predict(src, src_mask, pos, beam_size, raw) and returns: all_hyp,  edit_logits, self