Code Copycat Conundrum: Demystifying Repetition in LLM-based Code Generation
Not on the map. Why?
Abstract (arXiv)
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%.
Key facts. Cited by 4 papers in the map (data through 7 Oct 2026). Builds on 28 of its 35 references that are in the map. First posted on arXiv 17 Apr 2025.
Builds on
28 of 35 references.
References · 28
- 2023LLaMA: Open and Efficient Foundation Language Modelscited by 13,958
- 2021Evaluating Large Language Models Trained on Codecited by 8,053
- 2021Program Synthesis with Large Language Modelscited by 3,509
- 2019The Curious Case of Neural Text Degenerationcited by 2,881
- 2023Code Llama: Open Foundation Models for Codecited by 2,105
- 2023Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generationcited by 1,332
- 2024DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligencecited by 1,154
- 2023StarCoder: may the source be with you!cited by 790
- 2019CTRL: A Conditional Transformer Language Model for Controllable Generationcited by 754
- 2024BigCodeBench: Benchmarking Code Generation with Diverse Function Calls and Complex Instructionscited by 527
- 2024StarCoder 2 and The Stack v2: The Next Generationcited by 484
- 2023RepoCoder: Repository-Level Code Completion Through Iterative Retrieval and Generationcited by 357
16 more
- 2017Beam Search Strategies for Neural Machine Translationcited by 232
- 2022A Contrastive Framework for Neural Text Generationcited by 224
- 2023CrossCodeEval: A Diverse and Multilingual Benchmark for Cross-File Code Completioncited by 181
- 2023SantaCoder: don't reach for the stars!cited by 169
- 2022Multi-lingual Evaluation of Code Generation Modelscited by 158
- 2022Large Language Models are Few-shot Testers: Exploring LLM-based General Bug Reproductioncited by 110
- 2024Beyond Functional Correctness: Exploring Hallucinations in LLM-Generated Codecited by 106
- 2022Learning to Break the Loop: Analyzing and Mitigating Repetitions for Neural Text Generationcited by 90
- 2022Automated Repair of Programs from Large Language Modelscited by 71
- 2024EvoCodeBench: An Evolving Code Generation Benchmark Aligned with Real-World Code Repositoriescited by 71
- 2024Bugs in Large Language Models Generated Code: An Empirical Studycited by 59
- 2023Explainable Automated Debugging via Large Language Model-driven Scientific Debuggingcited by 40
- 2023Repetition In Repetition Out: Towards Understanding Neural Text Degeneration from the Data Perspectivecited by 39
- 2024TESTEVAL: Benchmarking Large Language Models for Test Case Generationcited by 38
- 2023Can Large Language Models Write Good Property-Based Tests?cited by 30
- 2024Beyond Functional Correctness: Investigating Coding Style Inconsistencies in Large Language Modelscited by 15
Built on by
Citing papers per year: 2025: 4.
4 papers.
- 2025An Empirical Study of Agent Developer Practices in AI Agent Frameworkscited by 14
- 2025EffiReasonTrans: RL-Optimized Reasoning for Code Translationcited by 5
- 2025Code Reasoning for Software Engineering Tasks: A Survey and A Call to Actioncited by 4
- 2025Lifecycle-Aware code generation: Leveraging Software Engineering Phases in LLMscited by 0
- 2025An Empirical Study of Agent Developer Practices in AI Agent Frameworks1 Dec 2025
- 2025Lifecycle-Aware code generation: Leveraging Software Engineering Phases in LLMs28 Oct 2025
- 2025EffiReasonTrans: RL-Optimized Reasoning for Code Translation21 Oct 2025
- 2025Code Reasoning for Software Engineering Tasks: A Survey and A Call to Action16 Jun 2025