arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2412.05159cs.AIcs.SE
收藏

通过检索增强生成中的任务特定嵌入对齐增强跨语言代码翻译

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

Los Alamos National Laboratory(洛斯阿拉莫斯国家实验室)

Manish Bhattarai, Minh Vu, Javier E. Santos, Ismael Boureima, Daniel O' Malley

AI总结:

本文提出在RAG中用CodeBLEU监督的对比学习对齐代码嵌入,以提升Fortran到C++翻译,在两个数据集上分别取得14%和15%的相对改进且无需微调语言模型。

摘要:

我们提出了一种通过将任务特定嵌入对齐集成到检索增强生成(RAG)框架中来增强从 Fortran 到 C++ 的跨语言代码翻译的新方法。与使用不了解下游任务的通用嵌入的传统检索方法不同,我们的策略直接使检索模型与最大化翻译质量的目标保持一致,该质量由 CodeBLEU 指标量化。这种对齐确保嵌入对于特定的代码翻译任务在语义和句法上都具有意义。我们的方法包括构建一个包含 25,000 个源自 Stack-V2 数据集的 Fortran 代码片段的数据集,并使用 LLaMA 3.1-8B 语言模型生成其对应的 C++ 翻译。我们计算生成的翻译与真实示例之间的成对 CodeBLEU 分数,以捕获细粒度的相似性。这些分数在对比学习框架中充当监督信号,在该框架中,我们优化嵌入模型,以检索最有利于提高语言模型翻译性能的 Fortran-C++ 对。通过将这些经过 CodeBLEU 优化的嵌入集成到 RAG 框架中,与采用通用嵌入的方法相比,我们的方法显著提高了检索准确性和代码生成质量。在 HPC Fortran2C++ 数据集上,我们的方法将平均 CodeBLEU 分数从 0.64 提升到 0.73,实现了 14% 的相对改进。在 Numerical Recipes 数据集上,我们观察到分数从 0.52 增加到 0.60,标志着 15% 的相对改进。重要的是,这些增益是在不对语言模型进行任何微调的情况下实现的,突显了我们方法的效率和实用性。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑