class_docstr: Partial Dependence Plot interpreter.
docstr: Create PDP chart info using provided inputs.
  
  Args:
    inputs: sequence of inputs, following model.input_spec()
    model: optional model to use to generate new examples.
    dataset: dataset which the current examples belong to.
    model_outputs: optional precomputed model outputs
    config: optional runtime config.
  
  Returns:
    A dict of alternate feature values to model outputs. The model outputs
    will be a number for regression models and a list of numbers for
    multiclass models.
  
  Raises:
    KeyError: `config` does not have a value for `feature`
    TypeError: `config` is missing
docstr_tok: ["Create","PDP","chart","info","using","provided","inputs",".","Args",":","inputs",":","sequence","of","inputs",",","following","model.input_spec","(",")","model",":","optional","model","to","use","to","generate","new","examples",".","dataset",":","dataset","which","the","current","examples","belong","to",".","model_outputs",":","optional","precomputed","model","outputs","config",":","optional","runtime","config",".","Returns",":","A","dict","of","alternate","feature","values","to","model","outputs",".","The","model","outputs","will","be","a","number","for","regression","models","and","a","list","of","numbers","for","multiclass","models",".","Raises",":","KeyError",":","`","config","`","does","not","have","a","value","for","`","feature","`","TypeError",":","`","config","`","is","missing"]
code: def run(
      self,
      inputs: list[types.JsonDict],
      model: lit_model.Model,
      dataset: lit_dataset.Dataset,
      model_outputs: Optional[list[types.JsonDict]] = None,
      config: Optional[types.JsonDict] = None,
  ):
      """Create PDP chart info using provided inputs.
  
      Args:
        inputs: sequence of inputs, following model.input_spec()
        model: optional model to use to generate new examples.
        dataset: dataset which the current examples belong to.
        model_outputs: optional precomputed model outputs
        config: optional runtime config.
  
      Returns:
        A dict of alternate feature values to model outputs. The model outputs
        will be a number for regression models and a list of numbers for
        multiclass models.
  
      Raises:
        KeyError: `config` does not have a value for `feature`
        TypeError: `config` is missing
      """
  
      if not config:
          raise TypeError("config must be provided")
  
      feature = config.get("feature")
      if not feature:
          raise KeyError('Config must have a "feature" field')
  
      pred_keys = utils.find_spec_keys(
          model.output_spec(), _SUPPORTED_PRED_TYPES
      )
      if not pred_keys:
          logging.warning(
              "PDP did not find any supported output fields."
          )
          return None
  
      provided_range = config.get("range", [])
      edited_outputs = {pred_key: {} for pred_key in pred_keys}
  
      # If a range was provided, use that to create the possible values.
      vals_to_test = (
          np.linspace(provided_range[0], provided_range[1], 10)
          if len(provided_range) == 2
          else self.get_vals_to_test(feature, dataset)
      )
  
      # If no specific inputs provided, use the entire dataset.
      inputs_to_use = inputs if inputs else dataset.examples
  
      # For each alternate value for a given feature.
      for new_val in vals_to_test:
          # Create copies of all provided inputs with the value replaced.
          edited_inputs = [
              utils.make_modified_input(inp, {feature: new_val}, "PDP")
              for inp in inputs_to_use
          ]
  
          # Run prediction on the altered inputs.
          outputs = list(model.predict(edited_inputs))
  
          # Store the mean of the prediction for the alternate value.
          for pred_key in pred_keys:
              field_spec = model.output_spec().get(pred_key)
              if isinstance(field_spec, types.RegressionScore):
                  edited_outputs[pred_key][new_val] = np.mean(
                      [output[pred_key] for output in outputs]
                  )
              else:
                  edited_outputs[pred_key][new_val] = np.mean(
                      [output[pred_key] for output in outputs], axis=0
                  )
  
      return edited_outputs
  
file_path: lit/lit_nlp/components/pdp.py
imports: import functools
  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 model
  from lit_nlp.api import types
  from lit_nlp.lib import utils
  import numpy
label_desc: Use image node_id 3 for calling the PdpInterpreter obj's underlying member method code with example usage: obj.run(inputs, model, dataset, model_outputs, config) and returns: edited_outputs, None