code: def mask_pad(w, lengths):
      batch = shape_list(lengths)[0]
      maxlen = tf.cast(tf.reduce_max(input_tensor=lengths), tf.int32)
      seq_mask = tf.reshape(
          tf.sequence_mask(lengths, maxlen=maxlen),
          [batch, 1, 1, maxlen],
      )
      b = tf.cast(seq_mask, tf.float32)
      w = w * b + -1e9 * (1 - b)
      return w
  
imports: import functools
  import numpy
  import tensorflow
  from finetune.optimizers.recompute_grads import recompute_grad
  from finetune.util.shapes import shape_list, lengths_from_eos_idx
  from finetune.nn.activations import act_fns
  from finetune.nn.nn_utils import dropout, norm
label_desc: Use image node_id 2 for calling a global function with example usage: mask_pad(w, lengths) and returns: w