Code Copycat Conundrum: Demystifying Repetition in LLM-based Code Generation

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Liu, Mingwei, Li, Juntao, Wang, Ying, Du, Xueying, Ou, Zuoyu, Chen, Qiuyuan, An, Bingxu, Wei, Zhao, Xu, Yong, Zou, Fangming, Peng, Xin, Lou, Yiling
Format: Preprint
Published: 2025
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866917987801366528
author Liu, Mingwei
Li, Juntao
Wang, Ying
Du, Xueying
Ou, Zuoyu
Chen, Qiuyuan
An, Bingxu
Wei, Zhao
Xu, Yong
Zou, Fangming
Peng, Xin
Lou, Yiling
author_facet Liu, Mingwei
Li, Juntao
Wang, Ying
Du, Xueying
Ou, Zuoyu
Chen, Qiuyuan
An, Bingxu
Wei, Zhao
Xu, Yong
Zou, Fangming
Peng, Xin
Lou, Yiling
contents Despite recent advances in Large Language Models (LLMs) for code generation, the quality of LLM-generated code still faces significant challenges. One significant issue is code repetition, which refers to the model's tendency to generate structurally redundant code, resulting in inefficiencies and reduced readability. To address this, we conduct the first empirical study to investigate the prevalence and nature of repetition across 19 state-of-the-art code LLMs using three widely-used benchmarks. Our study includes both quantitative and qualitative analyses, revealing that repetition is pervasive and manifests at various granularities and extents, including character, statement, and block levels. We further summarize a taxonomy of 20 repetition patterns. Building on our findings, we propose DeRep, a rule-based technique designed to detect and mitigate repetition in generated code. We evaluate DeRep using both open-source benchmarks and in an industrial setting. Our results demonstrate that DeRep significantly outperforms baselines in reducing repetition (with an average improvements of 91.3%, 93.5%, and 79.9% in rep-3, rep-line, and sim-line metrics) and enhancing code quality (with a Pass@1 increase of 208.3% over greedy search). Furthermore, integrating DeRep improves the performance of existing repetition mitigation methods, with Pass@1 improvements ranging from 53.7% to 215.7%.
format Preprint
id arxiv_https___arxiv_org_abs_2504_12608
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Code Copycat Conundrum: Demystifying Repetition in LLM-based Code Generation
Liu, Mingwei
Li, Juntao
Wang, Ying
Du, Xueying
Ou, Zuoyu
Chen, Qiuyuan
An, Bingxu
Wei, Zhao
Xu, Yong
Zou, Fangming
Peng, Xin
Lou, Yiling
Software Engineering
Artificial Intelligence
Despite recent advances in Large Language Models (LLMs) for code generation, the quality of LLM-generated code still faces significant challenges. One significant issue is code repetition, which refers to the model's tendency to generate structurally redundant code, resulting in inefficiencies and reduced readability. To address this, we conduct the first empirical study to investigate the prevalence and nature of repetition across 19 state-of-the-art code LLMs using three widely-used benchmarks. Our study includes both quantitative and qualitative analyses, revealing that repetition is pervasive and manifests at various granularities and extents, including character, statement, and block levels. We further summarize a taxonomy of 20 repetition patterns. Building on our findings, we propose DeRep, a rule-based technique designed to detect and mitigate repetition in generated code. We evaluate DeRep using both open-source benchmarks and in an industrial setting. Our results demonstrate that DeRep significantly outperforms baselines in reducing repetition (with an average improvements of 91.3%, 93.5%, and 79.9% in rep-3, rep-line, and sim-line metrics) and enhancing code quality (with a Pass@1 increase of 208.3% over greedy search). Furthermore, integrating DeRep improves the performance of existing repetition mitigation methods, with Pass@1 improvements ranging from 53.7% to 215.7%.
title Code Copycat Conundrum: Demystifying Repetition in LLM-based Code Generation
topic Software Engineering
Artificial Intelligence
url https://arxiv.org/abs/2504.12608