mlsanityData to 7 Oct 2026

Enhancing Cross-Language Code Translation via Task-Specific Embedding Alignment in Retrieval-Augmented Generation

arXiv 2412.05159 ↗First posted 6 Dec 2024cs.AI cs.SEcited by 4

On the map: Retrieval-augmented generation → RAG for code

Abstract (arXiv)

We introduce a novel method to enhance cross-language code translation from Fortran to C++ by integrating task-specific embedding alignment into a Retrieval-Augmented Generation (RAG) framework. Unlike conventional retrieval approaches that utilize generic embeddings agnostic to the downstream task, our strategy aligns the retrieval model directly with the objective of maximizing translation quality, as quantified by the CodeBLEU metric. This alignment ensures that the embeddings are semantically and syntactically meaningful for the specific code translation task. Our methodology involves constructing a dataset of 25,000 Fortran code snippets sourced from Stack-V2 dataset and generating their corresponding C++ translations using the LLaMA 3.1-8B language model. We compute pairwise CodeBLEU scores between the generated translations and ground truth examples to capture fine-grained similarities. These scores serve as supervision signals in a contrastive learning framework, where we optimize the embedding model to retrieve Fortran-C++ pairs that are most beneficial for improving the language model's translation performance. By integrating these CodeBLEU-optimized embeddings into the RAG framework, our approach significantly enhances both retrieval accuracy and code generation quality over methods employing generic embeddings. On the HPC Fortran2C++ dataset, our method elevates the average CodeBLEU score from 0.64 to 0.73, achieving a 14% relative improvement. On the Numerical Recipes dataset, we observe an increase from 0.52 to 0.60, marking a 15% relative improvement. Importantly, these gains are realized without any fine-tuning of the language model, underscoring the efficiency and practicality of our approach.

Key facts. Cited by 4 papers in the map (data through 7 Oct 2026). Placed in RAG for code, one of 15 directions in Retrieval-augmented generation. Builds on 12 of its 18 references that are in the map. First posted on arXiv 6 Dec 2024.

Builds on

12 of 18 references.

References · 12

  1. 2023LLaMA: Open and Efficient Foundation Language Modelscited by 13,958
  2. 2020Retrieval-Augmented Generation for Knowledge-Intensive NLP Taskscited by 9,160
  3. 2021Evaluating Large Language Models Trained on Codecited by 8,053
  4. 2018Representation Learning with Contrastive Predictive Codingcited by 7,662
  5. 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
  6. 2023StarCoder: may the source be with you!cited by 790
  7. 2024StarCoder 2 and The Stack v2: The Next Generationcited by 484
  8. 2020CodeBLEU: a Method for Automatic Evaluation of Code Synthesiscited by 468
  9. 2020Understanding the Behaviour of Contrastive Losscited by 397
  10. 2024Nomic Embed: Training a Reproducible Long Context Text Embeddercited by 255
  11. 2024Granite Code Models: A Family of Open Foundation Models for Code Intelligencecited by 116
  12. 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: 2025: 3; 2026: 1.

4 papers.

Similar, not cited

Close in wording, no citation either way

  1. 2024Enhancing Code Translation in Language Models with Few-Shot Learning via Retrieval-Augmented Generation
  2. 2026AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code Completion
  3. 2024Retrieval-augmented code completion for local projects using large language models
  4. 2024CodeXEmbed: A Generalist Embedding Model Family for Multiligual and Multi-task Code Retrieval
  5. 2025Across Programming Language Silos: A Study on Cross-Lingual Retrieval-augmented Code Generation
  6. 2025Towards A Generalist Code Embedding Model Based On Massive Data Synthesis
  7. 2025Beyond Code Pairs: Dialogue-Based Data Generation for LLM Code Translation
  8. 2025ReCode: Improving LLM-based Code Repair with Fine-Grained Retrieval-Augmented Generation