SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 1906.05714 · 2019

A Multiscale Visualization of Attention in the Transformer Model

arXiv · PDF · Open in the Atlas

Code that ran

3 of 3 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 3 failures of our instrument; 0 no recorded run), measured 2026-11-23; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/1906.05714.json · badge: /api/ran/1906.05714.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
pablowu/bertviz_backup reimplementation (classifier label)
classifier basis: classifier_2025
3 ran · 0 no recorded run
FunctionStatusWhere it lives
format_delimiters Ran
ran; our contract draft was wrong, not the code
pablowu/bertviz_backup/bertviz/attention.py
code served (permissive licence) · get_code("ff971286e5b3c45b")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

class MockTokenizer:
    def __init__(self):
        self.sep_token = "[SEP]"
        self.cls_token = "[CLS]"

tokens = ["hello", "[SEP]", "world", "[CLS]", "test"]
tokenizer = MockTokenizer()

ARGS = {
    "tokens": tokens,
    "tokenizer": tokenizer
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
format_special_chars Ran
ran; our contract draft was wrong, not the code
pablowu/bertviz_backup/bertviz/attention.py
code served (permissive licence) · get_code("11442089a6433797")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

torch.manual_seed(0)

# The function format_special_chars takes a list of tokens (strings)
# and replaces special characters with spaces
# tokens parameter: a list of strings

tokens = [
    'Ġhello',
    'world▁test',
    'Ġ▁mixed',
    'normal'
]

ARGS = {
    'tokens': tokens
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_attention Ran
ran; our contract draft was wrong, not the code
pablowu/bertviz_backup/bertviz/attention.py
code served (permissive licence) · get_code("ded9045e01073873")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
from collections import defaultdict

torch.manual_seed(0)

# Create a minimal tokenizer stand-in
class MinimalTokenizer:
    def __init__(self):
        self.cls_token = '[CLS]'
        self.sep_token = '[SEP]'
        self.vocab = {
            '[CLS]': 0,
            '[SEP]': 1,
            'hello': 2,
            'world': 3,
            'foo': 4,
            'bar': 5,
        }
    
    def tokenize(self, text):
        return text.lower().split()
    
    def convert_tokens_to_ids(self, tokens):
        return [self.vocab.get(t, 3) for t in tokens]

# Create a minimal model that returns attention data
class MinimalTransformerModel(nn.Module):
    def __init__(self, num_layers=2, num_heads=4, seq_len=6, hidden_dim=8):
        super().__init__()
        self.num_layers = num_layers
        self.num_heads = num_heads
        self.seq_len = seq_len
        self.hidden_dim = hidden_dim
    
    def forward(self, input_ids, token_type_ids=None):
        batch_size = input_ids.shape[0]
        actual_seq_len = input_ids.shape[1]
        
        # Create attention data for each layer
        attn_data_list = []
        for layer in range(self.num_layers):
            # Create attention weights: [batch, num_heads, seq_len, seq_len]
            attn_weights = torch.randn(batch_size, self.num_heads, actual_seq_len, actual_seq_len)
            attn_weights = torch.softmax(attn_weights, dim=-1)
            
            # Create queries and keys
            queries = torch.randn(batch_size, self.num_heads, actual_seq_len, self.hidden_dim)
            keys = torch.randn(batch_size, self.num_heads, actual_seq_len, self.hidden_dim)
            
            attn_data_list.append({
                'attn': attn_weights,
                'queries': queries,
                'keys': keys,
            })
        
        # Return tuple where last element is attention data list
        return (torch.randn(batch_size, actual_seq_len, 768), attn_data_list)

# Instantiate components
tokenizer = MinimalTokenizer()
model = MinimalTransformerModel(num_layers=2, num_heads=4, seq_len=6, hidden_dim=8)

# Define arguments
ARGS = {
    'model': model,
    'model_type': 'bert',
    'tokenizer': tokenizer,
    'sentence_a': 'hello world',
    'sentence_b': None,
    'include_queries_and_keys': False,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block

Also present in other papers' code

Of 3 samples lifted from this paper's linked repositories, 3 carry a function identity and 0 do not. Of the 3 distinct functions with an identity, 2 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 2 later) and 1 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
format_special_chars 1 other paper
1 later
2010.05607 (2020-10)
The elephant in the interpretability room: Why use attention as explanation when we have saliency methods?
get_attention 1 other paper
1 later
2010.05607 (2020-10)
The elephant in the interpretability room: Why use attention as explanation when we have saliency methods?

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

The Transformer is a sequence model that forgoes traditional recurrent architectures in favor of a fully attention-based approach. Besides improving performance, an advantage of using attention is that it can also help to interpret a model by showing how the model assigns weight to different input elements. However, the multi-layer, multi-head attention mechanism in the Transformer model can be difficult to decipher. To make the model more accessible, we introduce an open-source tool that visualizes attention at multiple scales, each of which provides a unique perspective on the attention mechanism. We demonstrate the tool on BERT and OpenAI GPT-2 and present three example use cases: detecting model bias, locating relevant attention heads, and linking neurons to model behavior.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("1906.05714")
get_code_for_paper("1906.05714")
have("1906.05714")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/1906.05714.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/1906.05714.svg)](https://syntology.ai/paper/1906.05714)

Connect an agent — have() is free.