code: def _weighted_sum(tensor, weights, mask):
      w_sum = weights.bmm(tensor)
      while mask.dim() < w_sum.dim():
          mask = mask.unsqueeze(1)
      mask = mask.transpose(-1, -2)
      mask = mask.expand_as(w_sum).contiguous().float()
      return w_sum * mask
  
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 2 for calling a global function with example usage: _weighted_sum(tensor, weights, mask) and returns: unknown