docstr: Tests clustering on LIT-internal gradient methods.
docstr_tok: ["Tests","clustering","on","LIT-internal","gradient","methods","."]
code: def test_clustering(self, salience_mapper, grad_key):
      """Tests clustering on LIT-internal gradient methods."""
      config = {
          salience_clustering.SALIENCE_MAPPER_KEY: salience_mapper,
          salience_clustering.N_CLUSTERS_KEY: 2,
          salience_clustering.TOP_K_TOKENS_KEY: 2,
      }
      (
          result,
          clustering_component,
          *_,
      ) = self._call_classification_model_on_standard_input(
          config, grad_key
      )
      # Cluster id assignment is random, so in one run the first 2 examples may
      # be cluster 0, in the next run they may be in cluster 1.
      cluster_id_of_first = result[salience_clustering.CLUSTER_ID_KEY][
          grad_key
      ][0]
      cluster_id_of_last = result[salience_clustering.CLUSTER_ID_KEY][
          grad_key
      ][-1]
      np.testing.assert_equal(
          result[salience_clustering.CLUSTER_ID_KEY][grad_key],
          [
              cluster_id_of_first,
              cluster_id_of_first,
              cluster_id_of_last,
              cluster_id_of_last,
              cluster_id_of_last,
          ],
      )
      np.testing.assert_allclose(
          result[salience_clustering.REPRESENTATION_KEY][grad_key][0],
          result[salience_clustering.REPRESENTATION_KEY][grad_key][1],
      )
      np.testing.assert_allclose(
          result[salience_clustering.REPRESENTATION_KEY][grad_key][2],
          result[salience_clustering.REPRESENTATION_KEY][grad_key][3],
      )
      np.testing.assert_allclose(
          result[salience_clustering.REPRESENTATION_KEY][grad_key][2],
          result[salience_clustering.REPRESENTATION_KEY][grad_key][4],
      )
      self.assertIn(grad_key, clustering_component.kmeans)
      self.assertIsNotNone(clustering_component.kmeans[grad_key])
  
imports: from absl.testing import absltest
  from absl.testing import parameterized
  from lit_nlp.api import dataset
  from lit_nlp.api import dtypes
  from lit_nlp.components import gradient_maps
  from lit_nlp.components import lime_explainer
  from lit_nlp.components import salience_clustering
  from lit_nlp.lib import testing_utils
  import numpy
label_desc: Use image node_id 5 for calling the SalienceClusteringTest obj's underlying member method code with example usage: obj.test_clustering(salience_mapper, grad_key) without return types