Skip to main content

attnview

attnview é um explorador HTML para pesquisa de atenção em Transformers. A interface foi feita para notebooks: ela começa com uma pergunta (query), mostra os tokens que essa posição consulta e deixa a matriz completa como inspeção secundária.

O caso normal: uma célula de notebook

pip install -U attnview
import attnview

# attention: [n_heads, query_length, key_length]
attnview.display(attention, tokens=tokens)

O resultado é um relatório interativo dentro do notebook. Você pode trocar camada, head e query; procurar um token; ver os maiores destinos; ordenar todos os pesos; e abrir a matriz exata quando precisar conferir um detalhe.

Prompts longos

O relatório não tenta colocar todos os tokens em uma linha. Ele mostra uma janela ao redor da query selecionada, com um campo de busca para saltar diretamente para qualquer posição. Nenhum valor é descartado: a tabela e a matriz completa ficam disponíveis abaixo.

TransformerLens

Passe o ActivationCache retornado por model.run_with_cache(...). O adaptador procura automaticamente os padrões ("pattern", layer) e reúne todas as camadas em um único relatório.

import attnview

logits, cache = model.run_with_cache(tokens)
view = attnview.display_cache(cache, tokens=model.to_str_tokens(tokens))

Para salvar o mesmo relatório:

attnview.export_cache(cache, "attention-atlas.html", tokens=model.to_str_tokens(tokens))

TransformerLens não é uma dependência obrigatória. A integração aceita qualquer objeto com a mesma interface de cache; para dados sem cache, use display.

Exportar um padrão

attnview.export_html(attention, "attention.html", tokens=tokens)

Use query_tokens e key_tokens separadamente para cross-attention. Os pesos exibidos são os valores brutos fornecidos; o relatório não os normaliza e não afirma causalidade a partir deles.

Instalação para notebooks

Jupyter normalmente já instala IPython. Se necessário:

pip install 'attnview[notebook]'

Desenvolvimento

python -m pip install -e '.[dev,notebook]'
python -m pytest
python -m build
python -m twine check dist/*

Licença

MIT

Metadata

Release files for attnview 0.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 attnview 0.4.0
File Size Uploaded
attnview-0.4.0.tar.gz 13.8 kB Details

Built distribution (wheel)

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

Total release size: 26.3 kB

Release files / attnview-0.4.0.tar.gz

Download URL attnview-0.4.0.tar.gz
Size 13.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4e7cd3acf75260ee9becfbce37438c9635558371e452be832e9ba1d244b490d4
BLAKE2b-256 checksum
How to use checksums
445dfc1ca7895b8d146822f01d1107954d49498c3b7efee76087ce5246558145
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.4.0-py3-none-any.whl

Download URL attnview-0.4.0-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa3779cbe1a43dc7f5d1b40d3defccd5a11e07879b202fa3610cbd45f57313be
BLAKE2b-256 checksum
How to use checksums
8b7026d54dac48e73c7152e31493db115760adf504890bca4fa4ecc17b54f4a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release history Release notifications | RSS feed

0.5.1

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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