Optimizing Class-Level Code Generation: Enhancing In-Context Learning in Large Language Models with Pruning Techniques
Year: 2025
Type: conference-paper
Abstract: Recent advances in large language models (LLMs) have demonstrated strong capabilities in code generation. However, most studies focus on method-level generation, leaving the effectiveness of LLMs on more complex class-level code generation underexplored. To address this, the ClassEval benchmark has been proposed, but constructing effective prompts for class-level tasks remains challenging due to longer input sequences and the inherent context length limitations of LLMs (e.g., 4096 tokens for GPT-3.5 and 8192 for GPT-4). We propose an attention-guided pruning strategy that selectively removes less informative code tokens, allowing more representative examples to be included in the prompt and thus providing richer semantic context for LLMs. Experiments on the ClassEval dataset using GPT-3.5 demonstrate that our strategy significantly outperforms random pruning, achieving 4.2%, 10.2%, and 13% higher accuracy in class-level code generation. Further analysis shows that pruning up to 40% of tokens while including four additional examples maximizes LLM performance, enabling more accurate and coherent class-level code generation.
Institution: National University of Defense Technology
Language: English
Subfield: Information Systems
Field: Computer Science
Domain: Physical Sciences
Open Access status: hybrid
OpenAlex ID: W7127599135
