code: def control_sparsity(mask: torch.Tensor, sparsity: float = None):
      r"""
      Transform the mask where top 1 - sparsity values are set to inf.
      Args:
          mask (torch.Tensor): Mask that need to transform.
          sparsity (float): Sparsity we need to control i.e. 0.7, 0.5 (Default: :obj:`None`).
      :rtype: torch.Tensor
      """
      if sparsity is None:
          sparsity = 0.7
  
      # Not apply here, Please refer to specific explainers in other directories
      #
      # if data_args.model_level == 'node':
      #     assert self.hard_edge_mask is not None
      #     mask_indices = torch.where(self.hard_edge_mask)[0]
      #     sub_mask = mask[self.hard_edge_mask]
      #     mask_len = sub_mask.shape[0]
      #     _, sub_indices = torch.sort(sub_mask, descending=True)
      #     split_point = int((1 - sparsity) * mask_len)
      #     important_sub_indices = sub_indices[: split_point]
      #     important_indices = mask_indices[important_sub_indices]
      #     unimportant_sub_indices = sub_indices[split_point:]
      #     unimportant_indices = mask_indices[unimportant_sub_indices]
      #     trans_mask = mask.clone()
      #     trans_mask[:] = - float('inf')
      #     trans_mask[important_indices] = float('inf')
      # else:
      _, indices = torch.sort(mask, descending=True)
      mask_len = mask.shape[0]
      split_point = int((1 - sparsity) * mask_len)
      important_indices = indices[:split_point]
      unimportant_indices = indices[split_point:]
      trans_mask = mask.clone()
      trans_mask[important_indices] = float("inf")
      trans_mask[unimportant_indices] = -float("inf")
  
      return trans_mask
  
imports: import torch
  import torch.nn
  from typing import List, Union
  from torch import Tensor
  import numpy
  from torch_geometric.data.data import Data
  from torch_geometric.nn import MessagePassing
label_desc: Use image node_id 1 for calling a global function with example usage: control_sparsity(mask, sparsity) and returns: trans_mask