SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2502.08507 · NAACL · 2025

Explanation based In-Context Demonstrations Retrieval for Multilingual Grammatical Error Correction

Wei Li, Wen Luo, Houfeng Wang, Guangyue Peng

arXiv · PDF · Open in the Atlas

Code that ran

4 of 5 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 4 have no contract verdict; 0 failures of our instrument; 1 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/2502.08507.json · badge: /api/ran/2502.08507.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
GMago-LeWay/FewShotGEC canonical (classifier label)
classifier basis not recorded on the link
4 ran · 1 no recorded run
FunctionStatusWhere it lives
gec_extract_answer Ran
ran on a synthesized input
GMago-LeWay/FewShotGEC/icl.py
code served (permissive licence) · get_code("b5c7b2f5cf30567d")
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

torch.manual_seed(0)

# Analyze the function to understand what parameters it needs:
# - string: a string that contains start and end markers
# - original_text: a fallback string to return
# - start: a marker string to split on
# - end: a marker string to split on

# The function checks:
# - if start is in string
# - if 'No errors found' is in string
# - if len(end) >= 5, it truncates end by removing last char
# - if end is in string
# - splits string by start, then by end
# - strips whitespace

ARGS = {
    'string': 'Error found: The cat sat on the mat. Please correct this.',
    'original_text': 'The cat sat on the mat.',
    'start': 'Error found: ',
    'end': '. Please correct this.'
}
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 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
gec_extract_answer Ran
ran on a synthesized input
GMago-LeWay/FewShotGEC/icl_prepare.py
code served (permissive licence) · get_code("9d5aa9ff4a2580b5")
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

def gec_extract_answer(string, original_text, start, end):
    if start not in string or 'No errors found' in string:
        return original_text
    if end not in string:
        return original_text
    answer = string.split(start)[1].split(end)[0]
    answer = answer.strip()
    if answer == '' or answer == ' ':
        return original_text
    return answer

torch.manual_seed(0)

ARGS = {
    "string": "The correction is: hello world :end_correction",
    "original_text": "hello world",
    "start": "The correction is:",
    "end": ":end_correction"
}
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 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
gec_split_answer Ran
ran on a synthesized input
GMago-LeWay/FewShotGEC/icl.py
code served (permissive licence) · get_code("6cf7ccab9586de56")
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

torch.manual_seed(0)

# Analyze the function:
# - string: str - a string that will be split by splitter
# - original_text: str - reference text for length comparison
# - splitter: str - delimiter for splitting the string

# The function splits `string` by `splitter`, checks if there are >= 3 parts,
# extracts the middle part (splits[1]), and validates its length relative to original_text.
# All parameters are strings, so we need to construct valid string arguments.

# Create test strings where splitting produces 3+ parts
string_value = "start<<answer text here>>end"
splitter_value = "<<"
original_text_value = "answer text here"

# Verify the logic:
# splits = string_value.split(splitter_value)
# -> ["start", "answer text here>>end"]
# This only gives 2 splits, need to fix

# Better approach: use splitter that appears multiple times
string_value = "prefix<<answer text>>suffix"
splitter_value = "<<"
# splits = ["prefix", "answer text>>suffix"]
# Still only 2. Need splitter that creates 3+ parts

# Even better:
string_value = "start||middle part||end||extra"
splitter_value = "||"
original_text_value = "middle part"
# splits = ["start", "middle part", "end", "extra"]
# len(splits) = 4, which is >= 3
# answer = "middle part".strip() = "middle part"
# len(answer) / len(original_text) = 11 / 11 = 1.0, which is in [0.5, 2.0]
# So it should return "middle part"

ARGS = {
    "string": "start||middle part||end||extra",
    "original_text": "middle part",
    "splitter": "||"
}
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
start_end_extraction Ran
ran on a synthesized input
GMago-LeWay/FewShotGEC/generate.py
code served (permissive licence) · get_code("ca931f77e5edb0c1")
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

def start_end_extraction(string, start, end):
    if start:
        if string.find(start) != -1:
            string = string.split(start, 1)[1]
    if end:
        if string.find(end) != -1:
            string = string.split(end, 1)[0]
    return string

ARGS = {
    "string": "hello[START]world[END]foo",
    "start": "[START]",
    "end": "[END]"
}
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 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
postprocess Not yet run
unverified (harvested, no recorded run)
GMago-LeWay/FewShotGEC/generate.py
code served (permissive licence) · get_code("07b276811116091c")
How it ran

no invocation recorded.

Also present in other papers' code

Of 5 samples lifted from this paper's linked repositories, 5 carry a function identity and 0 do not. Of the 5 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 5 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.

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

Grammatical error correction (GEC) aims to correct grammatical, spelling, and semantic errors in natural language text. With the growing of large language models (LLMs), direct text generation has gradually become the focus of the GEC methods, and few-shot incontext learning presents a cost-effective solution. However, selecting effective in-context examples remains challenging, as the similarity between input texts does not necessarily correspond to similar grammatical error patterns. In this paper, we propose a novel retrieval method based on natural language grammatical error explanations (GEE) to address this issue. Our method retrieves suitable few-shot demonstrations by matching the GEE of the test input with that of pre-constructed database samples, where explanations for erroneous samples are generated by LLMs. We conducted multilingual GEC few-shot experiments on both major open-source and closed-source LLMs. Experiments across five languages show that our method outperforms existing semantic and BM25-based retrieval techniques, without requiring additional training or language adaptation. This also suggests that matching error patterns is key to selecting examples. Our code is available at https://github.com/GMago-LeWay/FewShotGEC. * Identified Error: "долж быт" instead of "долж быть" * Correction: "долж быть" * Explanation: In Russian, the verb "должен быть" (should be) is in the third person singular form, which requires the verb "быть" (to be) in the infinitive form. (...) **Error 2: Adjective agreement** * Identified Error: "академической и сложной" instead of "академическим и сложным" * Correction: "академическим и сложным" * Explanation: In Russian, adjectives agree with the nouns they modify in terms of case and number. (...

For agents

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

get_harvested_code_for_paper("2502.08507")
get_code_for_paper("2502.08507")
have("2502.08507")

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

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

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

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

Connect an agent — have() is free.