Skip to main content
archive
Search Submit Donate Log in
Press Enter to search · Advanced search

Computer Science > Software Engineering

arXiv:2309.14345 (cs)
[Submitted on 3 Sep 2023 (v1), last revised 21 Mar 2025 (this version, v4)]

Title:Bias Testing and Mitigation in LLM-based Code Generation

Authors:Dong Huang, Jie M. Zhang, Qingwen Bu, Xiaofei Xie, Junjie Chen, Heming Cui
View a PDF of the paper titled Bias Testing and Mitigation in LLM-based Code Generation, by Dong Huang and 5 other authors
View PDF HTML (experimental)
Abstract: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).
Comments: Accepted by TOSEM
Subjects: Software Engineering (cs.SE); Artificial Intelligence (cs.AI)
Cite as: arXiv:2309.14345 [cs.SE]
  (or arXiv:2309.14345v4 [cs.SE] for this version)
  https://doi.org/10.48550/arXiv.2309.14345
arXiv-issued DOI via DataCite

Submission history

From: Huang Dong [view email]
[v1] Sun, 3 Sep 2023 07:14:49 UTC (1,375 KB)
[v2] Tue, 9 Jan 2024 09:19:17 UTC (2,368 KB)
[v3] Fri, 24 May 2024 13:03:49 UTC (3,776 KB)
[v4] Fri, 21 Mar 2025 06:36:33 UTC (4,542 KB)
Full-text links:

Access Paper:

    View a PDF of the paper titled Bias Testing and Mitigation in LLM-based Code Generation, by Dong Huang and 5 other authors
  • View PDF
  • HTML (experimental)
  • TeX Source
license iconview license

Current browse context:

cs.SE
< prev   |   next >
new | recent | 2023-09
Change to browse by:
cs
cs.AI

References & Citations

  • NASA ADS
  • Google Scholar
  • Semantic Scholar
Loading...

BibTeX formatted citation

Data provided by:

Bookmark

BibSonomy Reddit

Bibliographic and Citation Tools

Bibliographic Explorer (What is the Explorer?)
Connected Papers (What is Connected Papers?)
Litmaps (What is Litmaps?)
scite Smart Citations (What are Smart Citations?)

Code, Data and Media Associated with this Article

alphaXiv (What is alphaXiv?)
CatalyzeX Code Finder for Papers (What is CatalyzeX?)
DagsHub (What is DagsHub?)
Gotit.pub (What is GotitPub?)
Hugging Face (What is Huggingface?)
ScienceCast (What is ScienceCast?)

Demos

Replicate (What is Replicate?)
Hugging Face Spaces (What is Spaces?)
TXYZ.AI (What is TXYZ.AI?)

Recommenders and Search Tools

Influence Flower (What are Influence Flowers?)
CORE Recommender (What is CORE?)
  • Author
  • Venue
  • Institution
  • Topic

arXivLabs: experimental projects with community collaborators

arXivLabs is a framework that allows collaborators to develop and share new arXiv features directly on our website.

Both individuals and organizations that work with arXivLabs have embraced and accepted our values of openness, community, excellence, and user data privacy. arXiv is committed to these values and only works with partners that adhere to them.

Have an idea for a project that will add value for arXiv's community? Learn more about arXivLabs.

Which authors of this paper are endorsers? | Disable MathJax (What is MathJax?)
We gratefully acknowledge support from our major funders, member institutions, , and all contributors.
About · Help · Contact · Subscribe · Copyright · Privacy · Accessibility · Operational Status (opens in new tab)
Major funding support from
Simons Foundation Simons Foundation International Schmidt Sciences