[Paper Review] ShortCoder: Knowledge-Augmented Syntax Optimization for Token-Efficient Code Generation
ShortCoder uses 10 Python syntax simplification rules, a rule-based plus LLM-guided data synthesis pipeline, and LoRA fine-tuning to produce concise, semantically correct code, achieving about 18.1% token reduction with competitive performance on HumanEval.
Code generation tasks aim to automate the conversion of user requirements into executable code, significantly reducing manual development efforts and enhancing software productivity. The emergence of large language models (LLMs) has significantly advanced code generation, though their efficiency is still impacted by certain inherent architectural constraints. Each token generation necessitates a complete inference pass, requiring persistent retention of contextual information in memory and escalating resource consumption. While existing research prioritizes inference-phase optimizations such as prompt compression and model quantization, the generation phase remains underexplored. To tackle these challenges, we propose a knowledge-infused framework named ShortCoder, which optimizes code generation efficiency while preserving semantic equivalence and readability. In particular, we introduce: (1) ten syntax-level simplification rules for Python, derived from AST-preserving transformations, achieving 18.1% token reduction without functional compromise; (2) a hybrid data synthesis pipeline integrating rule-based rewriting with LLM-guided refinement, producing ShorterCodeBench, a corpus of validated tuples of original code and simplified code with semantic consistency; (3) a fine-tuning strategy that injects conciseness awareness into the base LLMs. Extensive experimental results demonstrate that ShortCoder consistently outperforms state-of-the-art methods on HumanEval, achieving an improvement of 18.1%-37.8% in generation efficiency over previous methods while ensuring the performance of code generation.
Motivation & Objective
- Reduce token usage and improve generation efficiency in code generation without sacrificing correctness or readability.
- Leverage AST-preserving syntax simplification rules to create a high-quality concise-code corpus.
- Inject domain knowledge into LLMs via efficient fine-tuning to enable zero-shot concise code generation.
Proposed method
- Design ten AST-preserving Python syntax simplification rules (Table I) to reduce tokens by 18.1% without functional loss.
- Build ShorterCodeBench via rule-based and LLM-guided synthesis to create <original_code, simplified_code> pairs (828 validated pairs).
- Fine-tune a Code LLM with LoRA to inject conciseness knowledge, enabling zero-shot concise code generation.
- Perform rule-based and LLM-assisted data construction to generate training pairs for knowledge injection.
- Evaluate using HumanEval with pass@k metrics and efficiency metrics (tokens, latency).
- Compare against baselines (CodeLlama-Instruct, CodeGen, DeepSeek-Coder) to assess efficiency and performance.
Experimental results
Research questions
- RQ1RQ1: How does ShortCoder perform relative to baseline code generation models on functional correctness and efficiency?
- RQ2RQ2: How does ShortCoder's efficiency compare to prompt-based efficiency enhancement techniques?
- RQ3RQ3: How readable and concise is the code produced by ShortCoder versus baselines (human evaluation)?
Key findings
- ShortCoder achieves 18.1% to 37.8% reduction in generated tokens compared with baselines.
- On HumanEval, ShortCoder attains Pass@1=0.612, Pass@10=0.764, Pass@100=0.967 while generating 162.02 tokens on average (GenTokens).
- ShortCoder outperforms baselines in efficiency metrics and approaches state-of-the-art performance with lower token cost.
- Fine-tuning with LoRA enables knowledge injection of conciseness patterns with reduced trainable parameters.
- Rule-guided fine-tuning consistently yields better efficiency than prompt-based methods, reducing average problem latency by 25%-64%.
- ShortCoder's approach maintains or improves functional correctness while producing shorter, more readable code.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.