发现大模型生成代码算法多样性低,提出新方法评估并提升多样性。
How Diversely Can Language Models Solve Problems? Exploring the Algorithmic Diversity of Model-Generated Code
- 用代码聚类与相似性度量,量化模型生成解的算法多样性。
- 小模型、低温度下生成代码算法单一,人类代码多样性更高。
- 混合不同模型+调高温度可显著提升多样性,适合优化生成策略者。
语言模型在从自然语言需求生成代码方面表现优异,但现有研究忽视了生成代码的算法多样性这一关键评价指标。本文提出系统化评估框架,引入基于代码理解与推理能力的聚类方法,构建衡量生成解中算法数量的多维指标。通过对比人类代码与模型生成代码,定量分析模型规模、温度、指令微调及问题复杂度对多样性的影响。结果表明,模型生成代码算法多样性显著偏低,且该问题长期被忽视。进一步实验显示,融合异构模型输出并提高采样温度至1.0以上,可有效提升多样性,尽管存在功能正确性下降风险。为推动该方向研究,作者开源代码与数据集。
原文摘要 · Abstract (English)
Language models (LMs) have exhibited impressive abilities in generating code from natural language requirements. In this work, we highlight the diversity of code generated by LMs as a critical criterion for evaluating their code generation capabilities. There is a lack of studies focused on assessing the diversity of generated code, which overlooks its importance in code LMs. Therefore, we propose a systematic approach to evaluate code diversity, introducing various metrics with inter-code similarity. Specifically, we introduce code clustering methods that leverages LMs' capabilities in code understanding and reasoning, resulting in a set of metrics that represent the number of algorithms in model-generated solutions. We extensively investigate the property of model-generated solutions by contrasting them with human-written ones and quantifying the impact of various factors on code diversity: model size, temperature, instruction tuning, and problem complexity. Our analysis demonstrates that model-generated solutions exhibit low algorithmic diversity, which was neglected by the research community. Moreover, we explore methods to increase code diversity by combining solutions from different models and increasing sampling temperatures. Our findings highlight that code diversity can be enhanced with the help of heterogeneous models and setting temperature beyond 1.0 that has not been fully explored due to the functional correctness degradation. To facilitate our research direction, we publicly share our code and datasets through open-source repositories.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。