SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2212.02437 · 2022

In-context Examples Selection for Machine Translation

arXiv · PDF · Open in the Atlas

Code that ran

9 of 9 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; 1 honoured the contract we drafted, 0 violated it and 6 have no contract verdict; 2 failures of our instrument; 0 no recorded run), measured 2026-11-21; 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/2212.02437.json · badge: /api/ran/2212.02437.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
sweta20/incontextmt canonical (classifier label)
classifier basis: classifier_2025
2 ran · 0 no recorded run
armelrandy/icl-mt community (classifier label)
classifier basis not recorded on the link
7 ran · 0 no recorded run
FunctionStatusWhere it lives
average_pool Ran
ran on a synthesized input
armelrandy/icl-mt/miscellaneous/embedding.py
code served (permissive licence) · get_code("4c1e8ffec89c5351")
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 Tensor, 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 torch

torch.manual_seed(0)

# Construct tensors for average_pool
# last_hidden_states: shape (batch_size, sequence_length, hidden_dim)
# attention_mask: shape (batch_size, sequence_length) with 0s and 1s

batch_size = 2
sequence_length = 3
hidden_dim = 4

last_hidden_states = torch.randn(batch_size, sequence_length, hidden_dim)
attention_mask = torch.tensor([
    [1, 1, 0],
    [1, 1, 1]
], dtype=torch.long)

ARGS = {
    "last_hidden_states": last_hidden_states,
    "attention_mask": attention_mask,
}
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 Tensor, 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
get_ngram_overlap_count Ran
ran on a synthesized input
armelrandy/icl-mt/create_recall_set_selection.py
code served (permissive licence) · get_code("81e0cf4e48cd09c5")
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 float, ndim 0, dtype family float, 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 math

max_ngram_order = 4

def my_log(num: float) -> float:
    if num == 0.0:
        return -9999999999
    return math.log(num)

def _compute_score_from_stats(correct, total, effective_order=True):
    scores = [0.0 for x in range(max_ngram_order)]
    smooth_mteval = 1.0
    eff_order = max_ngram_order
    if not any(correct):
        return 0.0
    for n in range(1, len(scores) + 1):
        if total[n - 1] == 0:
            break
        if effective_order:
            eff_order = n
        if correct[n - 1] == 0:
            smooth_mteval *= 2
            scores[n - 1] = 100.0 / (smooth_mteval * total[n - 1])
        else:
            scores[n - 1] = 100.0 * correct[n - 1] / total[n - 1]
    score = math.exp(sum([my_log(p) for p in scores[:eff_order]]) / eff_order)
    return score

def get_ngram_overlap_count(ref_ngrams, hyp_ngrams):
    correct = [0 for i in range(max_ngram_order)]
    total = correct[:]
    for hyp_ngram, hyp_count in hyp_ngrams.items():
        n = len(hyp_ngram) - 1
        total[n] += hyp_count
        if hyp_ngram in ref_ngrams:
            correct[n] += min(hyp_count, ref_ngrams[hyp_ngram])
    return _compute_score_from_stats(correct, total)

ref_ngrams = {
    ("the",): 5,
    ("cat",): 3,
    ("the", "cat"): 2,
    ("the", "cat", "sat"): 1,
    ("a", "dog"): 4,
}

hyp_ngrams = {
    ("the",): 4,
    ("cat",): 2,
    ("the", "cat"): 2,
    ("the", "cat", "sat"): 1,
    ("a", "bird"): 1,
}

ARGS = {
    "ref_ngrams": ref_ngrams,
    "hyp_ngrams": hyp_ngrams,
}
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 float, ndim 0, dtype family float, 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
get_outputs Ran
ran; our contract draft was wrong, not the code
sweta20/incontextmt/run_metrics_eval.py
pointer only (licence: NONE) · get_code("9213942ca8c46cb3")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, sweta20/incontextmt when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

get_recall_overlap_score Ran
ran on a synthesized input
armelrandy/icl-mt/create_recall_set_selection.py
code served (permissive licence) · get_code("60c3fa0b38fe859d")
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 float, ndim 0, dtype family float, 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
from collections import Counter

torch.manual_seed(0)

# The function expects hyp_ngrams and ref_ngrams to be dict-like objects
# that support:
# - & (intersection) operator
# - .values() method
# - sum() on the values

# Create sample n-gram counters (dictionaries)
# These represent counts of n-grams in hypotheses and references
hyp_ngrams = Counter({
    ('the', 'cat'): 2,
    ('sat', 'on'): 1,
    ('on', 'mat'): 1
})

ref_ngrams = Counter({
    ('the', 'cat'): 1,
    ('sat', 'on'): 1,
    ('the', 'dog'): 1
})

beta = 3.0
epsilon = 1e-16

ARGS = {
    'hyp_ngrams': hyp_ngrams,
    'ref_ngrams': ref_ngrams,
    'beta': beta,
    'epsilon': epsilon
}
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 float, ndim 0, dtype family float, 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
get_template Ran
ran on a synthesized input
armelrandy/icl-mt/templates.py
code served (permissive licence) · get_code("5c0c0ea656370837")
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 Template. 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)

ARGS = {
    'key': 5,
    'src': 'English',
    'tgt': 'French'
}
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 Template — a Template output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Template 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
hf_generate Ran
ran on a synthesized input
armelrandy/icl-mt/inference.py
code served (permissive licence) · get_code("2e5899bbe725001b")
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 torch
import torch.nn as nn
from unittest.mock import Mock, MagicMock

torch.manual_seed(0)

# Minimal tokenizer mock
class MockTokenizer:
    def __init__(self):
        self.eos_token_id = 2
        self.pad_token_id = 0
        self.padding_side = 'right'
    
    def __call__(self, texts, padding=True, return_tensors='pt'):
        # Return mock tokenized output
        batch_size = len(texts) if isinstance(texts, list) else 1
        seq_len = 5
        return Mock(
            input_ids=torch.randint(1, 100, (batch_size, seq_len)),
            attention_mask=torch.ones((batch_size, seq_len), dtype=torch.long)
        )
    
    def batch_decode(self, token_ids):
        # Return mock decoded strings
        return [f"decoded_{i}" for i in range(token_ids.shape[0])]
    
    def decode(self, token_ids, skip_special_tokens=False):
        return f"decoded_output_{token_ids.sum().item()}"

# Minimal model mock
class MockModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(10, 10)
    
    def generate(self, input_ids, max_new_tokens=None, temperature=None, top_p=None,
                 num_beams=None, repetition_penalty=None, eos_token_id=None,
                 pad_token_id=None, stopping_criteria=None, do_sample=None,
                 num_return_sequences=None, forced_bos_token_id=None):
        batch_size = input_ids.shape[0]
        seq_len = input_ids.shape[1] + 3
        return torch.randint(1, 100, (batch_size, seq_len))

# Minimal accelerator mock
class MockAccelerator:
    def __init__(self):
        self.num_processes = 1
    
    def free_memory(self):
        pass
    
    def prepare(self, dataloader):
        return dataloader
    
    def pad_across_processes(self, tensor, dim=1, pad_index=0, pad_first=False):
        return tensor
    
    def gather(self, tensor):
        return tensor

tokenizer = MockTokenizer()
model = MockModel()
accelerator = MockAccelerator()

ARGS = {
    'accelerator': accelerator,
    'model': model,
    'tokenizer': tokenizer,
    'prompts': ['def hello(): return "world"', 'def add(x, y): return x + y'],
    'max_new_tokens': 50,
    'temperature': 0.7,
    'top_p': 0.9,
    'stop_words': ['\ndef', '\nclass'],
    'num_beams': 1,
    'repetition_penalty': 1.0,
    'num_return_sequences': 1,
    'do_sample': True,
    'forced_bos_token_id': None
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, tqdm, transformers — 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
my_log Ran
ran, honoured the contract we drafted
armelrandy/icl-mt/create_recall_set_selection.py
code served (permissive licence) · get_code("e4996a7942440bb5")
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 float, ndim 0, dtype family float, 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 math

def my_log(num: float) -> float:
    if num == 0.0:
        return -9999999999
    return math.log(num)

ARGS = {
    "num": 2.718281828
}
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 float, ndim 0, dtype family float, 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
read_file Ran
ran; our contract draft was wrong, not the code
sweta20/incontextmt/run_metrics_eval.py
pointer only (licence: NONE) · get_code("c211341220630f0a")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, sweta20/incontextmt when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

remove_emojis Ran
ran on a synthesized input
armelrandy/icl-mt/histogram.py
code served (permissive licence) · get_code("88bb170e90013b2a")
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 re

def remove_emojis(text):
    emoji_pattern = re.compile('[😀-🙏🌀-🗿🚀-\U0001f6ff🜀-🝿🞀-\U0001f7ff🠀-\U0001f8ff🤀-🧿🨀-\U0001fa6f🩰-\U0001faff✂-➰Ⓜ-🉑]+', flags=re.UNICODE)
    return emoji_pattern.sub('', text)

ARGS = {
    'text': 'Hello 😀 World 🚀 This is a test 🙏'
}
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 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

Also present in other papers' code

Of 9 samples lifted from this paper's linked repositories, 9 carry a function identity and 0 do not. Of the 9 distinct functions with an identity, 2 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 1 the same month, 1 later) and 7 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
my_log 2 other papers
1 dated earlier, 1 later
1804.08771 (2018-04)
A Call for Clarity in Reporting BLEU Scores
2605.31545 (2026-05)
Preference-Aware Rubric Learning for Personalized Evaluation PREFERENCE-AWARE RUBRIC LEARNING FOR PERSON-ALIZED EVALUATION
average_pool 1 other paper
1 the same month
2212.10560 (2022-12)
SELF-INSTRUCT: Aligning Language Models with Self-Generated Instructions

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

Repositories linked to this paper

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

Abstract

Large-scale generative models show an impressive ability to perform a wide range of Natural Language Processing (NLP) tasks using in-context learning, where a few examples are used to describe a task to the model. For Machine Translation (MT), these examples are typically randomly sampled from the development dataset with a similar distribution as the evaluation set. However, it is unclear how the choice of these in-context examples and their ordering impacts the output translation quality. In this work, we aim to understand the properties of good in-context examples for MT in both in-domain and out-of-domain settings. We show that the translation quality and the domain of the in-context examples matter and that 1-shot noisy unrelated example can have a catastrophic impact on output quality. While concatenating multiple random examples reduces the effect of noise, a single good prompt optimized to maximize translation quality on the development dataset can elicit learned information from the pre-trained language model. Adding similar examples based on an n-gram overlap with the test source significantly and consistently improves the translation quality of the outputs, outperforming a strong kNN-MT baseline in 2 out of 4 out-of-domain datasets.

For agents

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

get_harvested_code_for_paper("2212.02437")
get_code_for_paper("2212.02437")
have("2212.02437")

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

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

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

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

Connect an agent — have() is free.