explainer
Defines an explainer for mG models.
This package defines the means to generate the sub-graph of all nodes that influenced the final label of some query node.
The package contains the following classes:
MGExplainer
MGExplainer ¶
Bases: Interpreter
Generates an explanation for a mG model output.
Generates the sub-graph of nodes that are responsible for the label of a given node.
Attributes:
-
model
–The model to explain.
-
query_node
(int | None
) –The node of the input graph for which the sub-graph of relevant nodes will be generated.
-
context
–The context in which the current expression is being evaluated.
-
compiler
–The compiler for the explainer.
Parameters:
-
model
(MGModel
) –The model to explain.
Source code in libmg/explainer/explainer.py
explain ¶
explain(
query_node: int, inputs: tuple[tf.Tensor, ...], filename: str | None = None, open_browser: bool = True, engine: Literal["pyvis", "cosmo"] = "pyvis"
) -> Graph
Explain the label of a query node by generating the sub-graph of nodes that affected its value.
Using the pyvis engine, the explanation is saved in a html file in the working directory. Using the cosmograph engine, the explanation is saved as a directory, containing an index.html file, in the working directory.
Parameters:
-
query_node
(int
) –The node for which to generate the explanation.
-
inputs
(tuple[Tensor, ...]
) –The inputs for the model to explain. This is the graph to which the query node belongs.
-
filename
(str | None
, default:None
) –The name of the .html file to save in the working directory. The string
graph_
will be prepended to it. -
open_browser
(bool
, default:True
) –If true, opens the default web browser and loads up the generated .html page.
-
engine
(Literal['pyvis', 'cosmo']
, default:'pyvis'
) –The visualization engine to use. Options are
pyvis
for PyVis orcosmo
for Cosmograph.
Returns:
-
Graph
–The generated sub-graph.