code: def sequence_mask(X, valid_len, value=0, axis=0):
      """Mask irrelevant entries in sequences."""
      assert axis in (0, 1)
      maxlen = X.size(axis)
      if axis == 1:
          mask = (
              th.arange((maxlen), dtype=th.float32, device=X.device)[
                  None, :
              ]
              < valid_len[:, None]
          )
      else:
          mask = (
              th.arange((maxlen), dtype=th.float32, device=X.device)[
                  :, None
              ]
              < valid_len[None, :]
          )
      X[~mask] = value
      return X
  
imports: import math
  from collections import OrderedDict
  import torch
  import numpy
  from torch import nn
  from typing import Union
  from .utils import to_torch_dtype
label_desc: Use image node_id 1 for calling a global function with example usage: sequence_mask(X, valid_len, value, axis) and returns: X