spectral-trust¶
spectral-trust turns a transformer's attention into graphs over the tokens and measures them: the Laplacian spectrum of every head, and the frequency content of the residual stream on those graphs, from one forward pass.

import spectral_trust as st
model = st.SpectralModel.from_pretrained("Qwen/Qwen3-0.6B")
cache = model.run_with_spectra("The cat sat on the mat because it was warm.")
print(cache["blocks.10.attn.fiedler_value"]) # one value per head
print(cache["blocks.10.graph.hfer"]) # the head-averaged graph
cache.heatmap("fiedler_value").save("fiedler.html")
Every measurement is a function of one forward pass: no labels, no probes,
no training. The library reads attention from a Hugging Face model, a
TransformerLens cache or an nnsight trace, and returns a SpectralCache
keyed like TransformerLens' ActivationCache.
- Getting started: install, load a model, read the cache.
- Concepts: graphs from attention, the two metric families, hybrid linear-attention models.
- Tutorials: quickstart, per-head analysis, TransformerLens and nnsight.
- API reference and changelog.