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 a chosen number of rounds of attention.
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.
Mechanism
Lenses such as the logit lens and the Jacobian lens read every hidden state of a layer through one fixed frame, so they share a ceiling, and in middle layers they often miss what the model already knows. A frame instead transports a hidden state through the model's own remaining layers, with the context the state attends to, and reads the result in lexical semantics, over the model's own vocabulary. In this frame, predictions can be read, attributed and steered at every layer. docs/MECHANISM.md explains the details, and the blog post explains why this frame matters.
Compatibility
LexFrame supports the same causal language models as 🤗 Transformers, including popular model families such as Llama, Qwen, Gemma, Mistral and DeepSeek.
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.1.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.1.0.tar.gz | 35.4 kB | With provenance | Details for lexframe-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lexframe-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for lexframe-1.1.0-py3-none-any.whl |
Total release size: 59.9 kB
Release files / lexframe-1.1.0.tar.gz
| Download URL | lexframe-1.1.0.tar.gz |
|---|---|
| Size | 35.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2aff3e6a6c58354ac645ffe25b68b5abc630753d0e50a04527f428801ab7d6ff
|
|
BLAKE2b-256 checksum How to use checksums |
ac559d165e686b1b58a02b0edd7756a71f59e74ada9dde41913269069f4c58cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 19, 2026.
Transparency logRelease files / lexframe-1.1.0-py3-none-any.whl
| Download URL | lexframe-1.1.0-py3-none-any.whl |
|---|---|
| Size | 24.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6f71aaea89d9e24a09037a49187fda588a0603d6fdd8c8e5d30146c5841d7bef
|
|
BLAKE2b-256 checksum How to use checksums |
4b0e8df8c9d7c8ba235b88a21a5ee086fc24ecb25a6ec8ed35348219a4c3e3e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 19, 2026.
Transparency logSecurity for lexframe 1.1.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.1.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 19, 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.