code: def _create_perturbation_mask(
      perturbed_feature_indices: Tensor,  # 1D tensor of one-hot feature indices
      feature_mask: Tuple[Tensor, ...],
      feature_idx_to_mask_idx: Dict[int, List[int]],
  ) -> Tuple[Union[Tensor, None], ...]:
      """
      Create binary mask for inputs based on perturbed one-hot feature indices
      Use None if no perturbation is needed for the corresponding input
      """
  
      # a set of input/mask indices that need perturbation
      perturbation_mask_indices = set()
      for i, v in enumerate(perturbed_feature_indices.tolist()):
          # value 0 means the feature has been perturbed
          if not v:
              perturbation_mask_indices |= set(
                  feature_idx_to_mask_idx[i]
              )
  
      # create binary mask for inputs & set it to None if no perturbation is needed
      perturbation_mask = tuple(
          perturbed_feature_indices[mask_elem]
          if i in perturbation_mask_indices
          else None
          for i, mask_elem in enumerate(feature_mask)
      )
  
      return perturbation_mask
  
file_path: captum/captum/attr/_core/dataloader_attr.py
imports: from collections import defaultdict
  from copy import copy
  from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
  import torch
  from captum._utils.common import _format_baseline, _format_feature_mask, _format_output, _format_tensor_into_tuples, _get_max_feature_index, _run_forward
  from captum._utils.typing import BaselineType
  from captum.attr._core.feature_ablation import FeatureAblation
  from captum.attr._utils.attribution import Attribution
  from torch import Tensor
label_desc: Use image node_id 2 for calling a global function with example usage: _create_perturbation_mask(perturbed_feature_indices, feature_mask, feature_idx_to_mask_idx) and returns: perturbation_mask