SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 1805.00631 · 2018

Accelerating Neural Transformer via an Average Attention Network

arXiv · PDF · Open in the Atlas

Code that ran

7 of 19 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 7 have no contract verdict; 0 failures of our instrument; 12 no recorded run), measured 2026-11-22; 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/1805.00631.json · badge: /api/ran/1805.00631.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
bzhangXMU/transformer-aan canonical (classifier label)
classifier basis: census
7 ran · 12 no recorded run
FunctionStatusWhere it lives
closest_length Ran
ran on a synthesized input
bzhangXMU/transformer-aan/code/thumt/utils/bleu.py
code served (permissive licence) · get_code("dd985e59ae3a38a4")
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, through the batch API) and returned int, ndim 0, dtype family int, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape 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 takes a candidate and references, and calls len() on them
# So they need to be objects with __len__ defined
# They can be lists, strings, tensors, or any sequence

candidate = "hello"
references = ["hi", "goodbye", "world", "testing"]

ARGS = {
    "candidate": candidate,
    "references": references
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, shape () — shape () as a later run recorded it
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
compute_batch_indices Ran
ran on a synthesized input
bzhangXMU/transformer-aan/code/thumt/utils/search_aan.py
code served (permissive licence) · get_code("6cc541726e9562c3")
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, through the batch API) and returned EagerTensor, ndim 2, dtype family int, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape 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 tensorflow as tf

# Set random seeds for reproducibility
tf.random.set_seed(0)

# Define arguments for compute_batch_indices
batch_size = 2
beam_size = 4

ARGS = {
    "batch_size": batch_size,
    "beam_size": beam_size,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
tensorflow — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type EagerTensor, ndim 2, dtype family int, shape (2, 4) — shape (2, 4) as a later run recorded it
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
compute_topk_scores_and_seq Ran
ran on a synthesized input
bzhangXMU/transformer-aan/code/thumt/utils/search_aan.py
code served (permissive licence) · get_code("90f2d69b85bf60d5")
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, through the batch API) and returned tuple. 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 tensorflow as tf
import numpy as np

# Set seeds for reproducibility
tf.random.set_seed(0)
np.random.seed(0)

# Define tensor dimensions
batch_size = 2
beam_size = 3
seq_length = 5

# Create small test tensors
sequences = tf.constant(np.random.randint(0, 100, (batch_size, beam_size, seq_length)), dtype=tf.int32)

scores = tf.constant(
    np.random.randn(batch_size, beam_size).astype(np.float32),
    dtype=tf.float32
)

scores_to_gather = tf.constant(
    np.random.randn(batch_size, beam_size).astype(np.float32),
    dtype=tf.float32
)

flags = tf.constant(
    np.random.choice([True, False], size=(batch_size, beam_size)),
    dtype=tf.bool
)

# Create decoded_states as a list of tensors
decoded_states = [
    tf.constant(np.random.randn(batch_size, beam_size, 4).astype(np.float32), dtype=tf.float32),
    tf.constant(np.random.randn(batch_size, beam_size, 6).astype(np.float32), dtype=tf.float32)
]

ARGS = {
    "sequences": sequences,
    "scores": scores,
    "scores_to_gather": scores_to_gather,
    "flags": flags,
    "beam_size": beam_size,
    "batch_size": batch_size,
    "decoded_states": decoded_states
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, tensorflow — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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
modified_precision Ran
ran on a synthesized input
bzhangXMU/transformer-aan/code/thumt/utils/bleu.py
code served (permissive licence) · get_code("9c5e87513bca1bae")
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, through the batch API) and returned tuple, 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.

from collections import Counter

def modified_precision(candidate, references, n):
    tngrams = len(candidate) + 1 - n
    counts = Counter([tuple(candidate[i:i + n]) for i in range(tngrams)])
    if len(counts) == 0:
        return (0, 0)
    max_counts = {}
    for reference in references:
        rngrams = len(reference) + 1 - n
        ngrams = [tuple(reference[i:i + n]) for i in range(rngrams)]
        ref_counts = Counter(ngrams)
        for ngram in counts:
            mcount = 0 if ngram not in max_counts else max_counts[ngram]
            rcount = 0 if ngram not in ref_counts else ref_counts[ngram]
            max_counts[ngram] = max(mcount, rcount)
    clipped_counts = {}
    for ngram, count in counts.items():
        clipped_counts[ngram] = min(count, max_counts[ngram])
    return (float(sum(clipped_counts.values())), float(sum(counts.values())))

# Setup: Create valid arguments for modified_precision
# The function expects:
# - candidate: a sequence (list) of tokens/words
# - references: a list of reference sequences
# - n: integer for n-gram size

candidate = [1, 2, 3, 2, 4, 5]
references = [
    [1, 2, 3, 4, 5],
    [1, 2, 2, 4, 5, 6],
]
n = 2

ARGS = {
    "candidate": candidate,
    "references": references,
    "n": n,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple 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
parse_args Ran
ran on a synthesized input
bzhangXMU/transformer-aan/code/trainer.py
code served (permissive licence) · get_code("69dd5f64c584f7eb")
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, through the batch API) and returned Namespace. 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 argparse

ARGS = {
    'args': [
        '--input', 'source.txt', 'target.txt',
        '--record', 'data.tfrecord',
        '--output', 'models/',
        '--vocabulary', 'vocab_src.txt', 'vocab_tgt.txt',
        '--validation', 'valid.txt',
        '--references', 'ref1.txt', 'ref2.txt',
        '--model', 'transformer',
        '--parameters', 'hidden_size=512,num_layers=6'
    ]
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Namespace — a Namespace output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Namespace 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
residual_fn Ran
ran on a synthesized input
bzhangXMU/transformer-aan/code/thumt/models/transformer.py
code served (permissive licence) · get_code("f3ce51f764fb2afc")
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, through the batch API) and returned EagerTensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape 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 tensorflow as tf
import numpy as np

# Create small tensors for x and y
# x and y should be compatible shapes for addition
x = tf.constant(np.random.randn(2, 4).astype(np.float32))
y = tf.constant(np.random.randn(2, 4).astype(np.float32))

# keep_prob parameter
keep_prob = 0.8

ARGS = {
    "x": x,
    "y": y,
    "keep_prob": keep_prob,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, tensorflow — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type EagerTensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
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
shortest_length Ran
ran on a synthesized input
bzhangXMU/transformer-aan/code/thumt/utils/bleu.py
code served (permissive licence) · get_code("531aab5936f2e596")
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, through the batch API) and returned int, ndim 0, dtype family int, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape 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 takes 'references' and iterates through it,
# calling len() on each element. So references should be a list
# of objects that have a length (strings, lists, tensors, etc.)

# Create a list of references with different lengths
references = [
    "hello",           # length 5
    [1, 2, 3],        # length 3
    "ab",             # length 2
    list(range(7))    # length 7
]

ARGS = {
    "references": references
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, shape () — shape () as a later run recorded it
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
add_timing_signal Not yet run
unverified (harvested, no recorded run)
bzhangXMU/transformer-aan/code/thumt/layers/attention.py
code served (permissive licence) · get_code("d159075513daf35b")
How it ran

no invocation recorded.

collect_params Not yet run
unverified (harvested, no recorded run)
bzhangXMU/transformer-aan/code/trainer.py
code served (permissive licence) · get_code("c55c6aba7b709f18")
How it ran

no invocation recorded.

combine_heads Not yet run
unverified (harvested, no recorded run)
bzhangXMU/transformer-aan/code/thumt/layers/attention.py
code served (permissive licence) · get_code("273d5e370a58f518")
How it ran

no invocation recorded.

get_weights Not yet run
unverified (harvested, no recorded run)
bzhangXMU/transformer-aan/code/thumt/models/transformer.py
code served (permissive licence) · get_code("1b441b0d053c905a")
How it ran

no invocation recorded.

import_params Not yet run
unverified (harvested, no recorded run)
bzhangXMU/transformer-aan/code/translator.py
code served (permissive licence) · get_code("149a90364d6911d9")
How it ran

no invocation recorded.

import_params Not yet run
unverified (harvested, no recorded run)
bzhangXMU/transformer-aan/code/trainer.py
code served (permissive licence) · get_code("ba3612d14359b1ea")
How it ran

no invocation recorded.

layer_norm Not yet run
unverified (harvested, no recorded run)
bzhangXMU/transformer-aan/code/thumt/layers/nn.py
code served (permissive licence) · get_code("788092fa1ba69066")
How it ran

no invocation recorded.

linear Not yet run
unverified (harvested, no recorded run)
bzhangXMU/transformer-aan/code/thumt/layers/nn.py
code served (permissive licence) · get_code("9676af2224c507fe")
How it ran

no invocation recorded.

log_prob_from_logits Not yet run
unverified (harvested, no recorded run)
bzhangXMU/transformer-aan/code/thumt/utils/search_aan.py
code served (permissive licence) · get_code("b4a5e930784a8355")
How it ran

no invocation recorded.

maxout Not yet run
unverified (harvested, no recorded run)
bzhangXMU/transformer-aan/code/thumt/layers/nn.py
code served (permissive licence) · get_code("52b62c3783732f3f")
How it ran

no invocation recorded.

merge_parameters Not yet run
unverified (harvested, no recorded run)
bzhangXMU/transformer-aan/code/translator.py
code served (permissive licence) · get_code("8be2667aba5e919e")
How it ran

no invocation recorded.

split_heads Not yet run
unverified (harvested, no recorded run)
bzhangXMU/transformer-aan/code/thumt/layers/attention.py
code served (permissive licence) · get_code("98b6d2c44a099591")
How it ran

no invocation recorded.

Also present in other papers' code

Of 19 samples lifted from this paper's linked repositories, 19 carry a function identity and 0 do not. Of the 19 distinct functions with an identity, 11 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 11 later) and 8 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
import_params 4 other papers
4 later
1810.03581 (2018-10)
Improving the Transformer Translation Model with Document-Level Context
1901.04112 (2019-01)
Unsupervised Neural Machine Translation with SMT as Posterior Regularization
2020.acl-main.320 (2020 (year only))
A Retrieve-and-Rewrite Initialization Method for Unsupervised Machine Translation
and 1 more not named here
add_timing_signal 2 other papers
2 later
1810.03581 (2018-10)
Improving the Transformer Translation Model with Document-Level Context
1901.04112 (2019-01)
Unsupervised Neural Machine Translation with SMT as Posterior Regularization
combine_heads 2 other papers
2 later
1810.03581 (2018-10)
Improving the Transformer Translation Model with Document-Level Context
2205.03766 (2022-05)
Scheduled Multi-task Learning for Neural Chat Translation
maxout 2 other papers
2 later
1810.03581 (2018-10)
Improving the Transformer Translation Model with Document-Level Context
2205.03766 (2022-05)
Scheduled Multi-task Learning for Neural Chat Translation
closest_length 1 other paper
1 later
1901.04112 (2019-01)
Unsupervised Neural Machine Translation with SMT as Posterior Regularization
collect_params 1 other paper
1 later
1810.03581 (2018-10)
Improving the Transformer Translation Model with Document-Level Context
import_params 1 other paper
1 later
1810.03581 (2018-10)
Improving the Transformer Translation Model with Document-Level Context
merge_parameters 1 other paper
1 later
1810.03581 (2018-10)
Improving the Transformer Translation Model with Document-Level Context
modified_precision 1 other paper
1 later
1901.04112 (2019-01)
Unsupervised Neural Machine Translation with SMT as Posterior Regularization
parse_args 1 other paper
1 later
1810.03581 (2018-10)
Improving the Transformer Translation Model with Document-Level Context
shortest_length 1 other paper
1 later
1901.04112 (2019-01)
Unsupervised Neural Machine Translation with SMT as Posterior Regularization

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

Repositories linked to this paper

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

Abstract

With parallelizable attention networks, the neural Transformer is very fast to train. However, due to the auto-regressive architecture and self-attention in the decoder, the decoding procedure becomes slow. To alleviate this issue, we propose an average attention network as an alternative to the self-attention network in the decoder of the neural Transformer. The average attention network consists of two layers, with an average layer that models dependencies on previous positions and a gating layer that is stacked over the average layer to enhance the expressiveness of the proposed attention network. We apply this network on the decoder part of the neural Transformer to replace the original target-side self-attention model. With masking tricks and dynamic programming, our model enables the neural Transformer to decode sentences over four times faster than its original version with almost no loss in training time and translation performance. We conduct a series of experiments on WMT17 translation tasks, where on 6 different language pairs, we obtain robust and consistent speed-ups in decoding.

For agents

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

get_harvested_code_for_paper("1805.00631")
get_code_for_paper("1805.00631")
have("1805.00631")

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

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

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

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

Connect an agent — have() is free.