class_docstr: Returns data for rendering ROC and Precision-Recall curves.
code: def run(
      self,
      inputs: Sequence[JsonDict],
      model: lit_model.Model,
      dataset: lit_dataset.Dataset,
      model_outputs: Optional[Sequence[JsonDict]] = None,
      config: Optional[JsonDict] = None,
  ):
      if not config:
          raise ValueError(
              "Curves required config parameters but received none."
          )
  
      if (target_label := config.get(TARGET_LABEL_KEY)) is None:
          raise ValueError(
              f"The config '{TARGET_LABEL_KEY}' field should contain the positive"
              f" class label."
          )
  
      # Find the prediction field key in the model output to use for calculations.
      output_spec = model.output_spec()
  
      if TARGET_PREDICTION_KEY in config:
          predictions_key: str = config[TARGET_PREDICTION_KEY]
      elif (
          len(pred_keys := self._find_supported_pred_keys(output_spec))
          == 1
      ):
          predictions_key: str = pred_keys[0]
      else:
          raise ValueError(
              "Unable to determine prediction field. Please provide one via the"
              f' "{TARGET_PREDICTION_KEY}" field in the CallConfig or update the'
              " model spec to output a single MulticlassPreds field."
          )
  
      if not inputs:
          return {ROC_DATA: [], PR_DATA: []}
  
      # Run prediction if needed:
      if model_outputs is None:
          model_outputs = list(model.predict(inputs))
  
      # Get scores for the target label.
      pred_spec = output_spec.get(predictions_key)
      if not isinstance(pred_spec, types.MulticlassPreds):
          raise TypeError(
              f"Expected {predictions_key} to be a MulticlassPreds field, but got a"
              f" {type(pred_spec).__name__}"
          )
  
      labels = pred_spec.vocab
      target_index = labels.index(target_label)
      scores = [o[predictions_key][target_index] for o in model_outputs]
  
      # Get ground truth for the target label.
      parent_key = pred_spec.parent
      ground_truth_list = []
      for ex in inputs:
          ground_truth_label = ex[parent_key]
          ground_truth = (
              1.0 if ground_truth_label == target_label else 0.0
          )
          ground_truth_list.append(ground_truth)
  
      # Compute ROC curve data.
      x, y, _ = metrics.roc_curve(ground_truth_list, scores)
      roc_data = list(zip(np.nan_to_num(x), np.nan_to_num(y)))
      roc_data.sort(key=lambda x: x[0])
  
      # Compute PR curve data.
      x, y, _ = metrics.precision_recall_curve(
          ground_truth_list, scores
      )
      pr_data = list(zip(np.nan_to_num(x), np.nan_to_num(y)))
      pr_data.sort(key=lambda x: x[0])
  
      # Create and return the result.
      return {ROC_DATA: roc_data, PR_DATA: pr_data}
  
file_path: lit/lit_nlp/components/curves.py
imports: from collections.abc import Sequence
  from typing import cast, Optional
  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
  from sklearn import metrics
label_desc: Use image node_id 1 for calling the CurvesInterpreter obj's underlying member method code with example usage: obj.run(inputs, model, dataset, model_outputs, config) and returns: dict, dict