class_docstr: Implements MASTER as described in paper: <https://arxiv.org/pdf/1910.02562.pdf>`_.
  Implementation based on the official Pytorch implementation: <https://github.com/wenwenyu/MASTER-pytorch>`_.
  
  Args:
  ----
      feature_extractor: the backbone serving as feature extractor
      vocab: vocabulary, (without EOS, SOS, PAD)
      d_model: d parameter for the transformer decoder
      dff: depth of the pointwise feed-forward layer
      num_heads: number of heads for the mutli-head attention module
      num_layers: number of decoder layers to stack
      max_length: maximum length of character sequence handled by the model
      dropout: dropout probability of the decoder
      input_shape: size of the image inputs
      exportable: onnx exportable returns only logits
      cfg: dictionary containing information about the model
class_docstr_tok: ["Implements","MASTER","as","described","in","paper",":","<","https",":","\/\/arxiv.org\/pdf\/1910.02562.pdf",">","`","_",".","Implementation","based","on","the","official","Pytorch","implementation",":","<","https",":","\/\/github.com\/wenwenyu\/MASTER-pytorch",">","`","_",".","Args",":","--","--","feature_extractor",":","the","backbone","serving","as","feature","extractor","vocab",":","vocabulary",",","(","without","EOS",",","SOS",",","PAD",")","d_model",":","d","parameter","for","the","transformer","decoder","dff",":","depth","of","the","pointwise","feed-forward","layer","num_heads",":","number","of","heads","for","the","mutli-head","attention","module","num_layers",":","number","of","decoder","layers","to","stack","max_length",":","maximum","length","of","character","sequence","handled","by","the","model","dropout",":","dropout","probability","of","the","decoder","input_shape",":","size","of","the","image","inputs","exportable",":","onnx","exportable","returns","only","logits","cfg",":","dictionary","containing","information","about","the","model"]
docstr: Decode function for prediction
  
  Args:
  ----
      encoded: input tensor
  
  Returns:
  -------
      A Tuple of torch.Tensor: predictions, logits
docstr_tok: ["Decode","function","for","prediction","Args",":","--","--","encoded",":","input","tensor","Returns",":","--","--","--","-","A","Tuple","of","torch.Tensor",":","predictions",",","logits"]
code: def decode(self, encoded: torch.Tensor) -> torch.Tensor:
      """Decode function for prediction
  
      Args:
      ----
          encoded: input tensor
  
      Returns:
      -------
          A Tuple of torch.Tensor: predictions, logits
      """
      b = encoded.size(0)
  
      # Padding symbol + SOS at the beginning
      ys = torch.full(
          (b, self.max_length),
          self.vocab_size + 2,
          dtype=torch.long,
          device=encoded.device,
      )  # pad
      ys[:, 0] = self.vocab_size + 1  # sos
  
      # Final dimension include EOS/SOS/PAD
      for i in range(self.max_length - 1):
          source_mask, target_mask = self.make_source_and_target_mask(
              encoded, ys
          )
          output = self.decoder(ys, encoded, source_mask, target_mask)
          logits = self.linear(output)
          prob = torch.softmax(logits, dim=-1)
          next_token = torch.max(prob, dim=-1).indices
          # update ys with the next token and ignore the first token (SOS)
          ys[:, i + 1] = next_token[:, i]
  
      # Shape (N, max_length, vocab_size + 1)
      return logits
  
imports: from copy import deepcopy
  from typing import Any, Callable, Dict, List, Optional, Tuple
  import torch
  from torch import nn
  from torch.nn import functional
  from torchvision.models._utils import IntermediateLayerGetter
  from doctr.datasets import VOCABS
  from doctr.models.classification import magc_resnet31
  from doctr.models.modules.transformer import Decoder, PositionalEncoding
  from ...utils.pytorch import _bf16_to_float32, load_pretrained_params
  from .base import _MASTER, _MASTERPostProcessor
label_desc: Use image node_id 5 for calling the MASTER obj's underlying member method code with example usage: obj.decode(encoded) and returns: logits