Enhancing Code Translation in Language Models with Few-Shot Learning via Retrieval-Augmented Generation
On the map: Retrieval-augmented generation → RAG for code
Abstract (arXiv)
The advent of large language models (LLMs) has significantly advanced the field of code translation, enabling automated translation between programming languages. However, these models often struggle with complex translation tasks due to inadequate contextual understanding. This paper introduces a novel approach that enhances code translation through Few-Shot Learning, augmented with retrieval-based techniques. By leveraging a repository of existing code translations, we dynamically retrieve the most relevant examples to guide the model in translating new code segments. Our method, based on Retrieval-Augmented Generation (RAG), substantially improves translation quality by providing contextual examples from which the model can learn in real-time. We selected RAG over traditional fine-tuning methods due to its ability to utilize existing codebases or a locally stored corpus of code, which allows for dynamic adaptation to diverse translation tasks without extensive retraining. Extensive experiments on diverse datasets with open LLM models such as Starcoder, Llama3-70B Instruct, CodeLlama-34B Instruct, Granite-34B Code Instruct, and Mixtral-8x22B, as well as commercial LLM models like GPT-3.5 Turbo and GPT-4o, demonstrate our approach's superiority over traditional zero-shot methods, especially in translating between Fortran and CPP. We also explored varying numbers of shots i.e. examples provided during inference, specifically 1, 2, and 3 shots and different embedding models for RAG, including Nomic-Embed, Starencoder, and CodeBERT, to assess the robustness and effectiveness of our approach.
Key facts. Cited by 16 papers in the map (data through 7 Oct 2026). Placed in RAG for code, one of 15 directions in Retrieval-augmented generation. Builds on 15 of its 21 references that are in the map. First posted on arXiv 29 Jul 2024.
Builds on
15 of 21 references.
References · 15
- 2021LoRA: Low-Rank Adaptation of Large Language Modelscited by 14,084
- 2020Retrieval-Augmented Generation for Knowledge-Intensive NLP Taskscited by 9,160
- 2021Evaluating Large Language Models Trained on Codecited by 8,053
- 2022Large Language Models are Zero-Shot Reasonerscited by 4,323
- 2019HuggingFace's Transformers: State-of-the-art Natural Language Processingcited by 2,201
- 2023Code Llama: Open Foundation Models for Codecited by 2,105
- 2024Mixtral of Expertscited by 1,785
- 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
- 2023StarCoder: may the source be with you!cited by 790
- 2024StarCoder 2 and The Stack v2: The Next Generationcited by 484
- 2020CodeBLEU: a Method for Automatic Evaluation of Code Synthesiscited by 468
- 2024Nomic Embed: Training a Reproducible Long Context Text Embeddercited by 255
3 more
- 2024Granite Code Models: A Family of Open Foundation Models for Code Intelligencecited by 116
- 2024Fine-tuning Large Language Models for Domain-specific Machine Translationcited by 43
- 2023Creating a Dataset for High-Performance Computing Code Translation using LLMs: A Bridge Between OpenMP Fortran and C++cited by 11
Built on by
Citing papers per year: 2024: 2; 2025: 11; 2026: 3.
16 papers.
Sort:
By area:
- 2024RepoTransBench: A Real-World Multilingual Benchmark for Repository-Level Code Translationcited by 21
- 2025From Code Foundation Models to Agents and Applications: A Comprehensive Survey and Practical Guide to Code Intelligencecited by 13
- 2025Lost in OCR Translation? Vision-Based Approaches to Robust Document Retrievalcited by 10
- 2025LLM-Assisted Translation of Legacy FORTRAN Codes to C++: A Cross-Platform Studycited by 7
- 2025ARCS: Agentic Retrieval-Augmented Code Synthesis with Iterative Refinementcited by 6
- 2025Function-to-Style Guidance of LLMs for Code Translationcited by 4
- 2025Skeleton-Guided-Translation: A Benchmarking Framework for Code Repository Translation with Fine-Grained Quality Evaluationcited by 3
- 2025Advances in LLMs with Focus on Reasoning, Adaptability, Efficiency and Ethicscited by 2
- 2024Benchmarking Large Language Models with Integer Sequence Generation Taskscited by 1
- 2025Optimizing Code Runtime Performance through Context-Aware Retrieval-Augmented Generationcited by 1
- 2025Performance Evaluation of General Purpose Large Language Models for Basic Linear Algebra Subprograms Code Generationcited by 1
- 2025BabelCoder: Agentic Code Translation with Specification Alignmentcited by 1
4 more
- 2026CodePivot: Bootstrapping Multilingual Transpilation in LLMs via Reinforcement Learning without Parallel Corporacited by 1
- 2025Context-Aware Search and Retrieval Over Erasure Channelscited by 0
- 2026Bridging Functional Correctness and Runtime Efficiency Gaps in LLM-Based Code Translationcited by 0
- 2026ORCA: Evaluating LLMs on Data Science Code Translationcited by 0
- 2026ORCA: Evaluating LLMs on Data Science Code Translation25 Sep 2026
- 2026Bridging Functional Correctness and Runtime Efficiency Gaps in LLM-Based Code Translation16 Jun 2026
- 2026CodePivot: Bootstrapping Multilingual Transpilation in LLMs via Reinforcement Learning without Parallel Corpora20 Apr 2026
- 2025BabelCoder: Agentic Code Translation with Specification Alignment7 Dec 2025
- 2025From Code Foundation Models to Agents and Applications: A Comprehensive Survey and Practical Guide to Code Intelligence23 Nov 2025
- 2025Context-Aware Search and Retrieval Over Erasure Channels16 Jul 2025
- 2025Function-to-Style Guidance of LLMs for Code Translation15 Jul 2025
- 2025Performance Evaluation of General Purpose Large Language Models for Basic Linear Algebra Subprograms Code Generation7 Jul 2025
- 2025Advances in LLMs with Focus on Reasoning, Adaptability, Efficiency and Ethics14 Jun 2025
- 2025Lost in OCR Translation? Vision-Based Approaches to Robust Document Retrieval8 May 2025
- 2025ARCS: Agentic Retrieval-Augmented Code Synthesis with Iterative Refinement29 Apr 2025
- 2025LLM-Assisted Translation of Legacy FORTRAN Codes to C++: A Cross-Platform Study21 Apr 2025
4 more
- 2025Optimizing Code Runtime Performance through Context-Aware Retrieval-Augmented Generation28 Jan 2025
- 2025Skeleton-Guided-Translation: A Benchmarking Framework for Code Repository Translation with Fine-Grained Quality Evaluation27 Jan 2025
- 2024RepoTransBench: A Real-World Multilingual Benchmark for Repository-Level Code Translation23 Dec 2024
- 2024Benchmarking Large Language Models with Integer Sequence Generation Tasks7 Nov 2024
- 2025Lost in OCR Translation? Vision-Based Approaches to Robust Document Retrievalcited by 10
- 2025ARCS: Agentic Retrieval-Augmented Code Synthesis with Iterative Refinementcited by 6
- 2025Optimizing Code Runtime Performance through Context-Aware Retrieval-Augmented Generationcited by 1
- 2025Context-Aware Search and Retrieval Over Erasure Channelscited by 0
- 2025Context-Aware Search and Retrieval Over Erasure Channels16 Jul 2025
- 2025Lost in OCR Translation? Vision-Based Approaches to Robust Document Retrieval8 May 2025
- 2025ARCS: Agentic Retrieval-Augmented Code Synthesis with Iterative Refinement29 Apr 2025
- 2025Optimizing Code Runtime Performance through Context-Aware Retrieval-Augmented Generation28 Jan 2025
- 2024RepoTransBench: A Real-World Multilingual Benchmark for Repository-Level Code Translationcited by 21
- 2025LLM-Assisted Translation of Legacy FORTRAN Codes to C++: A Cross-Platform Studycited by 7
- 2025Function-to-Style Guidance of LLMs for Code Translationcited by 4
- 2025Skeleton-Guided-Translation: A Benchmarking Framework for Code Repository Translation with Fine-Grained Quality Evaluationcited by 3
- 2025Performance Evaluation of General Purpose Large Language Models for Basic Linear Algebra Subprograms Code Generationcited by 1
- 2026Bridging Functional Correctness and Runtime Efficiency Gaps in LLM-Based Code Translationcited by 0
- 2026ORCA: Evaluating LLMs on Data Science Code Translationcited by 0
- 2026ORCA: Evaluating LLMs on Data Science Code Translation25 Sep 2026
- 2026Bridging Functional Correctness and Runtime Efficiency Gaps in LLM-Based Code Translation16 Jun 2026
- 2025Function-to-Style Guidance of LLMs for Code Translation15 Jul 2025
- 2025Performance Evaluation of General Purpose Large Language Models for Basic Linear Algebra Subprograms Code Generation7 Jul 2025
- 2025LLM-Assisted Translation of Legacy FORTRAN Codes to C++: A Cross-Platform Study21 Apr 2025
- 2025Skeleton-Guided-Translation: A Benchmarking Framework for Code Repository Translation with Fine-Grained Quality Evaluation27 Jan 2025
- 2024RepoTransBench: A Real-World Multilingual Benchmark for Repository-Level Code Translation23 Dec 2024
Similar, not cited
Close in wording, no citation either way
- 2024Enhancing Cross-Language Code Translation via Task-Specific Embedding Alignment in Retrieval-Augmented Generation
- 2023Exploring Parameter-Efficient Fine-Tuning Techniques for Code Generation with Large Language Models
- 2024Retrieval-augmented code completion for local projects using large language models
- 2025ReCode: Improving LLM-based Code Repair with Fine-Grained Retrieval-Augmented Generation
- 2024Improving the Ability of Pre-trained Language Model by Imparting Large Language Model's Experience ↗
- 2024Does Few-Shot Learning Help LLM Performance in Code Synthesis?
- 2025A Deep Dive into Retrieval-Augmented Generation for Code Completion: Experience on WeChat
- 2026Exploring different approaches to customize language models for domain-specific text-to-code generation