[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-92232":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":15,"stars7d":15,"stars30d":16,"stars90d":15,"forks30d":15,"starsTrendScore":15,"compositeScore":17,"rankGlobal":9,"rankLanguage":9,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":21,"hasPages":19,"topics":22,"createdAt":9,"pushedAt":9,"updatedAt":23,"readmeContent":24,"aiSummary":25,"trendingCount":15,"starSnapshotCount":15,"syncStatus":13,"lastSyncTime":26,"discoverSource":27},92232,"jacobian-lens","anthropics\u002Fjacobian-lens","anthropics"," Companion code for the global workspace interpretability paper",null,"Python",1062,153,2,1,0,643,64.56,"Apache License 2.0",false,"main",true,[],"2026-07-22 04:02:05","# jlens — Jacobian lens\n\n> **Reference implementation.** Not maintained and not accepting contributions.\n\nCompanion code for [**Verbalizable Representations Form a Global Workspace in\nLanguage Models**](https:\u002F\u002Ftransformer-circuits.pub\u002F2026\u002Fworkspace\u002Findex.html).\n\nThe Jacobian lens reads out what an internal activation is disposed to make the\nmodel say. It linearly transports a residual-stream vector at any layer and\nposition into the final-layer basis, then decodes it with the model's own\nunembedding into a ranked list of vocabulary tokens.\n\nThe transport is the average input–output Jacobian over a text corpus:\n\n```\nlens_l(h) = unembed( J_l @ h ), J_l = E[∂h_final \u002F ∂h_l]\n```\n\nThe expectation is over prompts, source positions, and all current-and-future\ntarget positions in a generic web-text corpus; the precise estimator\n(cotangents summed over target positions, then averaged over source positions)\nis documented in the [`jlens.fitting`](jlens\u002Ffitting.py) module docstring.\n\nThis repo fits the lens on open-weights decoder transformers, applies it, and\nrenders the interactive layer × position view shown below. Examples use Qwen;\nother HuggingFace decoders adapt cleanly.\n\n![Slice visualisation: ASCII-face example](assets\u002Fslice_vis.png)\n\n*The ASCII-face example: selecting the `^` (nose) position shows the lens\nreading out \"nose\" at mid layers, although the word never appears in the\nprompt.*\n\n## Install\n\n```bash\npip install -e .\n```\n\n## Usage\n\n### Apply\n\nTo apply a pre-fitted lens:\n\n```python\nimport transformers, jlens\n\nhf = transformers.AutoModelForCausalLM.from_pretrained(\"org\u002Fmodel\").cuda()\ntok = transformers.AutoTokenizer.from_pretrained(\"org\u002Fmodel\")\nmodel = jlens.from_hf(hf, tok)\n\nlens = jlens.JacobianLens.from_pretrained(\"org\u002Flens-repo\", filename=\"model\u002Flens.pt\")\nlens_logits, model_logits, _ = lens.apply(\n    model, \"Fact: The currency used in the country shaped like a boot is\",\n    positions=[-2])\nfor layer, logits in sorted(lens_logits.items()):\n    print(layer, [tok.decode([t]) for t in logits[0].topk(5).indices])\n```\n\n### Fit\n\nTo fit a lens on your own model:\n\n```python\nlens = jlens.fit(model, prompts=my_prompts, checkpoint_path=\"out\u002Fckpt.pt\")\nlens.save(\"out\u002Fjacobian_lens.pt\")\n```\n\nThe paper's lenses use 1000 sequences of 128 tokens from a pretraining-like\ncorpus. Quality saturates quickly (§9.3); ~100 prompts is usable. This is a\nreference implementation and is not optimized; fitting time is dominated by\nthe model's own backward pass. Parallelize by running `fit()` on disjoint\nslices and combining with `JacobianLens.merge()`.\n\n## Walkthrough\n\n[`walkthrough.ipynb`](walkthrough.ipynb) is the end-to-end notebook: load a\nmodel, load (or fit) a lens, apply it at a few layers, and render a slice page\nlike the one above.\n\nReading a slice page:\n\n- Each cell shows the lens top-1 word at that (position, layer); the\n  superscript is its rank over the full vocabulary.\n- Click a cell to select a (position, layer) and pin its top-1 token; pinned\n  tokens get rank-tracking charts and a rank heatmap.\n- The bottom row (`L = n_layers − 1`) is the model's actual output.\n\n## License and data\n\nCode is released under the Apache License 2.0 — see [LICENSE](LICENSE).\n\nThe replication and lens-eval prompt sets in [`data\u002F`](data\u002F) are synthetic,\nauthored by Anthropic, and released under the same Apache License 2.0 as the\ncode. See the READMEs in [`data\u002Fexperiments\u002F`](data\u002Fexperiments\u002F) and\n[`data\u002Fevaluations\u002F`](data\u002Fevaluations\u002F) for what each set contains.\n\nThe slice-vis pages use [d3](https:\u002F\u002Fgithub.com\u002Fd3\u002Fd3) (ISC license), loaded\nfrom the jsDelivr CDN with subresource integrity or inlined into\nself-contained pages.\n\nNo model weights or text corpora are bundled; models and datasets downloaded\nat run time are subject to their own licenses.\n","Jacobian Lens 是一个用于语言模型内部表征可解释性的工具，通过计算残差流激活到最终词表 logits 的平均雅可比矩阵，将任一层任一位置的隐藏状态线性映射为可解读的词汇预测分布。其核心是基于大规模文本语料估计的输入-输出雅可比期望值，并利用模型自身的解嵌层进行解码；支持 Hugging Face 格式开源解码器模型（如 Qwen），提供交互式层×位置可视化分析。适用于语言模型机制研究、神经元行为归因、全局工作空间假说验证等基础可解释性任务。","2026-07-08 04:29:53","CREATED_QUERY"]