Slices¶
trulens.nn.slices
¶
The slice, or layer, of the network provides flexibility over the level of abstraction for the explanation. In a low layer, an explanation may highlight the edges that were most important in identifying an object like a face, while in a higher layer, the explanation might highlight high-level features such as a nose or mouth. By raising the level of abstraction, explanations that generalize over larger sets of samples are possible.
Formally, A network, $f$, can be broken into a slice, $f = g \circ h$, where $h$ can be thought of as a pre-processor that computes features, and $g$ can be thought of as a sub-model that uses the features computed by $h$.
Classes¶
Cut
¶
Bases: object
A cut is the primary building block for a slice. It determines an internal component of a network to expose. A slice if formed by two cuts.
Functions¶
__init__
¶
PARAMETER | DESCRIPTION |
---|---|
name |
The name or index of a layer in the model, or a list containing the names/indices of mutliple layers.
TYPE:
|
anchor |
Determines whether input (
TYPE:
|
accessor |
An accessor function that operates on the layer, mapping the
tensor (or list thereof) corresponding to the layer's
input/output to another tensor (or list thereof). This can be
used to, e.g., extract a particular output from a layer that
produces a sequence of outputs. If
|
access_layer
¶
access_layer(layer: TensorLike) -> TensorLike
Applies self.accessor
to the result of collecting the relevant
tensor(s) associated with a layer's output.
PARAMETER | DESCRIPTION |
---|---|
layer |
The tensor output (or input, if so specified by the anchor) of the layer(s) specified by this cut.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
TensorLike
|
The result of applying |
InputCut
¶
Bases: Cut
Special cut that selects the input(s) of a model.
Functions¶
__init__
¶
PARAMETER | DESCRIPTION |
---|---|
anchor |
Determines whether input (
TYPE:
|
accessor |
An accessor function that operates on the layer, mapping the
tensor (or list thereof) corresponding to the layer's
input/output to another tensor (or list thereof). This can be
used to, e.g., extract a particular output from a layer that
produces a sequence of outputs. If
|
OutputCut
¶
Bases: Cut
Special cut that selects the output(s) of a model.
Functions¶
__init__
¶
PARAMETER | DESCRIPTION |
---|---|
anchor |
Determines whether input (
TYPE:
|
accessor |
An accessor function that operates on the layer, mapping the
tensor (or list thereof) corresponding to the layer's
input/output to another tensor (or list thereof). This can be
used to, e.g., extract a particular output from a layer that
produces a sequence of outputs. If
|
LogitCut
¶
Bases: Cut
Special cut that selects the logit layer of a model. The logit layer must be
named 'logits'
or otherwise specified by the user to the model wrapper.
Functions¶
__init__
¶
PARAMETER | DESCRIPTION |
---|---|
anchor |
Determines whether input (
TYPE:
|
accessor |
An accessor function that operates on the layer, mapping the
tensor (or list thereof) corresponding to the layer's
input/output to another tensor (or list thereof). This can be
used to, e.g., extract a particular output from a layer that
produces a sequence of outputs. If
|
Slice
¶
Bases: object
Class representing a slice of a network. A network, $f$, can be broken into a slice, $f = g \circ h$, where $h$ can be thought of as a pre-processor that computes features, and $g$ can be thought of as a sub-model that uses the features computed by $h$.
A Slice
object represents a slice as two Cut
s, from_cut
and to_cut
,
which are the layers corresponding to the output of $h$ and $g$,
respectively.