mlsanityData to 7 Oct 2026

Enhancing Code Translation in Language Models with Few-Shot Learning via Retrieval-Augmented Generation

arXiv 2407.19619 ↗First posted 29 Jul 2024cs.AI cs.SEcited by 16

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

  1. 2021LoRA: Low-Rank Adaptation of Large Language Modelscited by 14,084
  2. 2020Retrieval-Augmented Generation for Knowledge-Intensive NLP Taskscited by 9,160
  3. 2021Evaluating Large Language Models Trained on Codecited by 8,053
  4. 2022Large Language Models are Zero-Shot Reasonerscited by 4,323
  5. 2019HuggingFace's Transformers: State-of-the-art Natural Language Processingcited by 2,201
  6. 2023Code Llama: Open Foundation Models for Codecited by 2,105
  7. 2024Mixtral of Expertscited by 1,785
  8. 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
  9. 2023StarCoder: may the source be with you!cited by 790
  10. 2024StarCoder 2 and The Stack v2: The Next Generationcited by 484
  11. 2020CodeBLEU: a Method for Automatic Evaluation of Code Synthesiscited by 468
  12. 2024Nomic Embed: Training a Reproducible Long Context Text Embeddercited by 255
3 more
  1. 2024Granite Code Models: A Family of Open Foundation Models for Code Intelligencecited by 116
  2. 2024Fine-tuning Large Language Models for Domain-specific Machine Translationcited by 43
  3. 2023Creating a Dataset for High-Performance Computing Code Translation using LLMs: A Bridge Between OpenMP Fortran and C++cited by 11

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2024: 2; 2025: 11; 2026: 3.

16 papers.

Sort:

By area:

  1. 2024RepoTransBench: A Real-World Multilingual Benchmark for Repository-Level Code Translationcited by 21
  2. 2025From Code Foundation Models to Agents and Applications: A Comprehensive Survey and Practical Guide to Code Intelligencecited by 13
  3. 2025Lost in OCR Translation? Vision-Based Approaches to Robust Document Retrievalcited by 10
  4. 2025LLM-Assisted Translation of Legacy FORTRAN Codes to C++: A Cross-Platform Studycited by 7
  5. 2025ARCS: Agentic Retrieval-Augmented Code Synthesis with Iterative Refinementcited by 6
  6. 2025Function-to-Style Guidance of LLMs for Code Translationcited by 4
  7. 2025Skeleton-Guided-Translation: A Benchmarking Framework for Code Repository Translation with Fine-Grained Quality Evaluationcited by 3
  8. 2025Advances in LLMs with Focus on Reasoning, Adaptability, Efficiency and Ethicscited by 2
  9. 2024Benchmarking Large Language Models with Integer Sequence Generation Taskscited by 1
  10. 2025Optimizing Code Runtime Performance through Context-Aware Retrieval-Augmented Generationcited by 1
  11. 2025Performance Evaluation of General Purpose Large Language Models for Basic Linear Algebra Subprograms Code Generationcited by 1
  12. 2025BabelCoder: Agentic Code Translation with Specification Alignmentcited by 1
4 more
  1. 2026CodePivot: Bootstrapping Multilingual Transpilation in LLMs via Reinforcement Learning without Parallel Corporacited by 1
  2. 2025Context-Aware Search and Retrieval Over Erasure Channelscited by 0
  3. 2026Bridging Functional Correctness and Runtime Efficiency Gaps in LLM-Based Code Translationcited by 0
  4. 2026ORCA: Evaluating LLMs on Data Science Code Translationcited by 0

Similar, not cited

Close in wording, no citation either way

  1. 2024Enhancing Cross-Language Code Translation via Task-Specific Embedding Alignment in Retrieval-Augmented Generation
  2. 2023Exploring Parameter-Efficient Fine-Tuning Techniques for Code Generation with Large Language Models
  3. 2024Retrieval-augmented code completion for local projects using large language models
  4. 2025ReCode: Improving LLM-based Code Repair with Fine-Grained Retrieval-Augmented Generation
  5. 2024Improving the Ability of Pre-trained Language Model by Imparting Large Language Model's Experience ↗
  6. 2024Does Few-Shot Learning Help LLM Performance in Code Synthesis?
  7. 2025A Deep Dive into Retrieval-Augmented Generation for Code Completion: Experience on WeChat
  8. 2026Exploring different approaches to customize language models for domain-specific text-to-code generation