code: def apply_masks(scores, batch_size, unseen_mask, src_lengths):
      seq_len = scores.shape[-1]
  
      # [1, seq_len, seq_len]
      sequence_mask = torch.ones(seq_len, seq_len).unsqueeze(0).int()
      if unseen_mask:
          # [1, seq_len, seq_len]
          sequence_mask = (
              torch.tril(torch.ones(seq_len, seq_len), diagonal=0)
              .unsqueeze(0)
              .int()
          )
  
      if src_lengths is not None:
          # [batch_size, 1, seq_len]
          src_lengths_mask = create_src_lengths_mask(
              batch_size=batch_size, src_lengths=src_lengths
          ).unsqueeze(-2)
  
          # [batch_size, seq_len, seq_len]
          sequence_mask = sequence_mask & src_lengths_mask
  
      # [batch_size, 1, seq_len, seq_len]
      sequence_mask = sequence_mask.unsqueeze(1)
  
      scores = scores.masked_fill(sequence_mask == 0, -np.inf)
      return scores
  
file_path: translate/pytorch_translate/research/attention/multihead_attention.py
imports: import math
  import numpy
  import torch
  import torch.nn.functional
  from torch import nn
label_desc: Use image node_id 2 for calling a global function with example usage: apply_masks(scores, batch_size, unseen_mask, src_lengths) and returns: scores