visualization

class gdeep.visualization.Compactification(neural_net: Module, precision: float = 0.4, n_features: int | None = None, n_samples: int = 1000, epsilon: float = 0.05, n_epochs: int = 5000, boundary_tuple: List[Tuple[float, float]] | None = None)

Class to compactify the feature space and get better topological insights.

Args:
precision :

A tolerance on how close to the decision boundary the points shall be.

n_features :

number of input features

n_samples:

number of samples per chart

n_epochs:

number of epochs needed to push points to the decision boundary

boundary_tuple :

list of pairs (left,right). This list defines the boundaries in each coordinates

neural_net :

the trained network of which to compute the boundary

create_final_distance_matrix() Tuple[ndarray, List]

This is the main function to call without arguments

plot_chart(i: int) Figure

This functions plots the points in each chart.

Args:
i :

the chart index, from -1 to n_features

class gdeep.visualization.Visualiser(pipe: Trainer)

This class is the bridge to send to the tensorboard the required plots. It converts plots and images of different kinds to tensors

Args:
pipe :

the Trainer instance to get info from

Examples:

from gdeep.visualization import Visualiser
# you must have an initialized `trainer`
vs = Visualiser(trainer)
vs.plot_data_model()
plot_3d_dataset(n_pts: int = 100) None

This function has no arguments: its purpose is to store data to the tensorboard for visualization. Note that we are expecting the dataset item to be of type Tuple[Tensor, Tensor]

Args:
n_pts:

number of points to display

plot_activations(batch: List[List[Tensor] | Tensor] | None = None) None

Plot PCA of the activations of all layers of the self.model.

Args:
batch:

this should be an input batch for the model

plot_attribution(interpreter: Interpreter, **kwargs) Tuple[Figure, Figure]

this method generically plots the attribution of the interpreter

Args:
interpreter :

this is a gdeep.analysis.interpretability initialized Interpreter class

kwargs:

keywords arguments for the plot (visualize_image_attr of captum)

Returns:
matplotlib.figure, matplotlib.figure

they correspond respectively to the datum and attribution

plot_attributions_persistence_diagrams(interpreter: Interpreter, **kwargs) Figure

this method allows the plot, on top of the persistence diagram, of the attribution values. For example, this would be the method to call when you run saliency maps on the persistence diagrams. Note that all homology dimensions are plot together

Args:
interpreter :

this is a gdeep.analysis.interpretability initialized Interpreter class

kwargs:

keywords arguments for the plot (matplotlib.pyplot)

Returns:

matplotlib.figure.Figure

plot_betti_curves_layers(homology_dimensions: List[int] | None = None, batch: Tensor | None = None, **kwargs) None
Args:
homology_dimensions :

A list of homology dimensions, e.g. [0, 1, ...]

batch :

the selected batch of data to compute the activations on. By defaults, this method takes the first batch of elements

kwargs:

optional arguments for the creation of persistence diagrams

plot_betti_numbers_layers(homology_dimensions: List[int] | None = None, filtration_value: float = 1.0, batch: Tensor | None = None, **kwargs) Figure
Args:
homology_dimensions :

A list of homology dimensions, e.g. [0, 1, ...]

filtration_value:

the filtration value you want to threshold the filtration at

batch :

the selected batch of data to compute the activations on. By defaults, this method takes the first batch of elements

kwargs:

optional arguments for the creation of persistence diagrams

plot_betti_surface_layers(homology_dimensions: List[int] | None = None, batch: Tensor | None = None, **kwargs) List[Any]
Args:
homology_dimensions :

A list of homology dimensions, e.g. [0, 1, ...]

batch :

the selected batch of data to compute the activations on. By defaults, this method takes the first batch of elements

kwargs:

optional arguments for the creation of persistence diagrams

plot_decision_boundary(compact: bool = False, n_epochs: int = 100, precision: float = 0.1)

Plot the decision boundary as the intrinsic hypersurface defined by self.loss_fn == 0.5 in the case of 2 classes. The method also works for an arbitrary number of classes. Note that we are expecting a model whose forward function has only one tensor as input (and not multiple arguments).

Args:
compact:

if plotting the compactified version of the boundary

n_epochs:

number of training cycles to find the decision boundary

precision:

parameter to filter the spurious data that are close to te decision boundary, but not close enough

plot_feature_importance(interpreter: Interpreter)

This method allows to plot the results of an Interpreter for tabular data.

Args:
interpreter :

this is a gdeep.analysis.interpretability initialized Interpreter class

Returns:

matplotlib.figure

plot_interactive_model() None

This function has no arguments: its purpose is to store the model to tensorboard for an interactive visualization.

plot_interpreter_image(interpreter: Interpreter)

This method allows to plot the results of an Interpreter for image data.

Args:
interpreter:

this is a gdeep.analysis.interpretability initialized Interpreter class

Returns:

matplotlib.figure

plot_interpreter_text(interpreter: Interpreter)

This method allows to plot the results of an Interpreter for text data.

Args:
interpreter :

this is a gdeep.analysis.interpretability initialized Interpreter class

Returns:

matplotlib.figure

plot_persistence_diagrams(batch: List[Tensor] | None = None, homology_dimensions: List[int] | None = None, **kwargs) None

Plot a persistence diagrams of the activations

Args:
batch:

a batch of data, in the shape of (datum, label)

homology_dimensions:

a list of the homology dimensions, like [0, 1]

kwargs:

arguments for the persistence_diagrams_of_activations

plot_self_attention(attention_tensor: List[Tensor], tokens_x: List[str] | None = None, tokens_y: List[str] | None = None, **kwargs) Figure

This functions plots the self-attention layer of a transformer.

Args:
attention_tensor:

list of the self-attention tensors (i.e. the tensors corresponding to the activations, given an input

tokens_x:

The string tokens to be displayed along the x axis of the plot

tokens_y:

The string tokens to be displayed along the y axis of the plot

Returns:
Figure:

matplotlib pyplot

gdeep.visualization.persistence_diagrams_of_activations(activations_list: List[Tensor], homology_dimensions: List[int] | None = None, k: int = 5, mode: str = 'VR', max_edge_length: int = 10) List[Any]

Returns list of persistence diagrams of the activations of all layers of type layer_types

Args:
activations_list:

list of activation tensors for each layer

homology_dimensions :

list of homology dimensions. Defaults to [0, 1].

k :

number of neighbors parameter of the k-NN distance. If k <= 0, then the list of activations is considered as a point cloud and no knn distance is computed

mode :

choose the filtration (‘VR’ or ‘alpha’) to compute persistence default to ‘VR’.

max_edge_length :

maximum edge length of the simplices forming the complex

Returns:
(list):

list of persistence diagrams of activations of the different layers

gdeep.visualization.plotly2tensor(fig) Tensor

convert Plotly fig to an array.

Args:
fig (plotly GraphicObject):

figure to convert to tensor

Returns:
Tensor:

the tensor discretisation of the figure