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 in-context 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.
Introduction
The paradigm of Grammatical Error Correction (GEC) has shifted significantly from specialized edit-based models toward general-purpose Large Language Models (LLMs) utilizing In-Context Learning (ICL). In this few-shot setting, the model's performance is highly sensitive to the quality and relevance of the provided demonstrations.
Traditionally, researchers have relied on semantic retrieval—selecting examples that are topically similar to the input sentence. However, this paper argues that semantic similarity is a poor proxy for grammatical similarity. Two sentences can share the same topic (e.g., "cleaning") but contain vastly different errors (e.g., a tense error vs. a missing preposition). Conversely, sentences about entirely different subjects might share the same underlying grammatical struggle. To optimize ICL for GEC, models need to see examples of the specific mistake they are currently tasked with fixing.
Methodology: Explanation-based Retrieval
The authors propose a novel Explanation-based Retrieval pipeline that prioritizes structural error patterns over semantic content. The process consists of three distinct phases:
- Database Construction: A labeled GEC dataset is processed by a "teacher model" (Llama-3.1-8B) to generate natural language Grammatical Error Explanations (GEE) for every erroneous sample. This creates a searchable database where the "key" is the explanation of the error and the "value" is the (input, correction) pair.
- Two-Step Retrieval:
- Initial Explanation: When a new test sentence is received, the LLM performs a preliminary check to generate a brief explanation of the perceived error.
- Matching: This initial explanation serves as a query. Using vector embeddings (xlm-roberta-large), the system identifies the top-$k$ samples in the database with the most similar error explanations.
- In-Context Learning: The retrieved pairs are inserted into the final prompt as demonstrations. Notably, the long natural language explanations are omitted from the final prompt to save context space and prevent potential degradation in generation quality caused by excessive reasoning steps.
Experimental Setup
The method was evaluated across five languages to test its multilingual robustness:
- English: W&I+LOCNESS, CoNLL-14, and BEA-19.
- Chinese: HSK and NLPCC-18.
- German: Falko-Merlin.
- Russian: RULEC.
- Estonian: Tartu learner corpus.
Testing involved both open-source and closed-source LLMs, including GPT-4o-mini, to ensure the findings were not model-specific.
Key Results and Insights
- Superior Performance: The explanation-based method consistently outperformed Random selection, Semantic retrieval (SBERT), and keyword-based retrieval (BM25) across nearly all tested languages and models. For instance, on the English CoNLL-14 dataset using GPT-4o-mini, the method achieved an $F_{0.5}$ score of 58.74, surpassing the 57.87 achieved by semantic retrieval.
- The "Initial Explanation" Efficacy: Even if the LLM's first guess at an explanation is not perfectly accurate, it is typically "directionally correct" enough to serve as a high-quality search query for the GEE database.
- Multilingual Zero-Shot Transfer: By leveraging natural language explanations, the system avoids the need for language-specific rules, successfully transferring its capabilities to languages like Russian and Estonian through the LLM's internal multilingual understanding.
- Retrieval vs. Reasoning: An ablation study revealed that using "Chain of Thought" (asking the model to explain the error during the final output) actually degraded performance. The most effective use of explanations is for retrieval only, keeping the final correction prompt clean.
Conclusion and Future Work
This research demonstrates that for GEC, the structural nature of a mistake is a more powerful retrieval key than sentence meaning. While the method significantly closes the gap with state-of-the-art fine-tuned models without requiring parameter updates, some limitations remain. Future work will focus on reducing the computational cost of database construction and finding better ways to index "correct" (error-free) samples, which currently still rely on basic text similarity.
Summary updated