SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2109.09991 · EMNLP · 2021

Learning Kernel-Smoothed Machine Translation with Retrieved Examples

Lei Li, Shujian Huang, Mingxuan Wang, Shanbo Cheng, Jun Cao, Qingnan Jiang

arXiv · PDF · Open in the Atlas

Code that ran

5 of 10 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (1 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 4 have no contract verdict; 1 failure of our instrument; 5 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/2109.09991.json · badge: /api/ran/2109.09991.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
jiangqn/kster canonical (classifier label)
classifier basis: census
3 ran · 0 no recorded run
jiangqn/KSTER community
Papers with Code archive
2 ran · 5 no recorded run
FunctionStatusWhere it lives
FaissIndex Ran
ran on a synthesized input · constructed an object; no result was computed
jiangqn/KSTER/joeynmt/combiners.py
code served (permissive licence) · get_code("2c10660b4d784c0d")
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 an instance of its own class, FaissIndex: the run constructed the object and did not call it, so no result was computed. 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 numpy as np
import tempfile
import os

# Create temporary directory for embeddings files
temp_dir = tempfile.mkdtemp()

# Create small embeddings arrays for training and adding
np.random.seed(0)
dimension = 128
training_total_samples = 1000
add_total_samples = 500

training_embeddings = np.random.randn(training_total_samples, dimension).astype(np.float32)
add_embeddings = np.random.randn(add_total_samples, dimension).astype(np.float32)

training_path = os.path.join(temp_dir, 'training_embeddings.npy')
add_path = os.path.join(temp_dir, 'add_embeddings.npy')

np.save(training_path, training_embeddings)
np.save(add_path, add_embeddings)

# Create a trained index for testing load functionality
from faiss import index_factory, METRIC_L2, write_index
test_index = index_factory(dimension, 'IVF256,PQ32', METRIC_L2)
test_index.train(training_embeddings)
test_index.add(add_embeddings)
index_path = os.path.join(temp_dir, 'test_index.faiss')
write_index(test_index, index_path)

ARGS = {
    'factory_template': 'IVF256,PQ32',
    'load_index_path': None,
    'use_gpu': False,
    'index_type': 'L2'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
faiss, numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type FaissIndex — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a FaissIndex 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
GaussianKernel Ran
ran on a synthesized input
jiangqn/KSTER/joeynmt/combiners.py
code served (permissive licence) · get_code("9cd13fd04403e663")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) 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

INIT_ARGS = {}

ARGS = {
    'distances': torch.tensor([[0.5, 1.0, 1.5], [0.2, 0.8, 2.0]], dtype=torch.float32),
    'bandwidth': 0.5,
    'token_indices': torch.tensor([[0, 2, 4], [1, 3, 2]], dtype=torch.long),
    'vocab_size': 6
}

METHOD = 'compute_example_based_distribution'

if __name__ == '__main__':
    from __main__ import Kernel, GaussianKernel
    
    kernel = GaussianKernel(**INIT_ARGS)
    result = getattr(kernel, METHOD)(**ARGS)
    print("Distribution shape:", result[0].shape)
    print("Sparse distribution shape:", result[1].shape)
    print("Distribution:\n", result[0])
    print("Sparse distribution:\n", result[1])
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
__main__, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
build_scheduler Ran
ran; our contract draft was wrong, not the code
jiangqn/kster/joeynmt/builders.py
code served (permissive licence) · get_code("ecf1add161d46a9b")
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.

import torch
import torch.nn as nn
from torch.optim import Adam

torch.manual_seed(0)

# Create a minimal model for the optimizer
class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, x):
        return self.linear(x)

model = SimpleModel()
optimizer = Adam(model.parameters(), lr=0.001)

# Create config dictionaries for different scheduler modes
config_plateau = {
    "scheduler": "plateau",
    "learning_rate_min": 1e-6,
    "lr_decay": 0.5,
    "patience": 5
}

config_decaying = {
    "scheduler": "decaying",
    "learning_rate": 0.001,
    "learning_rate_decay": 0.5,
    "decay_steps": 1000
}

config_exponential = {
    "scheduler": "exponential",
    "learning_rate": 0.001,
    "learning_rate_decay": 0.99
}

config_noam = {
    "scheduler": "noam",
    "learning_rate": 1.0,
    "hidden_size": 512,
    "warmup_steps": 4000
}

config_warmupexponentialdecay = {
    "scheduler": "warmupexponentialdecay",
    "peak_learning_rate": 0.001,
    "learning_rate_decay_length": 10000,
    "learning_rate_decay": 0.5,
    "warmup_steps": 4000,
    "learning_rate_min": 1e-5
}

# Test with plateau mode
ARGS = {
    "config": config_plateau,
    "optimizer": optimizer,
    "scheduler_mode": "plateau",
    "hidden_size": 512
}
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, 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
generate_id Ran
ran on a synthesized input
jiangqn/kster/joeynmt/build_database.py
code served (permissive licence) · get_code("2b08b87924c54731")
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 str. 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
from hashlib import md5

torch.manual_seed(0)

# The function takes a single parameter 'sequence' which is a string
# It encodes the string and generates an MD5 hexdigest from it
# We need to provide a simple string value

ARGS = {
    "sequence": "hello_world"
}
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 str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
token_batch_size_fn Ran
ran on a synthesized input
jiangqn/kster/joeynmt/data.py
code served (permissive licence) · get_code("cb329af957271d21")
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

torch.manual_seed(0)

class Batch:
    def __init__(self, src, trg=None):
        self.src = src
        self.trg = trg

# Create sample batches with different sequence lengths
new_batch = Batch(src=[1, 2, 3, 4, 5], trg=[10, 11, 12])
count = 1
sofar = 0

ARGS = {
    "new": new_batch,
    "count": count,
    "sofar": sofar
}
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 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
Combiner Not yet run
unverified (harvested, no recorded run)
jiangqn/KSTER/joeynmt/combiners.py
code served (permissive licence) · get_code("2519fc0edb3124c4")
How it ran

no invocation recorded.

Database Not yet run
unverified (harvested, no recorded run)
jiangqn/KSTER/joeynmt/combiners.py
code served (permissive licence) · get_code("604e698c3ad33407")
How it ran

no invocation recorded.

DynamicCombiner Not yet run
unverified (harvested, no recorded run)
jiangqn/KSTER/joeynmt/combiners.py
code served (permissive licence) · get_code("12081610491cba7c")
How it ran

no invocation recorded.

EnhancedDatabase Not yet run
unverified (harvested, no recorded run)
jiangqn/KSTER/joeynmt/combiners.py
code served (permissive licence) · get_code("922f84b50145339d")
How it ran

no invocation recorded.

Kernel Not yet run
unverified (harvested, no recorded run)
jiangqn/KSTER/joeynmt/combiners.py
code served (permissive licence) · get_code("85f94e4c607f3908")
How it ran

no invocation recorded.

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 distinct functions with an identity, 2 are also present in other papers whose code we hold (2 with at least one paper dated earlier, 0 the same month, 0 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
build_scheduler 2 other papers
2 dated earlier
1907.12484 (2019-07)
Joey NMT: A Minimalist NMT Toolkit for Novices
2106.08942 (2021-06)
Revisiting the Weaknesses of Reinforcement Learning for Neural Machine Translation
token_batch_size_fn 2 other papers
2 dated earlier
1907.12484 (2019-07)
Joey NMT: A Minimalist NMT Toolkit for Novices
2106.08942 (2021-06)
Revisiting the Weaknesses of Reinforcement Learning for Neural Machine Translation

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

How to effectively adapt neural machine translation (NMT) models according to emerging cases without retraining? Despite the great success of neural machine translation, updating the deployed models online remains a challenge. Existing non-parametric approaches that retrieve similar examples from a database to guide the translation process are promising but are prone to overfit the retrieved examples. However, non-parametric methods are prone to overfit the retrieved examples. In this work, we propose to learn Kernel-Smoothed Translation with Example Retrieval (KSTER), an effective approach to adapt neural machine translation models online. Experiments on domain adaptation and multi-domain machine translation datasets show that even without expensive retraining, KSTER is able to achieve improvement of 1.1 to 1.5 BLEU scores over the best existing online adaptation methods. The code and trained models are released at https://github.com/jiangqn/KSTER.

For agents

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

get_harvested_code_for_paper("2109.09991")
get_code_for_paper("2109.09991")
have("2109.09991")

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

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

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

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

Connect an agent — have() is free.