LexFrame: Lexical Reference Frames
A toolkit for interpreting LM residual streams in their native semantics.
LexFrame reads a hidden state the way the model reads it, in the model's own vocabulary. It is model-native: the state is transported layer by layer through the model's own remaining layers, with nothing fitted to the output. It is context-aware: along the way the state attends to its prefix, for as many rounds as chosen.
Quickstart
pip install lexframe
import lexframe as lf
frame = lf.LexFrame(model, tokenizer).init(texts) # a loaded Hugging Face model and any unlabelled texts
text = "The Eiffel Tower is located in the city of"
v = frame.view(text, k=5)
v.tokens # read: the top 5 tokens of every layer at every position
v.first_layer(" Paris") # the first layer where " Paris" tops the reading
frame.attr(text) # attribute: each layer's contribution to the prediction
c = frame.view(text, layers=16)
frame.view(c.steer({" Paris": -4, " London": 4})).tokens # steer: move layer 16 from Paris toward London
docs/USAGE.md lists every command, 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 reading and where the state sits among the lexical bases, layer by layer. To try LexFrame without installing anything, open the quickstart in Colab.
Mechanism
Lenses such as the logit lens and the Jacobian lens read every hidden state of a layer with one fixed map, whatever the context, so they share a ceiling and, everywhere except near the output, often miss what the model already knows. LexFrame instead carries each hidden state and its context through the model's remaining layers and reads the result over the vocabulary, as the model reads it. These readings can be attributed and steered at every layer. docs/MECHANISM.md explains the details.
The top token that each method reads at every second layer of Qwen3-0.6B (top) and MiniCPM5-1B (bottom), shaded by its probability, with the Jacobian lens fitted on 100 sequences. At the last position, LexFrame reads " Paris" from layer 2 in Qwen3-0.6B and from layer 0 in MiniCPM5-1B, while both lenses read it only from layer 18 or later.
Compatibility
LexFrame supports the same causal language models as 🤗 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{gu2026lexframe,
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.2.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.2.0.tar.gz | 46.5 kB | With provenance | Details for lexframe-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lexframe-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for lexframe-1.2.0-py3-none-any.whl |
Total release size: 77.1 kB
Release files / lexframe-1.2.0.tar.gz
| Download URL | lexframe-1.2.0.tar.gz |
|---|---|
| Size | 46.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1f4711d9e89d63e74b7912059ad9c6c352828e6b247784d557b541af1fa46dc8
|
|
BLAKE2b-256 checksum How to use checksums |
6860e892915c36b857cb983e64ca19eb86d131c691983b1ecb007eabe899a3f0
|
| 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 Oct 21, 2026.
Transparency logRelease files / lexframe-1.2.0-py3-none-any.whl
| Download URL | lexframe-1.2.0-py3-none-any.whl |
|---|---|
| Size | 30.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f610910ccd83562b18c0f623b2de1e29da65568ef38a95acd895305335e6dafd
|
|
BLAKE2b-256 checksum How to use checksums |
3481b7845ffe1c762dbfdab8616f7ea52cf2e8456fa6441c9226cc8a2ea5edf2
|
| 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 Oct 21, 2026.
Transparency logSecurity for lexframe 1.2.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.2.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 Oct 21, 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.