Skip to content

How to Learn the Explanations of an Existing Model#

The FrozenModelTrainer is dedicated to learn the explanations of an existing model, where only the explanations are trained, the existing model itself remains unchanged.

The steps explaining how explanations are learned for an existing model are described below.

Build the model#

The first step consists in designing a model with frozen weights. We will follow the previous tutorial on how to create an explainable model, and focus on the differences between explaining an existing model and learning a self-explainable model.

Similarly to the model creation designed to be trained and to get the learned explanations, the explanation of an existing model requires your original model to be converted into an explainable model, please follow how to convert your original model to an XpdeepModel.

Info

Your model weights are conserved, therefore you will get the same performance on your original model and on your converted explainable model.

Model Specifications#

The specification of the existing model (Model specification ) must be slightly revised in order to learn its explanations. This operation does not alter the architecture or the weights of the existing model.

Set the frozen_model parameter to True to specify the context of learning the explanations of an existing model.

from xpdeep.model.model_parameters import ModelDecisionGraphParameters
from xpdeep.model.feature_extraction_output_type import FeatureExtractionOutputType

build_configuration = ModelDecisionGraphParameters(
  feature_extraction_output_type=FeatureExtractionOutputType.VECTOR,
  frozen_model=True
)

Train to Learn the Explanations#

The training process remains similar to that of a self-explainable model. The Trainer object requires specifying the max_epochs parameter, which represents the number of epochs dedicated to learning the explanations of the existing model. You should use the FrozenModelTrainer.

Internally, Xpdeep uses its own internal algorithm to compute and train explanations while conserving the original model parameters and performances intact.

from xpdeep.trainer.trainer import FrozenModelTrainer

trainer = FrozenModelTrainer(max_epochs=5)