Lune

ACL2025Top-tier venue

Rethinking Repetition Problems of LLMs in Code Generation

Yihong Dong, Yuchen Liu, Xue Jiang, Bin Gu, Zhi Jin, Ge Li

Abstract

With the advent of neural language models, the performance of code generation has been significantly boosted. However, the problem of repetitions during the generation process continues to linger. Previous work has primarily focused on content repetition, which is merely a fraction of the broader repetition problem in code generation. A more prevalent and challenging problem is structural repetition. In structural repetition, the repeated code appears in various patterns but possesses a fixed structure, which can be inherently reflected in grammar. In this paper, we formally define structural repetition and propose an efficient decoding approach called RPG, which stands for Repetition Penalization based on Grammar, to alleviate the repetition problems in code generation for LLMs. Specifically, RPG first leverages grammar rules to identify repetition problems during code generation, and then strategically decays the likelihood of critical tokens that contribute to repetitions, thereby mitigating them in code generation. To facilitate this study, we construct a new dataset CodeRepetEval to comprehensively evaluate approaches for mitigating the repetition problems in code generation. Extensive experimental results demonstrate that RPG substantially outperforms the best-performing baselines on CodeRepetEval dataset as well as HumanEval and MBPP benchmarks, effectively reducing repetitions and enhancing the quality of generated code. 1

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

7 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement Learning cites CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
  • EfficientEdit: Accelerating Code Editing via Edit-Oriented Speculative Decoding cites CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
  • EfficientEdit: Accelerating Code Editing via Edit-Oriented Speculative Decoding cites Self-Instruct: Aligning Language Models with Self-Generated Instructions
  • Escaping Mode Collapse in LLM Generation via Geometric Regulation cites The Curious Case of Neural Text Degeneration
  • MARD: Module-Aware Reasoning Distillation for Language Models with Adaptive Supervision cites Self-Instruct: Aligning Language Models with Self-Generated Instructions
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers7

  1. EfficientEdit: Accelerating Code Editing via Edit-Oriented Speculative DecodingPeiding Wang, Li Zhang, Fang Liu, Yinghao Zhu et al.ASE 2025 · 3 citations
  2. Task-and-Model-Aware Fractal-Consistency for Efficient LLM ReasoningZiqiu Luo, Jianmin Liu, Yukai Miao, Li Chen et al.ICML 2026
  3. Escaping Mode Collapse in LLM Generation via Geometric RegulationXin Du, Kumiko Tanaka-IshiiICML 2026
  4. MARD: Module-Aware Reasoning Distillation for Language Models with Adaptive SupervisionWenqi Yang, Jianjun Li, Zhibo Zhang, Mingqian Ding et al.ACL 2026
  5. OvisOCR: End-to-End Document Parsing via Aligning Specialized Perception with General ReasoningJun-Peng Jiang, Shiyin Lu, An-Yang Ji, Yinglun Li et al.ICML 2026

Builds on18

  1. The Curious Case of Neural Text DegenerationAri Holtzman, Jan Buys, Li Du, Maxwell Forbes et al.ICLR 2020 · 4,112 citations
  2. Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code GenerationJiawei Liu, Chunqiu Steven Xia, Yuyao Wang, Lingming ZhangNeurIPS 2023 · 2,317 citations
  3. CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and GenerationYue Wang, Weishi Wang, Shafiq R. Joty, Steven C. H. HoiEMNLP 2021 · 1,224 citations
  4. CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement LearningHung Le, Yue Wang, Akhilesh Deepak Gotmare, Silvio Savarese et al.NeurIPS 2022 · 571 citations
  5. Self-Instruct: Aligning Language Models with Self-Generated InstructionsYizhong Wang, Yeganeh Kordi, Swaroop Mishra, Alisa Liu et al.ACL 2023 · 540 citations

Related papers

  1. Duplicate-Aware Controlled Code Generation: Enhancing Copyright Protection with Targeted Reordering Beam Search in LLMsJunbo Fu, Guoshuai Zhao, Linkang Yang, Yunqi Mi et al.ACL Findings 2026
  2. A Theoretical Analysis of the Repetition Problem in Text GenerationZihao Fu, Wai Lam, Anthony Man-Cho So, Bei ShiAAAI 2021 · 114 citations
  3. Learning to Break the Loop: Analyzing and Mitigating Repetitions for Neural Text GenerationJin Xu, Xiaojiang Liu, Jianhao Yan, Deng Cai et al.NeurIPS 2022 · 135 citations
  4. LLM Hallucinations in Practical Code Generation: Phenomena, Mechanism, and MitigationZiyao Zhang, Chong Wang, Yanlin Wang, Ensheng Shi et al.ISSTA 2025 · 53 citations
  5. Mitigating the Learning Bias towards Repetition by Self-Contrastive Training for Open-Ended GenerationJian Guan, Minlie HuangACL Findings 2023 · 1 citation
Dusk over the sea between two cliffs drawn in fine vertical lines