class_docstr: Implements a SAR architecture as described in `"Show, Attend and Read:A Simple and Strong Baseline for
  Irregular Text Recognition" <https://arxiv.org/pdf/1811.00751.pdf>`_.
  
  Args:
  ----
      feature_extractor: the backbone serving as feature extractor
      vocab: vocabulary used for encoding
      rnn_units: number of hidden units in both encoder and decoder LSTM
      embedding_units: number of embedding units
      attention_units: number of hidden units in attention module
      max_length: maximum word length handled by the model
      num_decoder_cells: number of LSTMCell layers to stack
      dropout_prob: dropout probability for the encoder and decoder
      exportable: onnx exportable returns only logits
      cfg: dictionary containing information about the model
class_docstr_tok: ["Implements","a","SAR","architecture","as","described","in","`","``","Show",",","Attend","and","Read",":","A","Simple","and","Strong","Baseline","for","Irregular","Text","Recognition","''","<","https",":","\/\/arxiv.org\/pdf\/1811.00751.pdf",">","`","_",".","Args",":","--","--","feature_extractor",":","the","backbone","serving","as","feature","extractor","vocab",":","vocabulary","used","for","encoding","rnn_units",":","number","of","hidden","units","in","both","encoder","and","decoder","LSTM","embedding_units",":","number","of","embedding","units","attention_units",":","number","of","hidden","units","in","attention","module","max_length",":","maximum","word","length","handled","by","the","model","num_decoder_cells",":","number","of","LSTMCell","layers","to","stack","dropout_prob",":","dropout","probability","for","the","encoder","and","decoder","exportable",":","onnx","exportable","returns","only","logits","cfg",":","dictionary","containing","information","about","the","model"]
docstr: Compute categorical cross-entropy loss for the model.
  Sequences are masked after the EOS character.
  
  Args:
  ----
      gt: the encoded tensor with gt labels
      model_output: predicted logits of the model
      seq_len: lengths of each gt word inside the batch
  
  Returns:
  -------
      The loss of the model on the batch
docstr_tok: ["Compute","categorical","cross-entropy","loss","for","the","model",".","Sequences","are","masked","after","the","EOS","character",".","Args",":","--","--","gt",":","the","encoded","tensor","with","gt","labels","model_output",":","predicted","logits","of","the","model","seq_len",":","lengths","of","each","gt","word","inside","the","batch","Returns",":","--","--","--","-","The","loss","of","the","model","on","the","batch"]
code: def compute_loss(
      model_output: tf.Tensor,
      gt: tf.Tensor,
      seq_len: tf.Tensor,
  ) -> tf.Tensor:
      """Compute categorical cross-entropy loss for the model.
      Sequences are masked after the EOS character.
  
      Args:
      ----
          gt: the encoded tensor with gt labels
          model_output: predicted logits of the model
          seq_len: lengths of each gt word inside the batch
  
      Returns:
      -------
          The loss of the model on the batch
      """
      # Input length : number of timesteps
      input_len = tf.shape(model_output)[1]
      # Add one for additional <eos> token
      seq_len = seq_len + 1
      # One-hot gt labels
      oh_gt = tf.one_hot(gt, depth=model_output.shape[2])
      # Compute loss
      cce = tf.nn.softmax_cross_entropy_with_logits(oh_gt, model_output)
      # Compute mask
      mask_values = tf.zeros_like(cce)
      mask_2d = tf.sequence_mask(seq_len, input_len)
      masked_loss = tf.where(mask_2d, cce, mask_values)
      ce_loss = tf.math.divide(
          tf.reduce_sum(masked_loss, axis=1),
          tf.cast(seq_len, model_output.dtype),
      )
      return tf.expand_dims(ce_loss, axis=1)
  
imports: from copy import deepcopy
  from typing import Any, Dict, List, Optional, Tuple
  import tensorflow
  from tensorflow.keras import Model, Sequential, layers
  from doctr.datasets import VOCABS
  from doctr.utils.repr import NestedObject
  from ...classification import resnet31
  from ...utils.tensorflow import _bf16_to_float32, load_pretrained_params
  from ..core import RecognitionModel, RecognitionPostProcessor
label_desc: Use image node_id 2 for calling the SAR obj's underlying member method code with example usage: obj.compute_loss(model_output, gt, seq_len) and returns: tf