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 runs through the model's own remaining layers, with nothing fitted to the output. It is context-aware: it separates what the state carries by itself from what the context adds later, layer by layer and position by position.
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 that every state carries
v.first_layer(" Paris") # the first layer where " Paris" tops the reading
frame.ledger(text).sources # account: what each layer took from each position
frame.attr(text) # attribute: each layer's contribution to the prediction
c = frame.view(text, layers=16)
moved = c.steer({" Paris": -4, " London": 4}) # steer: move layer 16 from Paris toward London
frame.view(moved, frame="native").tokens # the model's output after the move
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 state of a layer with one fixed map, whatever its context. LexFrame instead runs each state through the model's remaining layers: the closure reading shows what the state carries by itself, the ledger what the context adds after each layer and from which positions, and the native frame gives each token a readout and a basis for attribution and steering. In the closure, every attention write after the state's layer is replaced by its calibrated prediction plus Gaussian noise, so the reading depends on the state alone and becomes the model's own output at the last layer. The ledger adds up exactly to the gap between a reading and the output. 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 14 in MiniCPM5-1B, while both lenses read it only from layer 18 or later; in Qwen3-0.6B all three read it from layer 22.
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.3.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.3.0.tar.gz | 56.9 kB | With provenance | Details for lexframe-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lexframe-1.3.0-py3-none-any.whl | Python 3 | none | any | Details for lexframe-1.3.0-py3-none-any.whl |
Total release size: 94.7 kB
Release files / lexframe-1.3.0.tar.gz
| Download URL | lexframe-1.3.0.tar.gz |
|---|---|
| Size | 56.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c3a203794d6322bb998cbfd580aaf7b3dba0da3045222845c38eca3d5e5d9cd
|
|
BLAKE2b-256 checksum How to use checksums |
f929e302a71ea18f7d0193980c1acb82fc7bb3a136d5ca96e3ed643cddb9e937
|
| 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 24, 2026.
Transparency logRelease files / lexframe-1.3.0-py3-none-any.whl
| Download URL | lexframe-1.3.0-py3-none-any.whl |
|---|---|
| Size | 37.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9ccdae8e8f7bedad9e79b1a7fad00776f4ed2c46320fab40f81e43a70cc39f5e
|
|
BLAKE2b-256 checksum How to use checksums |
03ee2b496ef9fffcd4f798b190859a9cc503c36c83a42739afae8d0985644337
|
| 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 24, 2026.
Transparency logSecurity for lexframe 1.3.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.3.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 24, 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.