class_docstr: Implements a PARSeq architecture as described in `"Scene Text Recognition
  with Permuted Autoregressive Sequence Models" <https://arxiv.org/pdf/2207.06966>`_.
  Modified implementation based on the official Pytorch implementation: <https://github.com/baudm/parseq/tree/main`_.
  
  Args:
  ----
      feature_extractor: the backbone serving as feature extractor
      vocab: vocabulary used for encoding
      embedding_units: number of embedding units
      max_length: maximum word length handled by the model
      dropout_prob: dropout probability for the decoder
      dec_num_heads: number of attention heads in the decoder
      dec_ff_dim: dimension of the feed forward layer in the decoder
      dec_ffd_ratio: depth multiplier for the feed forward layer in the decoder
      input_shape: input shape of the image
      exportable: onnx exportable returns only logits
      cfg: dictionary containing information about the model
class_docstr_tok: ["Implements","a","PARSeq","architecture","as","described","in","`","``","Scene","Text","Recognition","with","Permuted","Autoregressive","Sequence","Models","''","<","https",":","\/\/arxiv.org\/pdf\/2207.06966",">","`","_",".","Modified","implementation","based","on","the","official","Pytorch","implementation",":","<","https",":","\/\/github.com\/baudm\/parseq\/tree\/main","`","_",".","Args",":","--","--","feature_extractor",":","the","backbone","serving","as","feature","extractor","vocab",":","vocabulary","used","for","encoding","embedding_units",":","number","of","embedding","units","max_length",":","maximum","word","length","handled","by","the","model","dropout_prob",":","dropout","probability","for","the","decoder","dec_num_heads",":","number","of","attention","heads","in","the","decoder","dec_ff_dim",":","dimension","of","the","feed","forward","layer","in","the","decoder","dec_ffd_ratio",":","depth","multiplier","for","the","feed","forward","layer","in","the","decoder","input_shape",":","input","shape","of","the","image","exportable",":","onnx","exportable","returns","only","logits","cfg",":","dictionary","containing","information","about","the","model"]
code: def __init__(
      self,
      feature_extractor,
      vocab: str,
      embedding_units: int,
      max_length: int = 32,  # different from paper
      dropout_prob: float = 0.1,
      dec_num_heads: int = 12,
      dec_ff_dim: int = 384,  # we use it from the original implementation instead of 2048
      dec_ffd_ratio: int = 4,
      input_shape: Tuple[int, int, int] = (32, 128, 3),
      exportable: bool = False,
      cfg: Optional[Dict[str, Any]] = None,
  ) -> None:
      super().__init__()
      self.vocab = vocab
      self.exportable = exportable
      self.cfg = cfg
      self.max_length = max_length
      self.vocab_size = len(vocab)
      self.rng = np.random.default_rng()
  
      self.feat_extractor = feature_extractor
      self.decoder = PARSeqDecoder(
          embedding_units,
          dec_num_heads,
          dec_ff_dim,
          dec_ffd_ratio,
          dropout_prob,
      )
      self.embed = CharEmbedding(
          self.vocab_size + 3, embedding_units
      )  # +3 for SOS, EOS, PAD
      self.head = layers.Dense(
          self.vocab_size + 1, name="head"
      )  # +1 for EOS
      self.pos_queries = self.add_weight(
          shape=(1, self.max_length + 1, embedding_units),
          initializer="zeros",
          trainable=True,
          name="positions",
      )
      self.dropout = layers.Dropout(dropout_prob)
  
      self.postprocessor = PARSeqPostProcessor(vocab=self.vocab)
  
imports: import math
  from copy import deepcopy
  from itertools import permutations
  from typing import Any, Dict, List, Optional, Tuple
  import numpy
  import tensorflow
  from tensorflow.keras import Model, layers
  from doctr.datasets import VOCABS
  from doctr.models.modules.transformer import MultiHeadAttention, PositionwiseFeedForward
  from ...classification import vit_s
  from ...utils.tensorflow import _bf16_to_float32, load_pretrained_params
  from .base import _PARSeq, _PARSeqPostProcessor
label_desc: Use image node_id 1 to create a new PARSeq object from inherited base classes: _PARSeq, Model with example: obj = PARSeq(feature_extractor, vocab, embedding_units, max_length, dropout_prob, dec_num_heads, dec_ff_dim, dec_ffd_ratio, input_shape, exportable, cfg)