docstr: :param mask: mask that need to transform
  :param sparsity: sparsity we need to control i.e. 0.7, 0.5
  :return: transformed mask where top 1 - sparsity values are set to inf.
docstr_tok: [":","param","mask",":","mask","that","need","to","transform",":","param","sparsity",":","sparsity","we","need","to","control","i.e",".","0.7",",","0.5",":","return",":","transformed","mask","where","top","1","-","sparsity","values","are","set","to","inf","."]
code: def control_sparsity(self, mask: Tensor, sparsity=None, **kwargs):
      r"""
  
      :param mask: mask that need to transform
      :param sparsity: sparsity we need to control i.e. 0.7, 0.5
      :return: transformed mask where top 1 - sparsity values are set to inf.
      """
      if sparsity is None:
          sparsity = 0.7
  
      if not self.explain_graph:
          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: from typing import List, Tuple, Dict
  from math import sqrt
  import torch
  from torch import Tensor
  import torch.nn
  import matplotlib.pyplot
  import networkx
  from torch_geometric.nn import MessagePassing
  from torch_geometric.utils.loop import add_self_loops, remove_self_loops
  from torch_geometric.data import Data, Batch
  from torch_geometric.utils import to_networkx
  from ..models.utils import subgraph
  from rdkit import Chem
  from matplotlib.axes import Axes
  import numpy
  from ..models import GNNPool
label_desc: Use image node_id 8 for calling the ExplainerBase obj's underlying member method code with example usage: obj.control_sparsity(mask, sparsity) and returns: trans_mask