Skip to main content

LexFrame: Lexical Reference Frames

A toolkit for interpreting LM residual streams in their native semantics.

PyPI CI arXiv Blog

LexFrame overview

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"
s = frame.state(text)                                        # the hidden states of every layer and position
s[:, -1].decode(context=False).top(5)                        # decode: the top 5 labels that each layer's state carries
t = frame.trail(text)                                        # trail: where the prediction " Paris" comes from
t.attribute(), t.upstream()                                  # what each layer contributed, and from which positions
moved = s[16, -1].steer({" Paris": -4, " London": 4})        # steer: move layer 16 from Paris toward London
moved.decode().top(5)                                        # 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 in the frame, layer by layer. The examples need pip install "lexframe[demo]". 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. LexFrame carries each state to the output through the model's remaining layers and reads it there: with context, as the model runs; without context, with every later attention write replaced by its expectation given the state, which shows what the state carries by itself. A trail follows one prediction across layers and tells what the context brought in at each layer and from which positions. docs/MECHANISM.md explains the details.

The top token each method reads in Qwen3-0.6B

The top token each method reads in MiniCPM5-1B

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 16 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.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lexframe 1.4.0
File Size Uploaded Provenance Actions
lexframe-1.4.0.tar.gz 74.0 kB With provenance Details for lexframe-1.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lexframe 1.4.0
File Interpreter ABI Platform Actions
lexframe-1.4.0-py3-none-any.whl Python 3 none any Details for lexframe-1.4.0-py3-none-any.whl

Total release size: 126.5 kB

Release files / lexframe-1.4.0.tar.gz

Download URL lexframe-1.4.0.tar.gz
Size 74.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a068b0aff2ec4a5bc52de839ebcfe5fe6dad0ff7bb8bbd857de0a179285f6633
BLAKE2b-256 checksum
How to use checksums
e9db7e792793c72e36123a8d677c3212610c31f16430446dba95c9550049b3f5
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 28, 2026.

Transparency log

Release files / lexframe-1.4.0-py3-none-any.whl

Download URL lexframe-1.4.0-py3-none-any.whl
Size 52.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1d2833b578d30f5cb35b39ea6be3e2f418cb08101b0b2e31f7dce50db0be2686
BLAKE2b-256 checksum
How to use checksums
78eed9fe105f354e1ddcf781a67b0a43aeaac2a401c13a0f21d6bd44d5e0fdae
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 28, 2026.

Transparency log

Security for lexframe 1.4.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.

Select from 2 files

Attestation for lexframe-1.4.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 28, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page