code: def test_classification(self) -> None:
      num_in = 40
      inputs = torch.arange(0.0, num_in * 2.0).reshape(2, num_in)
      baselines = torch.arange(0.0, num_in * 4.0).reshape(4, num_in)
      target = torch.tensor(1)
      # 10-class classification model
      model = SoftmaxModel(num_in, 20, 10)
      model.eval()
      model.zero_grad()
  
      gradient_shap = GradientShap(model)
      n_samples = 10
      attributions, delta = gradient_shap.attribute(
          inputs,
          baselines=baselines,
          target=target,
          n_samples=n_samples,
          stdevs=0.009,
          return_convergence_delta=True,
      )
      _assert_attribution_delta(
          self, (inputs,), (attributions,), n_samples, delta
      )
  
      # try to call `compute_convergence_delta` externally
      with self.assertRaises(AssertionError):
          gradient_shap.compute_convergence_delta(
              attributions, inputs, baselines, target=target
          )
      # now, let's expand target and choose random baselines from `baselines` tensor
      rand_indices = np.random.choice(
          baselines.shape[0], inputs.shape[0]
      ).tolist()
      chosen_baselines = baselines[rand_indices]
  
      target_extendes = torch.tensor([1, 1])
      external_delta = gradient_shap.compute_convergence_delta(
          attributions, chosen_baselines, inputs, target=target_extendes
      )
      _assert_delta(self, external_delta)
  
      # Compare with integrated gradients
      ig = IntegratedGradients(model)
      baselines = torch.arange(0.0, num_in * 2.0).reshape(2, num_in)
      attributions_ig = ig.attribute(
          inputs, baselines=baselines, target=target
      )
      self._assert_shap_ig_comparision(
          (attributions,), (attributions_ig,)
      )
  
file_path: captum/tests/attr/test_gradient_shap.py
imports: from typing import cast, Tuple, Union
  import numpy
  import torch
  from captum._utils.typing import Tensor
  from captum.attr._core.gradient_shap import GradientShap
  from captum.attr._core.integrated_gradients import IntegratedGradients
  from numpy import ndarray
  from tests.helpers.basic import assertTensorAlmostEqual, BaseTest
  from tests.helpers.basic_models import BasicLinearModel, BasicModel2
  from tests.helpers.classification_models import SoftmaxModel
label_desc: Use image node_id 4 for calling the Test obj's underlying member method code with example usage: obj.test_classification() without return types