arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2605.00382cs.SEcs.AIcs.SI
收藏

LLM生成代码中的社会偏见:基准测试与缓解

Social Bias in LLM-Generated Code: Benchmark and Mitigation

Concordia University(康科德大学);Lassonde School of Engineering, York University(York大学工程学院)

Fazle Rabbi, Lin Ling, Song Wang, Jinqiu Yang

AI总结:

本文研究LLM生成代码中的社会偏见问题,通过SocialBias-Bench基准测试发现四种主流模型存在严重偏见,提出Fairness Monitor Agent (FMA)有效降低偏见并提升代码正确性。

摘要:

大型语言模型(LLMs)正被越来越多地用于生成人类中心应用中的代码,其中民主公平性至关重要。然而,现有评估几乎只关注功能正确性,导致LLM生成代码中的社会偏见未被充分考察。通过扩展我们对Solar的先前工作,我们使用包含343个现实世界编码任务的SocialBias-Bench基准进行全面实证研究。我们评估了四种主流LLMs,发现所有模型都存在严重偏见,代码偏见评分高达60.58%。我们进一步表明,标准提示级别干预,如链式推理和公平性人格分配,反而加剧了偏见。我们还探讨了结构化多代理软件过程框架是否能改善公平性,发现结构化管道在早期角色正确界定代码应考虑和不应考虑的内容时能减少偏见。然而,将显式公平性指令添加到所有代理角色中会产生比不提供更差的结果,表明责任分散未被解决。为了解决这些限制,我们提出了公平性监控代理(FMA),它可无缝插入任何现有代码生成管道中,无需修改。FMA分析任务描述以确定应考虑或限制的属性,然后通过迭代审查过程检测并纠正违规行为,无需可执行测试套件。在所有343个任务上评估,FMA将偏见降低了65.1%,比单独使用开发代理提高了65.1%,并使功能正确性从75.80%提升到83.97%,优于所有其他研究方法。

英文摘要:

Large Language Models (LLMs) are increasingly deployed to generate code for human-centered applications where demographic fairness is critical. However, existing evaluations focus almost exclusively on functional correctness, leaving social bias in LLM-generated code largely unexamined. Extending our prior work on Solar, we conduct a comprehensive empirical study using SocialBias-Bench, a benchmark of 343 real-world coding tasks spanning seven demographic dimensions. We evaluate four prominent LLMs and find severe bias across all models, with Code Bias Scores reaching up to 60.58%. We further show that standard prompt-level interventions, such as Chain-of-Thought reasoning and fairness persona assignment, inadvertently amplify bias rather than reduce it. We then investigate whether structured multi-agent software process frameworks can improve fairness, finding that structured pipelines reduce bias when early roles correctly scope what the code should and should not consider. However, adding explicit fairness instructions to all agent roles produces worse outcomes than providing none, suggesting that diffused responsibility goes unaddressed. To address these limitations, we propose the Fairness Monitor Agent (FMA), a modular component that plugs into any existing code generation pipeline without modifying it. FMA analyzes the task description to determine which attributes should be considered or restricted, then detects and corrects violations through an iterative review process, without requiring an executable test suite. Evaluated on all 343 tasks, FMA reduces bias by 65.1% compared to a developer agent alone and improves functional correctness from 75.80% to 83.97%, outperforming all other studied approaches.

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

↑