chemprop.callbacks.interpret
============================

.. py:module:: chemprop.callbacks.interpret


Attributes
----------

.. autoapisummary::

   chemprop.callbacks.interpret.logger


Classes
-------

.. autoapisummary::

   chemprop.callbacks.interpret.MyersonExplainerCallback


Module Contents
---------------

.. py:data:: logger

.. py:class:: MyersonExplainerCallback(model_paths, output, sampling_threshold = 20, save_as_json = False)

   Bases: :py:obj:`lightning.pytorch.callbacks.Callback`


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

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

   Alternatively, if :code:`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).

   :param model_paths: A list of paths to the models to be used for explanations.
   :type model_paths: list[Path]
   :param output: The path to the output file for saving predictions, used to derive the explanation file path.
   :type output: Path
   :param sampling_threshold: 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.
   :type sampling_threshold: int, default=20
   :param save_as_json: If `True`, save the explanations as a JSON file instead of a npz file.
   :type save_as_json: bool, default=False


   .. py:attribute:: sampling_threshold
      :value: 20



   .. py:attribute:: save_as_json
      :value: False



   .. py:attribute:: model_counter
      :value: 0



   .. py:attribute:: max_model_counter
      :value: -1



   .. py:attribute:: output_filename_base


   .. py:attribute:: output_path_dir


   .. py:method:: on_predict_start(trainer, pl_module)

      Called when the predict begins.



   .. py:method:: on_predict_batch_end(trainer, pl_module, outputs, batch, batch_idx, dataloader_idx = 0)

      Called when the predict batch ends.



   .. py:method:: on_predict_end(trainer, pl_module)

      Called when predict ends.



