code: def _get_mask(length, max_length):
      """Generate a square mask for the sequence. The masked positions are filled with float('-inf').
      Unmasked positions are filled with float(0.0).
      """
      length = length.unsqueeze(-1)
      B = paddle.shape(length)[0]
      grid = paddle.arange(0, max_length).unsqueeze(0).tile([B, 1])
      zero_mask = paddle.zeros([B, max_length], dtype="float32")
      inf_mask = paddle.full([B, max_length], "-inf", dtype="float32")
      diag_mask = paddle.diag(
          paddle.full([max_length], "-inf", dtype=paddle.float32),
          offset=0,
          name=None,
      )
      mask = paddle.where(grid >= length, inf_mask, zero_mask)
      mask = mask.unsqueeze(1) + diag_mask
      return mask.unsqueeze(1)
  
imports: import math
  import paddle
  from paddle import nn
  import paddle.nn.functional
  from paddle.nn import LayerList
  from ppocr.modeling.heads.rec_nrtr_head import TransformerBlock, PositionalEncoding
label_desc: Use image node_id 4 for calling a global function with example usage: _get_mask(length, max_length) and returns: mask