class_docstr: Transformer-based language model responsible for spell correction.
  Implementation of language model of \
      `ABINet <https://arxiv.org/pdf/2103.06495>`_.
  
  Args:
      dictionary (dict or :obj:`Dictionary`): The config for `Dictionary` or
          the instance of `Dictionary`. The dictionary must have an end
          token.
      d_model (int): Hidden size :math:`E` of model. Defaults to 512.
      n_head (int): Number of multi-attention heads.
      d_inner (int): Hidden size of feedforward network model.
      n_layers (int): The number of similar decoding layers.
      dropout (float): Dropout rate.
      detach_tokens (bool): Whether to block the gradient flow at input
       tokens.
      use_self_attn (bool): If True, use self attention in decoder layers,
          otherwise cross attention will be used.
      max_seq_len (int): Maximum sequence length :math:`T`. The
          sequence is usually generated from decoder. Defaults to 40.
      module_loss (dict, optional): Config to build loss. Defaults to None.
      postprocessor (dict, optional): Config to build postprocessor.
          Defaults to None.
      init_cfg (dict or list[dict], optional): Initialization configs.
          Defaults to None.
class_docstr_tok: ["Transformer-based","language","model","responsible","for","spell","correction",".","Implementation","of","language","model","of","\\","`","ABINet","<","https",":","\/\/arxiv.org\/pdf\/2103.06495",">","`","_",".","Args",":","dictionary","(","dict","or",":","obj",":","`","Dictionary","`",")",":","The","config","for","`","Dictionary","`","or","the","instance","of","`","Dictionary","`",".","The","dictionary","must","have","an","end","token",".","d_model","(","int",")",":","Hidden","size",":","math",":","`","E","`","of","model",".","Defaults","to","512.","n_head","(","int",")",":","Number","of","multi-attention","heads",".","d_inner","(","int",")",":","Hidden","size","of","feedforward","network","model",".","n_layers","(","int",")",":","The","number","of","similar","decoding","layers",".","dropout","(","float",")",":","Dropout","rate",".","detach_tokens","(","bool",")",":","Whether","to","block","the","gradient","flow","at","input","tokens",".","use_self_attn","(","bool",")",":","If","True",",","use","self","attention","in","decoder","layers",",","otherwise","cross","attention","will","be","used",".","max_seq_len","(","int",")",":","Maximum","sequence","length",":","math",":","`","T","`",".","The","sequence","is","usually","generated","from","decoder",".","Defaults","to","40.","module_loss","(","dict",",","optional",")",":","Config","to","build","loss",".","Defaults","to","None",".","postprocessor","(","dict",",","optional",")",":","Config","to","build","postprocessor",".","Defaults","to","None",".","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","configs",".","Defaults","to","None","."]
docstr: Generate location masks given input sequence length.
  
  Args:
      seq_len (int): The length of input sequence to transformer.
      device (torch.device or str, optional): The device on which the
          masks will be placed.
  
  Returns:
      Tensor: A mask tensor of shape (seq_len, seq_len) with -infs on
      diagonal and zeros elsewhere.
docstr_tok: ["Generate","location","masks","given","input","sequence","length",".","Args",":","seq_len","(","int",")",":","The","length","of","input","sequence","to","transformer",".","device","(","torch.device","or","str",",","optional",")",":","The","device","on","which","the","masks","will","be","placed",".","Returns",":","Tensor",":","A","mask","tensor","of","shape","(","seq_len",",","seq_len",")","with","-infs","on","diagonal","and","zeros","elsewhere","."]
code: def _get_location_mask(
      seq_len: int, device: Union[Optional[torch.device], str] = None
  ) -> torch.Tensor:
      """Generate location masks given input sequence length.
  
      Args:
          seq_len (int): The length of input sequence to transformer.
          device (torch.device or str, optional): The device on which the
              masks will be placed.
  
      Returns:
          Tensor: A mask tensor of shape (seq_len, seq_len) with -infs on
          diagonal and zeros elsewhere.
      """
      mask = torch.eye(seq_len, device=device)
      mask = mask.float().masked_fill(mask == 1, float("-inf"))
      return mask
  
file_path: mmocr/mmocr/models/textrecog/decoders/abi_language_decoder.py
imports: import copy
  from typing import Dict, List, Optional, Sequence, Union
  import torch
  import torch.nn
  from mmcv.cnn.bricks.transformer import BaseTransformerLayer
  from mmengine.model import ModuleList
  from mmocr.models.common.dictionary import Dictionary
  from mmocr.models.common.modules import PositionalEncoding
  from mmocr.registry import MODELS
  from mmocr.structures import TextRecogDataSample
  from .base import BaseDecoder
label_desc: Use image node_id 5 for calling the ABILanguageDecoder obj's underlying member method code with example usage: obj._get_location_mask(seq_len, device) and returns: mask