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
      dropout_prob: dropout probability of the encoder LSTM
      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","dropout_prob",":","dropout","probability","of","the","encoder","LSTM","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:
  ----
      model_output: predicted logits of the model
      gt: the encoded tensor with gt labels
      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",":","--","--","model_output",":","predicted","logits","of","the","model","gt",":","the","encoded","tensor","with","gt","labels","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: torch.Tensor,
      gt: torch.Tensor,
      seq_len: torch.Tensor,
  ) -> torch.Tensor:
      """Compute categorical cross-entropy loss for the model.
      Sequences are masked after the EOS character.
  
      Args:
      ----
          model_output: predicted logits of the model
          gt: the encoded tensor with gt labels
          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 = model_output.shape[1]
      # Add one for additional <eos> token
      seq_len = seq_len + 1  # type: ignore[assignment]
      # Compute loss
      # (N, L, vocab_size + 1)
      cce = F.cross_entropy(
          model_output.permute(0, 2, 1), gt, reduction="none"
      )
      mask_2d = (
          torch.arange(input_len, device=model_output.device)[None, :]
          >= seq_len[:, None]
      )
      cce[mask_2d] = 0
  
      ce_loss = cce.sum(1) / seq_len.to(dtype=model_output.dtype)
      return ce_loss.mean()
  
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 ...classification import resnet31
  from ...utils.pytorch import _bf16_to_float32, load_pretrained_params
  from ..core import RecognitionModel, RecognitionPostProcessor
label_desc: Use image node_id 3 for calling the SAR obj's underlying member method code with example usage: obj.compute_loss(model_output, gt, seq_len) and returns: ce_loss