Encode Errors: Representational Retrieval of In-Context Demonstrations for Multilingual Grammatical Error Correction

Guangyue Peng, Wei Li, Wen Luo, Houfeng Wang

Abstract

Large Language Models (LLMs) often struggle with Grammatical Error Correction (GEC), frequently suffering from misalignment or over-correction. This paper introduces Representational Retrieval, a method that leverages the model's internal "Grammatical Error Representations" (GER) to find in-context demonstrations with similar error patterns. By focusing on error-type similarity rather than semantic similarity, this approach significantly improves correction accuracy across multiple languages and reduces unnecessary rewrites.

Introduction

Grammatical Error Correction (GEC) is a challenging task for LLMs. Despite their fluency, models often fail to fix specific errors (misalignment) or rewrite correct sentences unnecessarily (over-correction). Traditional In-Context Learning (ICL) relies on semantic retrieval, which often provides examples based on topic rather than grammatical structure. For instance, a model correcting a verb tense error in a sentence about "cooking" might be shown correct sentences about "recipes," which does little to clarify the underlying grammatical rule.

Methodology: Representational Retrieval

The authors propose a pipeline that extracts and utilizes internal model states to guide retrieval. The core of this method is the Grammatical Error Representation (GER).

The Representational Retrieval pipeline, showing Representation Construction via PCA and Representation-based Retrieval using an Error Database.

The process involves four key steps:

  1. Initial Probe: The model performs a zero-shot correction attempt.
  2. Error Vector Extraction: By comparing hidden states of edited vs. unedited tokens, Principal Component Analysis (PCA) identifies Error Vectors (EV) in the latent space.
  3. GER Projection: Input sentences are projected onto these EVs, creating a semantically neutral encoding of the error type (e.g., tense vs. spelling).
  4. Dynamic Retrieval: These GERs query an "Error DB" for demonstrations with matching error patterns. The magnitude of the first GER component determines the number of examples retrieved, optimizing computational efficiency.

Key Insights: The Model as its Own Critic

A fundamental discovery of this work is that LLMs inherently capture grammatical error information within their internal states.

Density plot of the first GER component, demonstrating clear separation between erroneous (TP, FP) and correct (TN, FN) tokens.

The first principal component (EV1) serves as a highly effective error detector, achieving over 98% accuracy in distinguishing erroneous tokens. Furthermore, by clustering sentences by error type rather than topic, the model avoids the "Over-Correction Trap." Seeing examples of specific errors being fixed encourages the model to be more conservative and targeted in its edits.

Evaluation and Results

The method was evaluated across five datasets in four languages (English, German, Romanian, and Estonian).

  • Performance: GER-based retrieval outperformed state-of-the-art explanation-based methods by up to 9 points in $F_{0.5}$ score for English.
  • Multilingual Robustness: In low-resource settings like Estonian, the method provided a 1.2x improvement over baselines.
  • Efficiency: The vector-based extraction is approximately 50x faster than methods requiring text-based explanations.
  • Scaling: An 8B Llama 3.1 model using this method matched the performance of much larger models like GPT-4o-mini.

Conclusion

Representational Retrieval demonstrates that the internal states of LLMs contain rich, actionable information about grammatical errors. By shifting from semantic to representational retrieval, GEC becomes more precise and efficient. Future work may explore using these representations to directly steer the decoding process, further refining the model's ability to correct errors in real-time.

Summary updated

BibTeX
@inproceedings{peng2025encode,
  author = {Guangyue Peng and Wei Li and Wen Luo and Houfeng Wang},
  title = {{Encode Errors: Representational Retrieval of In-Context Demonstrations for Multilingual Grammatical Error Correction}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure