Fannar¶
Representation spaces of trained models from Gram matrices of several sources: one positive-definite kernel per source of information, admissible transformations, Hadamard composition, and the geometry and spectral energy of the resulting matrix.
Fannar is the name of the method, and this library is its implementation. Both are described in the paper Building Spaces via Similarity Tensors in Reproducing Kernel Hilbert Spaces: A Mechanistic Interpretability Method.
pip install fannar # core: numpy + matplotlib
pip install "fannar[all]" # + PyTorch, scikit-learn and pandas
The idea in one line¶
\(K_l\) is the raw Gram matrix of source \(l\) (from a kernel, or one you supply), \(T_l\) the component transform, \(\circ\) the Hadamard product and \(T\) the final transform. By the Schur product theorem, \(G\) is positive semidefinite for any such choice, so it defines a geometry (distances, neighbourhoods, level sets) and a spectral decomposition of energy. Everything Fannar reports is read from \(G\).
The library keeps apart, as the paper does:
- the method: the construction above and the readings on \(G\)
(
KernelPipeline,GramSpace); - the instantiation: which objects, which sources, which kernels and transformations
(
TorchSources,TreeSources, or a function of yours).
What it shows¶
Note
These examples come from models trained to illustrate the method, one run each; the systematic evaluation is in the paper. More case studies, and the interpretability service, at fannar.fernandocsdm.com.
Where to go next¶
-
Quick start
Interpret a PyTorch classifier layer by layer in a dozen lines.
-
Examples
Runnable scripts for tables, trees, images and text, with the output they print.
-
By kind of data
fannar.tabular,fannar.image,fannar.textandfannar.tree: one entry point each. -
The method
Sources, kernels, admissible transforms, the Hadamard product, and why the floor matters.
-
Your own Gram matrices
Use the construction with any objects: your kernels, your transforms, your matrices.
-
API reference
Every public class and function, generated from the docstrings.
License¶
Fannar is released under the Creative Commons Attribution-NonCommercial 4.0 International License. For commercial use of the method, see the interpretability service at fannar.fernandocsdm.com.