chemprop.callbacks.interpret#

Attributes#

Classes#

MyersonExplainerCallback

A MyersonExplainerCallback calculates and saves Myerson explanations during a predict call.

Module Contents#

chemprop.callbacks.interpret.logger#
class chemprop.callbacks.interpret.MyersonExplainerCallback(model_paths, output, sampling_threshold=20, save_as_json=False)[source]#

Bases: lightning.pytorch.callbacks.Callback

A MyersonExplainerCallback calculates and saves Myerson explanations during a predict call.

The explanations are saved as a compressed NumPy archive (.npz file) by default. Each molecule’s explanation is saved as a separate array within the archive (e.g., arr_0, arr_1, etc.). Each array will be a 1D or 2D NumPy array of shape num_atoms (for regression or binary classification) or num_atoms x num_classes (for multi-label classification) containing the explanation for one molecule.

Alternatively, if save_as_json is set to True, the explanations are saved as a JSON file. The JSON file contains a list of explanations, where each explanation corresponds to a molecule. For 2D explanations (multi-label), each inner list represents a column (i.e., attributions for a specific label across all atoms).

Parameters:
  • model_paths (list[Path]) – A list of paths to the models to be used for explanations.

  • output (Path) – The path to the output file for saving predictions, used to derive the explanation file path.

  • sampling_threshold (int, default=20) – The maximum number of atoms in a molecule for which to use the exact explainer. For molecules with more atoms, a sampling-based explainer is used.

  • save_as_json (bool, default=False) – If True, save the explanations as a JSON file instead of a npz file.

sampling_threshold = 20#
save_as_json = False#
model_counter = 0#
max_model_counter = -1#
output_filename_base#
output_path_dir#
on_predict_start(trainer, pl_module)[source]#

Called when the predict begins.

on_predict_batch_end(trainer, pl_module, outputs, batch, batch_idx, dataloader_idx=0)[source]#

Called when the predict batch ends.

Parameters:
  • trainer (lightning.pytorch.Trainer)

  • pl_module (lightning.pytorch.LightningModule)

  • outputs (Any)

  • batch (Any)

  • batch_idx (int)

  • dataloader_idx (int)

on_predict_end(trainer, pl_module)[source]#

Called when predict ends.