SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 1805.08241 · 2018

Sparse and Constrained Attention for Neural Machine Translation

arXiv · PDF · Open in the Atlas

Code that ran

11 of 11 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 11 have no contract verdict; 0 failures of our instrument; 0 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.08241.json · badge: /api/ran/1805.08241.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
Unbabel/sparse_constrained_attention community (classifier label)
classifier basis not recorded on the link
11 ran · 0 no recorded run
FunctionStatusWhere it lives
count_repetitions Ran
ran on a synthesized input
Unbabel/sparse_constrained_attention/coverage-eval/rep_score.py
code served (permissive licence) · get_code("6f72f5575120536e")
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 list, ndim 3, 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

# The function takes:
# 1. n_gram_sentence_list: a list of lists where each inner list contains items to count
# 2. threshold: an integer threshold for filtering

# Looking at the function body:
# - It iterates over n_gram_sentence_list
# - For each line, it calls Counter(line) which counts occurrences of items
# - It filters items where count v > threshold
# - Items can be any hashable type (the code converts them to tuples of (k, v))

# Create a small example with n-grams as strings or tuples
n_gram_sentence_list = [
    ['the', 'the', 'cat', 'sat'],  # 'the' appears 2 times
    ['a', 'a', 'a', 'dog'],  # 'a' appears 3 times
]

threshold = 1

ARGS = {
    'n_gram_sentence_list': n_gram_sentence_list,
    'threshold': threshold,
}
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 list, ndim 3, 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
create_fertility_dictionary Ran
ran on a synthesized input
Unbabel/sparse_constrained_attention/generate_fertilities.py
code served (permissive licence) · get_code("b9ea7b997195665c")
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 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 tempfile
import os

# Create temporary files for source and alignment data
source_file = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.txt')
align_file = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.txt')

# Write sample source sentences (space-separated words)
source_file.write("the cat sat on the mat\n")
source_file.write("a dog ran in the park\n")
source_file.close()

# Write sample alignment pairs (format: source_idx-target_idx space-separated)
align_file.write("0-0 1-1 2-2 3-3 4-4 5-5\n")
align_file.write("0-0 1-1 2-2 3-3 4-4 5-5\n")
align_file.close()

ARGS = {
    'source': source_file.name,
    'align': align_file.name,
}
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 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
create_ngram_sentence_list Ran
ran on a synthesized input
Unbabel/sparse_constrained_attention/coverage-eval/rep_score.py
code served (permissive licence) · get_code("775e3fffe173e4c5")
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 list. 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 numpy as np

# sentence_list: a list of sentences, where each sentence is a list of tokens
# n_grams: an integer specifying the n-gram size

sentence_list = [
    ['the', 'quick', 'brown', 'fox'],
    ['jumps', 'over', 'lazy', 'dog', 'today']
]

n_grams = 2

ARGS = {
    'sentence_list': sentence_list,
    'n_grams': n_grams
}
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 list — a list 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
get_segments Ran
ran on a synthesized input
Unbabel/sparse_constrained_attention/aer/postprocess_attention_bpe.py
code served (permissive licence) · get_code("883808c0a4cdfcfb")
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 torch

torch.manual_seed(0)

# Analyze the function: get_segments takes a 'sentence' parameter
# The function calls sentence.split(' ') which means it expects a string
# It iterates through words and checks if word[-2:] != '@@'
# This is a function that segments words based on BPE-style @@ markers

# Create a valid sentence with some words marked with @@ for subword tokenization
sentence = "hello@@ world@@ foo bar"

ARGS = {
    "sentence": sentence
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — 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
get_train_order Ran
ran on a synthesized input
Unbabel/sparse_constrained_attention/fertility/utils.py
code served (permissive licence) · get_code("fc25511b9fbfb2ea")
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 list, ndim 2, dtype family int; 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

torch.manual_seed(0)

# The function takes training_data (list of sequences) and batch_size (int)
# It iterates through training_data calling len(sent) on each element
# So training_data should be a list of sequences (strings, lists, or any object with __len__)

training_data = [
    "hello",
    "hello",
    "world",
    "world",
    "world",
    "a",
    "ab",
    "ab",
    "abc"
]

batch_size = 3

ARGS = {
    "training_data": training_data,
    "batch_size": batch_size
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 2, dtype family int — 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
list_of_indeces Ran
ran on a synthesized input
Unbabel/sparse_constrained_attention/coverage-eval/drop_score.py
code served (permissive licence) · get_code("6b5b0e687ba650c7")
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 list. 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 tempfile
import os

# Create a temporary .align file with test data
temp_dir = tempfile.mkdtemp()
align_file_path = os.path.join(temp_dir, "test.align")

# Write sample alignment data
# Format: source_index-target_index source_index-target_index ...
with open(align_file_path, 'w') as f:
    f.write("# Header comment\n")
    f.write("<metadata>\n")
    f.write("0-0 1-1 2-2\n")
    f.write("0-1 1-0 2-3\n")
    f.write("1-0 2-1\n")

ARGS = {
    "path": align_file_path,
    "index": 0
}
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 list — a list 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
load_sentences Ran
ran on a synthesized input
Unbabel/sparse_constrained_attention/aer/postprocess_attention_bpe.py
code served (permissive licence) · get_code("ee28c141250a7e04")
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 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 tempfile
import os

# Create a temporary file with some sample sentences
temp_file = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.txt')
temp_file.write("Hello world\n")
temp_file.write("This is a test sentence\n")
temp_file.write("Another line here\n")
temp_file.close()

file_path = temp_file.name

ARGS = {
    'file_path': file_path
}
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 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
n_gram_score Ran
ran on a synthesized input
Unbabel/sparse_constrained_attention/coverage-eval/rep_score.py
code served (permissive licence) · get_code("2a63cefd985e399b")
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 list, ndim 1, dtype family int; 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

# Analyze the function to understand what it expects:
# - n_gram_reference_repeated_list: a list of lists, where each inner list contains tuples with [0] = n-gram and [1] = count
# - n_gram_output_repeated_list: same structure as above
# Both should have the same length for zipping

# Create sample n-gram data structures
# Each element is a tuple where [0] is the n-gram (as a string or identifier) and [1] is the repetition count

reference_repeated_list_1 = [
    ("hello", 1),
    ("world", 2),
    ("test", 1)
]

reference_repeated_list_2 = [
    ("foo", 1),
    ("bar", 3)
]

output_repeated_list_1 = [
    ("hello", 1),
    ("world", 3),  # appears 3 times in output but only 2 in reference
    ("extra", 2)   # appears 2 times in output but 0 in reference
]

output_repeated_list_2 = [
    ("foo", 2),    # appears 2 times in output but 1 in reference
    ("baz", 1)
]

n_gram_reference_repeated_list = [
    reference_repeated_list_1,
    reference_repeated_list_2
]

n_gram_output_repeated_list = [
    output_repeated_list_1,
    output_repeated_list_2
]

ARGS = {
    "n_gram_reference_repeated_list": n_gram_reference_repeated_list,
    "n_gram_output_repeated_list": n_gram_output_repeated_list
}
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 list, ndim 1, dtype family int — 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
popen_io Ran
ran on a synthesized input
Unbabel/sparse_constrained_attention/force_align.py
code served (permissive licence) · get_code("20e6ab89b91679c4")
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 Popen. 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 subprocess
import threading

def popen_io(cmd):
    p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

    def consume(s):
        for _ in s:
            pass
    threading.Thread(target=consume, args=(p.stderr,)).start()
    return p

# The function takes a cmd parameter which should be a command to pass to subprocess.Popen
# A simple, harmless command that produces minimal output
ARGS = {
    "cmd": ["echo", "hello"]
}
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 Popen — a Popen output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Popen 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
read_file Ran
ran on a synthesized input
Unbabel/sparse_constrained_attention/fertility/utils.py
code served (permissive licence) · get_code("dcf92267cfb613e2")
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 list. 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 tempfile
import os

# Create a temporary file with sample training data
temp_file = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.txt')
temp_file.write("hello world\n")
temp_file.write("foo bar baz\n")
temp_file.close()

temp_file_fert = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.txt')
temp_file_fert.write("1 2 3\n")
temp_file_fert.write("4 5\n")
temp_file_fert.close()

ARGS = {
    'path': temp_file.name,
    'fert': False
}
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 list — a list 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
sortbylength Ran
ran on a synthesized input
Unbabel/sparse_constrained_attention/fertility/utils.py
code served (permissive licence) · get_code("560fe3552307f73a")
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 torch
import numpy as np

torch.manual_seed(0)

# Construct valid arguments for sortbylength function
# The function expects:
# - src: List of source sentences (each sentence is a sequence/list)
# - ferts: Optional list of fertility values corresponding to src
# - maxlen: Maximum sentence length permitted

# Create small sample data
src = [
    [1, 2, 3, 4, 5],           # sentence of length 5
    [1, 2],                      # sentence of length 2
    [1, 2, 3, 4, 5, 6, 7, 8],  # sentence of length 8
    [1],                         # sentence of length 1
]

ferts = [
    [0.8, 0.9, 1.0, 0.7, 0.6],
    [0.9, 0.8],
    [1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3],
    [0.5],
]

maxlen = 10000

ARGS = {
    "src": src,
    "ferts": ferts,
    "maxlen": maxlen,
}
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 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

Also present in other papers' code

Of 11 samples lifted from this paper's linked repositories, 11 carry a function identity and 0 do not. Of the 11 distinct functions with an identity, 1 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 1 later) and 10 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
popen_io 1 other paper
1 later
2109.10197 (2021-09)
One Source, Two Targets: Challenges and Rewards of Dual Decoding

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

In NMT, words are sometimes dropped from the source or generated repeatedly in the translation. We explore novel strategies to address the coverage problem that change only the attention transformation. Our approach allocates fertilities to source words, used to bound the attention each word can receive. We experiment with various sparse and constrained attention transformations and propose a new one, constrained sparsemax, shown to be differentiable and sparse. Empirical evaluation is provided in three languages pairs.

For agents

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

get_harvested_code_for_paper("1805.08241")
get_code_for_paper("1805.08241")
have("1805.08241")

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

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

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

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

Connect an agent — have() is free.