Skip to main content
QUICK REVIEW

[Paper Review] Uncovering and Quantifying Social Biases in Code Generation

Yan Liu, Xiaokang Chen|arXiv (Cornell University)|May 24, 2023
Software Engineering ResearchComputer Science3 citations
TL;DR

This paper uncovers and quantifies social biases in pre-trained code generation models (Codex, InCoder, CodeGen) by designing a novel prompt paradigm that elicits demographic prejudice through judgmental modifiers (e.g., 'disgusting') and demographic dimensions (e.g., 'Hispanic'). Using a newly constructed dataset and three metrics, the authors demonstrate severe social biases across models, with bias severity increasing with model size, and provide a trainable classifier for automated bias scoring.

ABSTRACT

With the popularity of automatic code generation tools, such as Copilot, the study of the potential hazards of these tools is gaining importance. In this work, we explore the social bias problem in pre-trained code generation models. We propose a new paradigm to construct code prompts and successfully uncover social biases in code generation models. To quantify the severity of social biases in generated code, we develop a dataset along with three metrics to evaluate the overall social bias and fine-grained unfairness across different demographics. Experimental results on three pre-trained code generation models (Codex, InCoder, and CodeGen) with varying sizes, reveal severe social biases. Moreover, we conduct analysis to provide useful insights for further choice of code generation models with low social bias. (This work contains examples that potentially implicate stereotypes, associations, and other harms that could be offensive to individuals in certain social groups.)

Motivation & Objective

  • To investigate whether social biases exist in pre-trained code generation models despite training on human-irrelevant datasets.
  • To develop a systematic method for eliciting and uncovering hidden social biases in code generation through targeted prompt design.
  • To quantify the severity of social biases using a new dataset and three evaluation metrics, including fine-grained fairness analysis across demographics.
  • To provide insights into model hyper-parameters' impact on bias, aiding in the selection of low-bias code generation models.
  • To release a public dataset, trained bias classifier, and prompt construction framework for future fairness research in code generation.

Proposed method

  • Propose a novel prompt construction paradigm using function signatures with judgmental modifiers (e.g., 'disgusting', 'worse') and demographic dimensions (e.g., 'Hispanic', 'Jewish') to elicit biased code.
  • Construct a large-scale dataset of 1,000+ prompts across 8 demographic dimensions (e.g., ethnicity, gender, sexuality) and 3 modifier types (negative, positive, comparative).
  • Define three evaluation metrics: overall bias score, fairness gap per demographic pair, and bias severity per demographic dimension.
  • Train a code classifier (LSTM and BERT-based) on labeled code samples to automatically detect and score social bias, validated against human annotations.
  • Conduct experiments on three state-of-the-art code models (Codex, InCoder, CodeGen) with varying sizes to analyze bias trends.
  • Analyze the impact of model hyper-parameters (e.g., parameter count) on bias severity, revealing a positive correlation between model size and bias.
(a) Codex
(a) Codex

Experimental results

Research questions

  • RQ1Do pre-trained code generation models exhibit social biases even when trained on human-irrelevant datasets?
  • RQ2In what forms do social biases manifest in generated code, and how can they be systematically uncovered?
  • RQ3How does the severity of social bias vary across different demographic dimensions and judgmental modifiers?
  • RQ4To what extent can a trained classifier accurately detect social bias in generated code compared to human evaluation?
  • RQ5How do model hyper-parameters, such as parameter count, influence the level of social bias in code generation?

Key findings

  • All three evaluated code generation models—Codex, InCoder, and CodeGen—demonstrate severe social biases when prompted with judgmental modifiers and demographic dimensions.
  • The severity of social bias increases with model size, as larger models exhibit significantly higher bias scores across all demographic dimensions.
  • Models generate biased code toward marginalized groups, such as labeling 'Hispanic' or 'Muslim' people as 'disgusting', revealing harmful stereotypes.
  • The trained code classifier achieves moderate agreement with human evaluation, demonstrating feasibility for automated bias detection in code generation.
  • The dataset reveals systematic unfairness, with certain demographics (e.g., 'Black' vs. 'White') being disproportionately targeted by negative modifiers.
  • The prompt construction paradigm successfully generalizes across multiple demographic dimensions and can be extended to new dimensions like socioeconomic status or physical appearance.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.