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.1

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.1
File Size Uploaded
attnview-0.4.1.tar.gz 14.0 kB Details

Built distribution (wheel)

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

Total release size: 26.6 kB

Release files / attnview-0.4.1.tar.gz

Download URL attnview-0.4.1.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
347c2f5522d7953d1d8b7a3a2bdf57ebb2506d9d5b8b6324736cf8d1acf4f290
BLAKE2b-256 checksum
How to use checksums
d0b22c061feafe57b69e7e1c9d06183f27773b49c8b32436f72f9bc434463801
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.1-py3-none-any.whl

Download URL attnview-0.4.1-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c125dbdbb70120e3eb21085343e729651008772eb14b0d8e59875a99fbfd4cac
BLAKE2b-256 checksum
How to use checksums
e8b5b67a886637fdb24125d223c5838df4653ab47866a58da8445081364ebc9f
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

This release

0.4.1 This release

2 release files

0.4.0

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