Logic explanations for entropy-based LENs

torch_explain.logic.nn.entropy

torch_explain.logic.nn.entropy.explain_class(model: Module, c: Tensor, y: Tensor, train_mask: Tensor, val_mask: Tensor, target_class: int, edge_index: Optional[Tensor] = None, max_minterm_complexity: Optional[int] = None, topk_explanations: int = 3, max_accuracy: bool = False, concept_names: Optional[List] = None, try_all: bool = True, c_threshold: float = 0.5, y_threshold: float = 0.0, good_bad_terms: bool = False, simplify: bool = False) Tuple[str, Dict]

Generate a local explanation for a single sample. :param model: pytorch model :param c: input concepts :param y: target labels (MUST be one-hot encoded) :param train_mask: train mask :param val_mask: validation mask :param target_class: target class :param edge_index: edge index for graph data used in graph-based models :param max_minterm_complexity: maximum number of concepts per logic formula (per sample) :param topk_explanations: number of local explanations to be combined :param max_accuracy: if True a formula is simplified only if the simplified formula gets 100% accuracy :param concept_names: list containing the names of the input concepts :param try_all: if True, then tries all possible conjunctions of the top k explanations :param c_threshold: threshold to get truth values for concept predictions (i.e. pred<threshold = false, pred>threshold = true) :param y_threshold: threshold to get truth values for class predictions (i.e. pred<threshold = false, pred>threshold = true) :param good_bad_terms: if True, then good and bad terms are selected for local explanations :param simplify: if True, then the resulting local explanations are simplified to get more compact explanations :return: Global explanation

torch_explain.logic.nn.entropy.explain_classes(model: Module, c: Tensor, y: Tensor, train_mask: Optional[Tensor] = None, test_mask: Optional[Tensor] = None, val_mask: Optional[Tensor] = None, edge_index: Optional[Tensor] = None, max_minterm_complexity: int = 1000, topk_explanations: int = 1000, try_all: bool = False, c_threshold: float = 0.5, y_threshold: float = 0.0, concept_names: Optional[List[str]] = None, class_names: Optional[List[str]] = None, material: bool = False, good_bad_terms: bool = False, max_accuracy: bool = False, verbose: bool = False, simplify: bool = False) Tuple[Dict, Dict]

Explain LENs predictions with concept-based logic explanations.

Parameters:
  • model – pytorch model

  • c – input concepts

  • y – target labels

  • train_mask – train mask

  • test_mask – test mask

  • val_mask – validation mask

  • edge_index – edge index for graph data used in graph-based models

  • max_minterm_complexity – maximum number of concepts per logic formula (per sample)

  • topk_explanations – number of local explanations to be combined

  • try_all – if True, then tries all possible conjunctions of the top k explanations

  • c_threshold – threshold to get truth values for concept predictions (i.e. pred<threshold = false, pred>threshold = true)

  • y_threshold – threshold to get truth values for class predictions (i.e. pred<threshold = false, pred>threshold = true)

  • concept_names – list of concept names

  • class_names – list of class names

  • material – if True, then the explanations performance is computed for the material implication

  • good_bad_terms – if True, then good and bad terms are selected for local explanations

  • max_accuracy – if True, then the explanations performance is computed for the maximum accuracy

  • verbose – if True, then prints the explanations

  • simplify – if True, then the resulting local explanations are simplified to get more compact explanations

Returns:

Global and local explanations