attnview
attnview mostra padrões de atenção de Transformers no terminal ou em um HTML
interativo. A entrada é uma camada no formato [n_heads, query_length, key_length]:
linhas são queries; colunas são keys.
Comece aqui — dois comandos
pip install --upgrade attnview
Quer saber se está funcionando? Rode exatamente isto:
attnview demo
Você verá uma heatmap colorida no terminal. Para gerar o relatório HTML:
attnview demo --output attention.html
O comando informa o caminho do arquivo. Abra attention.html no navegador; não
há servidor para iniciar nem URL para procurar.
Use com sua atenção real
import attnview
# `attention` can be a NumPy array, a PyTorch tensor, or nested Python sequences.
# Mostra no terminal.
attnview.show(attention, tokens=["[BOS]", "The", "cat", "sat", "."])
# Cria o arquivo HTML e informa onde ele foi salvo.
attnview.show(attention, tokens=tokens, output="attention.html")
Se seus dados já estão em JSON, você também pode renderizá-los diretamente:
attnview render attention.json --tokens tokens.json
attnview render attention.json --tokens tokens.json --output attention.html
attention.json contém a matriz [heads, queries, keys]; tokens.json é uma
lista como ["[BOS]", "The", "cat", "sat", "."].
Como ler a tela
- Rows are queries: the token doing the attending.
- Columns are keys: the token being attended to.
- The selected head is rendered in the main heatmap; the HTML report also offers one-click head selection through miniature maps.
- Amber marks high attention, teal marks moderate attention, and the darkest cells are near zero. This deliberately avoids a rainbow palette that makes magnitude difficult to read.
API Python
attnview.show(
attention,
tokens=None,
query_tokens=None,
key_tokens=None,
head=0,
output=None,
top_k=3,
title="Attention Explorer",
)
Pass tokens for self-attention. For cross-attention, pass query_tokens and
key_tokens independently. With output=None (the default), show prints to
the current terminal. With an .html path, it writes a standalone HTML document
and returns its Path.
render_html(...) returns the standalone HTML string when embedding it elsewhere.
Requirements
Python 3.10+ and Rich. NumPy and PyTorch are not required: if they are installed, their arrays/tensors are accepted directly.
Development
python -m pip install -e '.[dev]'
python -m pytest
python -m build
python -m twine check dist/*
License
MIT
Metadata
Release files for attnview 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| attnview-0.1.1.tar.gz | 13.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| attnview-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.6 kB
Release files / attnview-0.1.1.tar.gz
| Download URL | attnview-0.1.1.tar.gz |
|---|---|
| Size | 13.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5a91156f3e71221ae7c6cd61522d6c269b55d8312b5ca02a1882333c5796f100
|
|
BLAKE2b-256 checksum How to use checksums |
159cc9dfc3137933977b2b38b8b08f5166288e156eb60f681d25cd58190e7eb2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|
Release files / attnview-0.1.1-py3-none-any.whl
| Download URL | attnview-0.1.1-py3-none-any.whl |
|---|---|
| Size | 12.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
31ae79997ece1f89581d1b2560a9563d7f29581b2af106a9ce832eddff644c15
|
|
BLAKE2b-256 checksum How to use checksums |
f1066f2163ec5b99f34e442e9b4bca0ce7f4fee5705b1d92c11273db5d1ee950
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|