def subsequent_mask(size):
    """Generate a square mask for the sequence. The masked positions are filled with float('-inf').
        Unmasked positions are filled with float(0.0).
    """
    mask = torch.ones(1, size, size, dtype=torch.float32)
    mask_inf = torch.triu(
        torch.full(
            size=[1, size, size], fill_value=-np.inf, dtype=torch.float32),
        diagonal=1)
    mask = mask + mask_inf
    padding_mask = torch.equal(mask, torch.Tensor(1).type(mask.dtype))
    return padding_mask
Generate a square mask for the sequence. The masked positions are filled with float('-inf').
Unmasked positions are filled with float(0.0).
pytorchocr/modeling/heads/sr_rensnet_transformer.py