class_docstr: Salience map using the values of gradient * input as attribution.
class_docstr_tok: ["Salience","map","using","the","values","of","gradient","*","input","as","attribution","."]
docstr: Run this component, given a model and input(s).
docstr_tok: ["Run","this","component",",","given","a","model","and","input","(","s",")","."]
code: def run(
      self,
      inputs: list[JsonDict],
      model: lit_model.Model,
      dataset: lit_dataset.Dataset,
      model_outputs: Optional[list[JsonDict]] = None,
      config: Optional[JsonDict] = None,
  ) -> Optional[list[JsonDict]]:
      """Run this component, given a model and input(s)."""
      # Find gradient fields to interpret
      output_spec = model.output_spec()
      grad_fields = self.find_fields(output_spec)
      logging.info(
          "Found fields for gradient attribution: %s", str(grad_fields)
      )
      if (
          len(grad_fields) == 0
      ):  # pylint: disable=g-explicit-length-test
          return None
  
      # Run model, if needed.
      if model_outputs is None:
          model_outputs = list(model.predict(inputs))
      assert len(model_outputs) == len(inputs)
  
      all_results: list[JsonDict] = []
      for o in model_outputs:
          result: dict[str, dtypes.TokenSalience] = {}
          for grad_field in grad_fields:
              embeddings_field = cast(
                  types.TokenGradients, output_spec[grad_field]
              ).grad_for
              scores = self._interpret(
                  o[grad_field], o[embeddings_field]
              )
  
              token_field = cast(
                  types.TokenGradients, output_spec[grad_field]
              ).align
              tokens = o[token_field]
              result[grad_field] = dtypes.TokenSalience(tokens, scores)
          all_results.append(result)
  
      return all_results
  
imports: from typing import cast, Optional
  from absl import logging
  from lit_nlp.api import components
  from lit_nlp.api import dataset
  from lit_nlp.api import dtypes
  from lit_nlp.api import model
  from lit_nlp.api import types
  from lit_nlp.components.citrus import utils
  from lit_nlp.lib import utils
  import numpy
label_desc: Use image node_id 3 for calling the GradientDotInput obj's underlying member method code with example usage: obj.run(inputs, model, dataset, model_outputs, config) and returns: all_results, None