code: def _slice_by_percentiles(
      data: AttackInputData,
      from_percentile: float,
      to_percentile: float,
      return_slice_indices: bool = False,
  ) -> AttackInputData:
      """Slices samples by loss percentiles."""
  
      # Find from_percentile and to_percentile percentiles in losses.
      loss_train = data.get_loss_train()
      loss_test = data.get_loss_test()
      if data.is_multilabel_data():
          logging.info(
              "For multilabel data, when slices by percentiles are "
              "requested, losses are summed over the class axis before "
              "slicing."
          )
          loss_train = np.sum(loss_train, axis=1)
          loss_test = np.sum(loss_test, axis=1)
      losses = np.concatenate((loss_train, loss_test))
      from_loss = np.percentile(losses, from_percentile)
      to_loss = np.percentile(losses, to_percentile)
  
      idx_train = (from_loss <= loss_train) & (loss_train <= to_loss)
      idx_test = (from_loss <= loss_test) & (loss_test <= to_loss)
  
      return _slice_data_by_indices(
          data, idx_train, idx_test, return_slice_indices
      )
  
file_path: privacy/tensorflow_privacy/privacy/privacy_tests/membership_inference_attack/dataset_slicing.py
imports: from collections import abc
  import copy
  import logging
  from typing import List, Optional
  import numpy
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import AttackInputData
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import SingleSliceSpec
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import SlicingFeature
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import SlicingSpec
label_desc: Use image node_id 4 for calling a global function with example usage: _slice_by_percentiles(data, from_percentile, to_percentile, return_slice_indices) and returns: _slice_data_by_indices