arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2403.06503cs.PLcs.CLcs.LG
收藏

使用上下文无关文法自动生成 Python 程序

Automatic Generation of Python Programs Using Context-Free Grammars

New York University Abu Dhabi (NYUAD)(纽约大学阿布扎比分校);Ecole nationale Supérieure d’Informatique (ESI)(国立高等信息学院)

Kamel Yamani, Marwa Naïr, Riyadh Baghdadi

AI总结:

本文提出开源工具 TinyPy Generator,利用 BNF 形式的上下文无关文法递归生成构造即正确、复杂度可调的大规模 Python 程序,以支持语言模型训练及解释器、编译器稳健性验证。

摘要:

近年来,数据已成为新的黄金,是构建智能系统的强大工具。然而,获取高质量数据仍然具有挑战性,尤其是在代码方面。为解决这一问题,我们开发了 TinyPy Generator,这是一个使用上下文无关文法生成随机 Python 程序的工具。生成的程序在构造上即保证正确。我们的系统使用自定义产生式规则(采用 Backus-Naur Form(BNF)格式)递归生成代码。这使我们能够生成具有不同复杂程度的代码,从仅包含赋值的代码,到包含条件语句和循环的更复杂代码。我们提出的工具能够轻松实现大规模 Python 代码生成,可广泛应用于各类场景。TinyPy Generator 在机器学习领域尤其有用,可生成大量 Python 代码,用于训练 Python 语言模型。此外,研究编程语言的研究人员可以利用该工具为其实验创建数据集,从而帮助验证代码解释器或编译器的稳健性。与现有研究不同,我们已将实现开源。这允许用户根据自身需求进行定制,并将潜在用途扩展到其他语言。

英文摘要:

In recent years, data has emerged as the new gold, serving as a powerful tool for creating intelligent systems. However, procuring high-quality data remains challenging, especially for code. To address this, we developed TinyPy Generator, a tool that generates random Python programs using a context-free grammar. The generated programs are guaranteed to be correct by construction. Our system uses custom production rules (in the Backus-Naur Form (BNF) format) to recursively generate code. This allows us to generate code with different levels of complexity, ranging from code containing only assignments to more complex code containing conditionals and loops. Our proposed tool enables effortless large-scale Python code generation, beneficial for a wide range of applications. TinyPy Generator is particularly useful in the field of machine learning, where it can generate substantial amounts of Python code for training Python language models. Additionally, researchers who are studying programming languages can utilize this tool to create datasets for their experiments, which can help validate the robustness of code interpreters or compilers. Unlike existing research, we have open-sourced our implementation. This allows customization according to user needs and extends potential usage to other languages.

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

↑