基于LLM的使用标识符替换的长代码翻译
LLM Based Long Code Translation using Identifier Replacement
AI总结:
针对LLM处理长代码翻译受限于上下文窗口的问题,提出一种结合标识符替换的零样本翻译方法,通过用占位符替换长标识符以降低token消耗,有效提升翻译准确性与效率。
摘要:
在软件开发领域,LLM已被用于自动化代码翻译等任务,即将一种编程语言的源代码翻译为另一种语言,同时保留其功能。然而,LLM在处理无法放入上下文窗口的长源代码时常常遇到困难,从而导致翻译不准确。为了解决这个问题,我们提出了一种结合标识符替换的新型零样本代码翻译方法。通过在翻译过程中将用户给定的长标识符替换为通用占位符,我们的方法减少了token数量和内存使用,使LLM能够专注于代码的逻辑结构,从而提高了长代码翻译的效率和成本效益。我们的实证结果表明,该方法保留了语法和层次信息,并生成了减少token的翻译结果。
英文摘要:
In the domain of software development, LLMs have been utilized to automate tasks such as code translation, where source code from one programming language is translated to another while preserving its functionality. However, LLMs often struggle with long source codes that don't fit into the context window, which produces inaccurate translations. To address this, we propose a novel zero-shot code translation method that incorporates identifier replacement. By substituting user-given long identifiers with generalized placeholders during translation, our method allows the LLM to focus on the logical structure of the code, by reducing token count and memory usage, which improves the efficiency and cost-effectiveness of long code translation. Our empirical results demonstrate that our approach preserves syntactical and hierarchical information and produces translation results with reduced tokens.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。