arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2309.14345cs.SEcs.AI
收藏

基于大语言模型的代码生成中的偏差测试与缓解

Bias Testing and Mitigation in LLM-based Code Generation

The University of Hong Kong(香港大学);King’s College London(伦敦国王学院);Shanghai Jiao Tong University(上海交通大学);Singapore Management University(新加坡管理大学);Tianjin University(天津大学)

Dong Huang, Jie M. Zhang, Qingwen Bu, Xiaofei Xie, Junjie Chen, Heming Cui

AI总结:

该研究针对LLM代码生成中的社会偏见问题,提出专用偏差测试框架,实证发现主流LLM生成代码普遍存在偏差,且测试执行反馈能有效降低偏差比例,优于常规提示工程策略。

摘要:

随着大语言模型(LLM)在软件开发生态中的应用日益广泛,一个紧迫的问题随之浮现:生成的代码是否包含与年龄、性别、种族相关的社会偏见与不公平现象?这一问题关乎依赖这些模型生成代码的软件应用的完整性、公平性与伦理基础,但现有文献对此研究尚不充分。本文提出了一种专门面向代码生成任务的新型偏差测试框架。基于该框架,我们对五种被广泛研究的大语言模型(即PALM-2-CodeChat-bison、Claude-instant-1、GPT-3.5-turbo、GPT-4-turbo和GPT-4)生成代码中的偏差开展了全面的实证研究。研究结果表明偏差现象普遍存在,例如这些大语言模型生成的代码中,有13.47%至49.10%存在性别相关的偏见行为。此外,我们研究了当前代码生成场景中常用的五种偏差缓解提示策略,即零样本、单样本、少样本,以及两种思维链(CoT)提示,分别测试了有无反馈驱动优化的效果。评估结果显示,直接使用提示工程策略缓解偏差的效果有限,但我们的测试执行反馈可大幅降低代码偏差比例(例如GPT-4的偏差比例从59.88%降至4.79%)。

英文摘要:

As the adoption of LLMs becomes more widespread in software coding ecosystems, a pressing issue has emerged: does the generated code contain social bias and unfairness, such as those related to age, gender, and race? This issue concerns the integrity, fairness, and ethical foundation of software applications that depend on the code generated by these models but are underexplored in the literature. This paper presents a novel bias testing framework that is specifically designed for code generation tasks. Based on this framework, we conduct an extensive empirical study on the biases in code generated by five widely studied LLMs (i.e., PALM-2-CodeChat-bison, Claude-instant-1, GPT-3.5-turbo, GPT-4-turbo, and GPT-4). Our findings reveal that biases are prevalent. For example, 13.47% to 49.10% of the codes generated by these LLMs have biased behaviors towards gender. Moreover, we study five bias mitigation prompt strategies that are commonly used in current code generation scenarios, i.e., zero-shot, one-shot, few-shot, and two Chain-of-Thought (CoT) prompts, with and without provided feedback-driven refinement. Our evaluation results illustrate that using direct prompt engineering strategies has limited effectiveness in mitigating bias, but our test execution feedback can help to reduce the ratio of code biases to a large extent (e.g., from 59.88% to 4.79% for GPT-4).

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

↑