LexFrame: Lexical Reference Frames
A toolkit for interpreting LM residual streams in their native semantics.
LexFrame reads every hidden state of a language model, at every layer and position, in the model's own vocabulary: its logits, its gradients, and the semantic bases that link them, for every label. It is model-native: the state runs through the model's own remaining layers, calibrated once on unlabelled text, with nothing fitted to the output. It is context-aware: it separates what the state carries by itself from what the context adds later, and steers or ablates the model's run with the full context, carrying every move forward to the output.
Quickstart
pip install lexframe
import lexframe as lf
frame = lf.Frame(model, tokenizer).calibrate(texts) # calibrate once
text = "The Eiffel Tower is located in the city of"
trace = frame.trace(text) # last token
trace.logits().softmax(-1).topk(5) # top labels per layer
state = trace[16] # layer 16
b = state.basis([" Paris", " London"]) # label bases
state.compose(state.logits()) # reconstruct the state
state.project(state.vector) # recover its logits
moved = state.steer({" Paris": -4, " London": 4}) # steer toward London
moved[-1].logits().softmax(-1).topk(5) # output after steering
trace[13].ablate()[-1].logits().softmax(-1).topk(5) # remove block 12's write
docs/USAGE.md describes every command, from logits, gradients and semantic bases to composition, projection, steering and ablation, and examples/walkthrough.py puts them to work: where SmolLM3 decides that the Eiffel Tower is in Paris, who wrote that decision, and how to change it. examples/visualize.py plots every layer's logits, basis angles, attribution, steering effects and lens comparisons. Explore LexFrame directly with the notebook.
Mechanism
LexFrame reads a hidden state by running the model's remaining layers with later attention writes replaced by calibrated conditional means and residual variation; the centered log of the average output distribution gives its logits. True gradients differentiate the actual output with the prefix context fixed. Under one fixed output-derived inner product shared across layers, logits-weighted label bases reconstruct the native state, projection recovers its logits, and the angular part preserves the true differential between hidden-state and logit tangent spaces. For finite effects, steer and ablate rerun the model with full context; steering targets output-logit changes at fixed state norm while minimizing KL change among other labels. docs/MECHANISM.md gives the definitions and derivations.
The top token each method reads at every second layer of OLMo3-7B, for "The Space Needle is located in the city of" after the document start, shaded by its probability (Jacobian lens fitted on 100 sequences). The model answers " Seattle" (0.42). At the last position, LexFrame reads " Seattle" from layer 20, the Jacobian lens from layer 22 and the logit lens from layer 24.
Compatibility
LexFrame supports any causal LM in 🤗 Transformers, including popular model families such as Llama, Qwen, Gemma, Mistral and DeepSeek, and compact or fully open ones such as Phi, OLMo and MiniCPM.
Citation
@article{gu2026lexical,
title={Lexical Reference Frames: Interpreting LM Residual Streams in Native Semantics},
author={Gu, Jian and Zhang, Hongyu and Chen, Chunyang and Aleti, Aldeida},
journal={arXiv preprint arXiv:2610.22169},
year={2026}
}
Metadata
Release files for lexframe 1.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lexframe-1.6.0.tar.gz | 2.1 MB | With provenance | Details for lexframe-1.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lexframe-1.6.0-py3-none-any.whl | Python 3 | none | any | Details for lexframe-1.6.0-py3-none-any.whl |
Total release size: 2.1 MB
Release files / lexframe-1.6.0.tar.gz
| Download URL | lexframe-1.6.0.tar.gz |
|---|---|
| Size | 2.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
14dcf47eac0dc40b02586562382640bbe5a5018137329fe1550bb9b08702ce7e
|
|
BLAKE2b-256 checksum How to use checksums |
e2d4ec8ac11627a08c5abdf78395b278e18240cb02ead5c26b930b35e0e66bb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.
Transparency logRelease files / lexframe-1.6.0-py3-none-any.whl
| Download URL | lexframe-1.6.0-py3-none-any.whl |
|---|---|
| Size | 40.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
85adb9d13f1e1a651ba9b9045889e37147db2b252cc9071be61f140e4690bb44
|
|
BLAKE2b-256 checksum How to use checksums |
128be6a30c4c4235f1cd1bc0530ac150d187f11921a637bb1ef520270bd87f0f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.
Transparency logSecurity for lexframe 1.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for lexframe-1.6.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.