Model Wrappers¶
trulens.nn.models
¶
The TruLens library is designed to support models implemented via a variety of
different popular python neural network frameworks: Keras (with TensorFlow or
Theano backend), TensorFlow, and Pytorch. Models developed with different frameworks
implement things (e.g., gradient computations) a number of different ways. We define
framework specific ModelWrapper
instances to create a unified model API, providing the same
functionality to models that are implemented in disparate frameworks. In order to compute
attributions for a model, we provide a trulens.nn.models.get_model_wrapper
function
that will return an appropriate ModelWrapper
instance.
Some parameters are exclusively utilized for specific frameworks and are outlined in the parameter descriptions.
Functions¶
get_model_wrapper
¶
get_model_wrapper(model: ModelLike, *, logit_layer=None, replace_softmax: bool = False, softmax_layer=-1, custom_objects=None, device: str = None, input_tensors=None, output_tensors=None, internal_tensor_dict=None, default_feed_dict=None, session=None, backend=None, force_eval=True, **kwargs)
Returns a ModelWrapper implementation that exposes the components needed for computing attributions.
PARAMETER | DESCRIPTION |
---|---|
model |
The model to wrap. If using the TensorFlow 1 backend, this is expected to be a graph object.
TYPE:
|
logit_layer |
Supported for Keras and Pytorch models. Specifies the name or index of the layer that produces the logit predictions.
DEFAULT:
|
replace_softmax |
Supported for Keras models only. If true, the activation
function in the softmax layer (specified by
TYPE:
|
softmax_layer |
Supported for Keras models only. Specifies the layer that
performs the softmax. This layer should have an
DEFAULT:
|
custom_objects |
Optional, for use with Keras models only. A dictionary of custom objects used by the Keras model.
DEFAULT:
|
device |
Optional, for use with Pytorch models only. A string specifying the device to run the model on.
TYPE:
|
input_tensors |
Required for use with TensorFlow 1 graph models only. A list of tensors representing the input to the model graph.
DEFAULT:
|
output_tensors |
Required for use with TensorFlow 1 graph models only. A list of tensors representing the output to the model graph.
DEFAULT:
|
internal_tensor_dict |
Optional, for use with TensorFlow 1 graph models only. A dictionary mapping user-selected layer names to the internal tensors in the model graph that the user would like to expose. This is provided to give more human-readable names to the layers if desired. Internal tensors can also be accessed via the name given to them by tensorflow.
DEFAULT:
|
default_feed_dict |
Optional, for use with TensorFlow 1 graph models only. A dictionary of default values to give to tensors in the model graph.
DEFAULT:
|
session |
Optional, for use with TensorFlow 1 graph models only. A
DEFAULT:
|
backend |
Optional, for forcing a specific backend. String values recognized are pytorch, tensorflow, keras, or tf.keras.
DEFAULT:
|
force_eval |
_Optional, True will force a model.eval() call for PyTorch models. False will retain current model state
DEFAULT:
|
Returns: ModelWrapper