code: def _masked_softmax(tensor, mask):
      tensor_shape = tensor.size()
      reshaped_tensor = tensor.view(-1, tensor_shape[-1])
  
      # Reshape the mask so it matches the size of the input tensor.
      while mask.dim() < tensor.dim():
          mask = mask.unsqueeze(1)
      mask = mask.expand_as(tensor).contiguous().float()
      reshaped_mask = mask.view(-1, mask.size()[-1])
      result = F.softmax(reshaped_tensor * reshaped_mask, dim=-1)
      result = result * reshaped_mask
      # 1e-13 is added to avoid divisions by zero.
      result = result / (result.sum(dim=-1, keepdim=True) + 1e-13)
      return result.view(*tensor_shape)
  
imports: import math
  import torch
  import torch.nn.functional
  from torch import nn
  from .decoder.seq2seq_state import TransformerState
label_desc: Use image node_id 1 for calling a global function with example usage: _masked_softmax(tensor, mask) and returns: result