Introduction
While Large Language Models (LLMs) have demonstrated remarkable proficiency in sentence-level translation, their performance often degrades when tasked with document-level machine translation (DocMT). Two primary challenges hinder their effectiveness: incoherence and context window limitations. Without access to broader document context, models tend to produce translations that lack consistency in terminology and style. Furthermore, the limited input window of LLMs makes it difficult to incorporate long-range information and multiple few-shot demonstrations simultaneously without exceeding token limits or significantly increasing inference latency.
To address these issues, this research introduces Context-Aware Prompting (CAP). CAP is a novel framework designed to enhance the document-level translation capabilities of LLMs by efficiently selecting and summarizing relevant context to guide the translation process through in-context learning (ICL).
The Context-Aware Prompting (CAP) Framework
The CAP framework operates through a three-stage pipeline designed to maximize the utility of available context while respecting the model's constraints.
- Dynamic Context Window: Rather than relying on a fixed sliding window of preceding sentences, CAP utilizes the LLM's internal attention mechanisms. By extracting attention scores from the final layer, the system identifies which previous sentences are most linguistically relevant to the current target sentence. This allows the model to capture non-linear dependencies across the document.
- Summarize and Retrieve: To manage the context window efficiently, CAP employs the LLM to generate a concise summary of the identified relevant sentences. This summary serves as a semantic query to retrieve $K$ high-quality bilingual sentence pairs from a large-scale datastore (e.g., OPUS-100) using cosine similarity.
- Inference: The retrieved sentence pairs are used as task-specific demonstrations in a few-shot prompt. This provides the LLM with both the immediate document context (via the summary) and relevant translation examples, leading to more coherent and accurate document-level outputs.
Experimental Evaluation
The effectiveness of CAP was evaluated across several diverse benchmarks, including WMT22 newstest for general translation (German-English and Chinese-English), the GuoFeng dataset for Zero Pronoun Translation (ZPT), and the WMT23 Literary Translation dataset for long-range consistency. The framework was tested using various LLM families, including Qwen (ranging from 1.8B to 72B parameters) and Baichuan.
Key Results and Analysis
CAP consistently outperformed zero-shot baselines and standard prompting strategies such as random selection or BM25-based retrieval.
As shown in the results, the CAP method achieved superior d-BLEU and chrF2 scores across all tested language pairs. Notably, even smaller models like Qwen-7B-Chat, when equipped with CAP, can rival or exceed the performance of larger specialized translation models like NLLB-3.3B in certain contexts.
Beyond general metrics, CAP showed significant improvements in specific linguistic tasks:
- Pronoun Recovery: In Chinese-to-English translation, CAP's ability to "see" the omitted subject in the summarized context allowed models to correctly re-insert pronouns (e.g., "He" or "She") that zero-shot models often missed. For instance, Qwen-1.8B saw a ZPT accuracy jump from 29.29% to 32.58%.
- Literary Consistency: On the WMT23 Literary task, CAP improved entity consistency and "Blonde" scores, demonstrating its effectiveness for creative and complex texts.
Conclusion
Context-Aware Prompting (CAP) provides an efficient path for leveraging LLMs in document-level translation without the need for expensive fine-tuning. By using internal attention for context selection and summarization for retrieval, CAP bridges the gap between sentence-level and document-level accuracy. While challenges remain regarding computational overhead and perfect long-range coreference consistency, CAP represents a significant step forward in making LLMs more effective for complex, context-dependent translation tasks.
Summary updated