SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2506.08607 · ICML · 2025

Sample Efficient Demonstration Selection for In-Context Learning

Sourangshu Bhattacharya, Avishek Anand, Kiran Purohit

arXiv · PDF · Open in the Atlas

Code that ran

5 of 8 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 1 has no contract verdict; 4 failures of our instrument; 3 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/2506.08607.json · badge: /api/ran/2506.08607.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
kiranpurohit/case canonical (classifier label)
classifier basis: classifier_2025
5 ran · 3 no recorded run
FunctionStatusWhere it lives
clean_ans Ran
ran; our contract draft was wrong, not the code
kiranpurohit/case/Code/LLM_experiments/CASE_Gsm8K_selection.py
code served (permissive licence) · get_code("f13f3af49bce9e05")
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 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

def clean_ans(s):
    ans_s = s.split('#### ')[1]
    ans_s = ans_s.replace(',', '')
    return ans_s

# The function takes a string parameter 's' that should contain '#### ' as a delimiter
# It splits on '#### ', takes the second part, and removes commas
test_string = "Question: What is 2+2? #### 4"

ARGS = {
    's': test_string
}
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 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
get_prompt Ran
ran; our contract draft was wrong, not the code
kiranpurohit/case/Code/LLM_experiments/CASE_Gsm8K_selection.py
code served (permissive licence) · get_code("f4cfbae1ebeb837e")
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 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 get_prompt(ex):
    s = '\n\n'
    s += 'Question:' + ex['question'] + '\n'
    ex['answer'] = re.sub('<<.*?>>', '', ex['answer'])
    ex['answer'] = ex['answer'].replace('#### ', 'Final Answer:')
    s += ex['answer']
    return s

ARGS = {
    'ex': {
        'question': 'What is 2 + 2?',
        'answer': 'We need to add 2 and 2. <<step1>> 2 + 2 = 4. #### 4'
    }
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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
prompt_for_manual_prediction Ran
ran; our contract draft was wrong, not the code
kiranpurohit/case/Code/LLM_experiments/CASE_Gsm8K_selection.py
code served (permissive licence) · get_code("eef468548fe005c1")
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 pandas as pd
import re

# Create example data structures
ex = {
    'question': ' What is 2 + 2?',
    'answer': 'Step 1: Add the numbers.\n2 + 2 = 4\n#### 4'
}

shots_data = [
    {
        'question': ' What is 1 + 1?',
        'answer': 'Step 1: Add the numbers.\n1 + 1 = 2\n#### 2'
    },
    {
        'question': ' What is 3 + 3?',
        'answer': 'Step 1: Add the numbers.\n3 + 3 = 6\n#### 6'
    }
]

shots = pd.DataFrame(shots_data)

ARGS = {
    'ex': ex,
    'shots': shots
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
pandas — 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
self_con Ran
ran; our contract draft was wrong, not the code
kiranpurohit/case/Code/LLM_experiments/CASE_tabmwp_selection.py
code served (permissive licence) · get_code("4a389d1ce1f37d1b")
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 2, 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

torch.manual_seed(0)

# The function self_con takes a list of strings and extracts answers from them
# It splits by 'The answer is:', cleans up the text, and counts occurrences

tmp_list = [
    "Some reasoning here. The answer is: 42",
    "More text. The answer is: 42",
    "Different answer. The answer is: 7",
    "Another one. The answer is: 42",
    "Text with special chars. The answer is: $100%",
    "Text with comma. The answer is: 1,000",
    "Text with period. The answer is: 3.14.",
    "containing the final answer for: should_be_ignored",
    "Empty answer. The answer is: ",
]

ARGS = {
    'tmp_list': tmp_list
}
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 list, ndim 2, 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
top_m_arm Ran
ran on a synthesized input
kiranpurohit/case/Code/LLM_experiments/CASE_Gsm8K_selection.py
code served (permissive licence) · get_code("c25b31771e40684e")
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 NoneType. 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 pandas as pd

# Create mock data for initialization
np.random.seed(42)

# Create sample X matrix (N=5 samples, K=3 arms/features)
X = np.random.randn(5, 3)

# Create sample validation data
val_data = pd.DataFrame({
    'question': ['What is 2+2?', 'What is 3+3?'],
    'answer': ['#### 4', '#### 6']
})

# Create sample subsets
subsets = [[0, 1], [1, 2]]

# Create sample theta
theta = np.random.randn(1, 5)

# Mock args object
class MockArgs:
    pass

args = MockArgs()

INIT_ARGS = {
    'args': args,
    'X': X,
    'm': 2,
    'val_data': val_data,
    'subsets': subsets,
    'theta': theta,
    'delta': 0.05,
    'epsilon': 0.11
}

ARGS = {}

METHOD = 'reset_bandit_specific_parameters'

# Import and construct the class
from random import sample
import re

def clean_ans(s):
    try:
        ans_s = s.split('#### ')[1]
        ans_s = ans_s.replace(',', '')
        return ans_s
    except:
        return s

class top_m_arm:

    def __init__(self, args, X, m, val_data=None, subsets=None, theta=None, delta=0.05, epsilon=0.11):
        self.not_terminated = 0
        self.current_n_simu = 0
        self.delta = delta
        self.epsilon = epsilon
        self.m = m
        self.val_data = val_data
        self.subsets = subsets
        self.X = X
        self.N, self.K = np.shape(X)
        self.arms = list(range(self.K))
        self.true_theta = theta
        self.theta = None
        self.T_init = 0
        self.n_das = 5
        self.sigma = 0.5
        self.index_time = 0

    def reset_bandit_specific_parameters(self):
        assert np.shape(self.X)[0] == self.N and np.shape(self.X)[1] == self.K and (len(np.shape(self.X)) == 2)
        self.T_init = 0
        self.hyper = 1.0
        self.B_inv = 1 / float(self.hyper ** 2) * np.eye(self.N)
        self.b = np.zeros(self.N)
        self.theta = np.random.normal(0, 1, size=(1, self.N))

    def clear(self):
        self.rewards = []
        self.pulled_arms = []

# Construct and call
instance = top_m_arm(**INIT_ARGS)
instance.reset_bandit_specific_parameters()
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
numpy, openai, pandas, tenacity — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type NoneType — a NoneType output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a NoneType 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
LLM_error_indicator Not yet run
unverified (harvested, no recorded run)
kiranpurohit/case/Code/LLM_experiments/CASE_Gsm8K_selection.py
code served (permissive licence) · get_code("175ae74476e58e2f")
How it ran

no invocation recorded.

get_completion Not yet run
unverified (harvested, no recorded run)
kiranpurohit/case/Code/LLM_experiments/CASE_Gsm8K_selection.py
code served (permissive licence) · get_code("f2f4fbbf9e2b7fe5")
How it ran

no invocation recorded.

llm_output Not yet run
unverified (harvested, no recorded run)
kiranpurohit/case/Code/LLM_experiments/CASE_Gsm8K_selection.py
code served (permissive licence) · get_code("8f0482096f8f0ccc")
How it ran

no invocation recorded.

Also present in other papers' code

Of 8 samples lifted from this paper's linked repositories, 8 carry a function identity and 0 do not. Of the 8 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 6 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
clean_ans
brick of this paper's assembly: helper
1 other paper
1 dated earlier
2411.03877 (2024-11)
EXPLORA: Efficient Exemplar Subset Selection for Complex Reasoning
llm_output
brick of this paper's assembly: helper
1 other paper
1 dated earlier
2411.03877 (2024-11)
EXPLORA: Efficient Exemplar Subset Selection for Complex Reasoning

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 in-context learning paradigm with LLMs has been instrumental in advancing a wide range of natural language processing tasks. The selection of few-shot examples (exemplars / demonstration samples) is essential for constructing effective prompts under context-length budget constraints. In this paper, we formulate the exemplar selection task as a top-m best arms identification problem. A key challenge in this setup is the exponentially large number of arms that need to be evaluated to identify the m-best arms. We propose CASE (Challenger Arm Sampling for Exemplar selection), a novel sample-efficient selective exploration strategy that maintains a shortlist of "challenger" arms, which are current candidates for the top-m arms. In each iteration, only one of the arms from this shortlist or the current topm set is pulled, thereby reducing sample complexity and, consequently, the number of LLM evaluations. Furthermore, we model the scores of exemplar subsets (arms) using a parameterized linear scoring function, leading to stochastic linear bandits setting. CASE achieves remarkable efficiency gains of up to 7× speedup in runtime while requiring 7× fewer LLM calls (87% reduction) without sacrificing performance compared to state-of-the-art exemplar selection methods. We release our code and data. 1 * Equal contribution.

For agents

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

get_harvested_code_for_paper("2506.08607")
get_code_for_paper("2506.08607")
have("2506.08607")

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

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

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

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

Connect an agent — have() is free.