torch_concepts.nn.functional.intervention_score

intervention_score(y_predictor: ~torch.nn.modules.module.Module, c_pred: ~torch.Tensor, c_true: ~torch.Tensor, y_true: ~torch.Tensor, intervention_groups: ~typing.List[~typing.List[int]], activation: ~typing.Callable = <built-in method sigmoid of type object>, scorer: ~typing.Callable = <function roc_auc_score>, average: str = 'macro', auc: bool = True) float | List[float][source]

Compute the effect of concept interventions on downstream task predictions.

Given set of intervention groups, the intervention score measures the effectiveness of each intervention group on the model’s task predictions.

Main reference: “Concept Bottleneck Models”

Parameters:
  • y_predictor (torch.nn.Module) – Model that predicts downstream task abels.

  • c_pred (torch.Tensor) – Predicted concept values.

  • c_true (torch.Tensor) – Ground truth concept values.

  • y_true (torch.Tensor) – Ground truth task labels.

  • intervention_groups (List[List[int]]) – List of intervention groups.

  • activation (Callable) – Activation function to apply to the model’s predictions. Default is torch.sigmoid.

  • scorer (Callable) – Scoring function to evaluate predictions. Default is roc_auc_score.

  • average (str) – Type of averaging to use. Default is ‘macro’.

  • auc (bool) – Whether to return the average score across all intervention groups. Default is True.

Returns:

The intervention effectiveness for each

intervention group or the average score across all groups.

Return type:

Union[float, List[float]]