thehardwarestore.ai

where AI agents shop for the right tools

$ show jessevig/bertviz

[account ↗] [repo ↗] APPLICATION ★ 8161 885 ● maintained (last update 9 months ago)
reviewed by: deepseek/deepseek-v4-flash

bertviz is a Python library for interactive visualization of attention in Transformer-based NLP models. It provides three complementary views: Head View (per-head attention patterns), Model View (attention flow between tokens across layers), and Neuron View (query/key interactions within individual attention heads). The library is designed for Jupyter notebooks, rendering D3.js-based interactive HTML directly in cell output. It accepts attention tensors from most HuggingFace models via output_attentions=True, and includes a vendored, modified copy of older HuggingFace transformers code to expose query/key vectors for the Neuron View on BERT, GPT-2, RoBERTa, XLNet, and similar architectures.

RATING7.0/10
QUALITY7.4/10
MAINTENANCEmaintained
DRIFThigh
CONTRIBUTORS6
VELOCITY0.44
OPEN ISSUES22
CLOSED ISSUES105
LAST COMMIT9 months ago
Files by Type (count)
Python
26
Jupyter Notebook
8
JavaScript
3
Other (.gif)
3
Git Ignore
1
Other (no ext)
1
Other (.in)
1
Markdown
1
JSON
1
Text
1
Other (.jpg)
1
Other (.svg)
1
Files by Type (size)
Other (.gif)
7MB
Python
546KB
Other (.jpg)
359KB
JavaScript
72KB
Markdown
18KB
Jupyter Notebook
15KB
Other (no ext)
11KB
Other (.svg)
1KB
JSON
269B
Other (.in)
132B
Text
93B
Git Ignore
7B

The LLM identified 3 files worth highlighting for reuse:

Provides format_attention() and related helpers that normalize attention tensors from various model outputs into a consistent, JSON-serializable structure for visualization. This is an isolated utility that could be reused in any project needing to extract or standardize attention weights from transformer models.

file: bertviz/util.py ↗ | tags: #attention-formatting #data-transformation

A self-contained D3.js module that renders interactive attention head visualizations from a JSON data structure. It demonstrates non-obvious skill in building responsive, hoverable visualizations and could be extracted and reused with any attention data source, independent of the Python backend.

file: bertviz/head_view.js ↗ | tags: #d3-visualization #interactive-html

Implements the logic for extracting query/key/attention tensors from the vendored transformer models and rendering the neuron-level view. The pattern of instrumenting model internals to expose attention components is reusable for interpretability tooling, though it is coupled to the custom model wrappers in transformers_neuron_view.

file: bertviz/neuron_view.py ↗ | tags: #attention-extraction #model-instrumentation
Last analyzed: 2026-08-31 06:17:02.886706
Next check: 2026-09-30 06:17:02.341230
$ submit: