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 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 carry both, 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.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].logits().softmax(-1).topk(5)                        # logits: the top 5 labels that each layer's state carries
moved = s[16, -1].steer({" Paris": -4, " London": 4})        # steer: move layer 16 from Paris toward London
moved[-1, -1].logits().softmax(-1).topk(5)                   # the model's output after the move
s[13, -1].ablate()[-1, -1].logits().softmax(-1).topk(5)      # ablate: the output without layer 12's write at the last position
b = s[16, -1].basis([" Paris", " London"])                  # basis: the labels' semantic bases at a state (None: all)

docs/USAGE.md describes every command, from logits, gradients and semantic bases to 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 and where the state sits among the semantic bases. Explore LexFrame directly with the quickstart in Colab.

Mechanism

LexFrame carries each state through the model's own remaining layers and reads it at the output. Other positions enter a layer only through its attention write, so every later write is replaced by its expectation given the state, calibrated once on unlabelled text: the logits are what the state carries by itself. The gradients are the model's own, and the semantic bases carry both: a state is the sum of the bases of the whole vocabulary weighted by its logits, and a move along a label's basis changes that label's logit by the step, to first order. Steering rotates a state at its norm so that chosen labels' logits change by given amounts and the other labels change least; ablation removes what a layer, a sublayer or one source position wrote; both run the model itself with the full context. Lenses instead read every state of a layer with one fixed map. docs/MECHANISM.md explains the details.

The top token each method reads in OLMo3-7B

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.43). 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.5.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.5.0
File Size Uploaded Provenance Actions
lexframe-1.5.0.tar.gz 67.2 kB With provenance Details for lexframe-1.5.0.tar.gz

Built distribution (wheel)

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

Total release size: 112.8 kB

Release files / lexframe-1.5.0.tar.gz

Download URL lexframe-1.5.0.tar.gz
Size 67.2 kB
Tags Source
SHA-256 checksum
How to use checksums
83b1cb2399afa7dc01f445829872120a659229d45da23fe2d9aa9137a4c137c4
BLAKE2b-256 checksum
How to use checksums
0aad192e796dadd5184b207a8d5e959fb8f4e97b1988af51b59af381956bf7d7
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 1, 2026.

Transparency log

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

Download URL lexframe-1.5.0-py3-none-any.whl
Size 45.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b2dafb680bd4956ca2dca50a1f33bc01b1849c85f3c5c63092e6c79e3c4a9e7
BLAKE2b-256 checksum
How to use checksums
4cb2cf3ba07186112fea3d5cb9d0de0f14e190076d80ffd241f64a8390fc35ee
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 1, 2026.

Transparency log

Security for lexframe 1.5.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.5.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 1, 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