Table of Contents
Fetching ...

ShortCoder: Knowledge-Augmented Syntax Optimization for Token-Efficient Code Generation

Sicong Liu, Yanxian Huang, Mingwei Liu, Jiachi Chen, Ensheng Shi, Yuchi Ma, Hongyu Zhang, Yin Zhang, Yanlin Wang

TL;DR

ShortCoder tackles token-inefficiency in code generation by injecting knowledge into LLMs and applying AST-preserving syntax simplifications for Python. The approach combines ten syntax-level rules, a rule- and LLM-based data synthesis pipeline (ShorterCodeBench) yielding 828 validated <original, simplified> code pairs, and a LoRA-based fine-tuning regime that imbues conciseness. Experimental results on HumanEvalPlus show 18.1% token reduction and 18.1%-37.8% generation efficiency gains with maintained functional performance, outperforming prompt-based efficiency methods. The work demonstrates that syntax-aware code simplification plus knowledge injection can significantly reduce inference costs while preserving readability and correctness, with public release of data and code.

Abstract

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.

ShortCoder: Knowledge-Augmented Syntax Optimization for Token-Efficient Code Generation

TL;DR

ShortCoder tackles token-inefficiency in code generation by injecting knowledge into LLMs and applying AST-preserving syntax simplifications for Python. The approach combines ten syntax-level rules, a rule- and LLM-based data synthesis pipeline (ShorterCodeBench) yielding 828 validated <original, simplified> code pairs, and a LoRA-based fine-tuning regime that imbues conciseness. Experimental results on HumanEvalPlus show 18.1% token reduction and 18.1%-37.8% generation efficiency gains with maintained functional performance, outperforming prompt-based efficiency methods. The work demonstrates that syntax-aware code simplification plus knowledge injection can significantly reduce inference costs while preserving readability and correctness, with public release of data and code.

Abstract

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.
Paper Structure (36 sections, 2 equations, 11 figures, 4 tables)

This paper contains 36 sections, 2 equations, 11 figures, 4 tables.

Figures (11)

  • Figure 1: Overview of ShortCoder.
  • Figure 2: An example illustrating the multiple variable assignment simplification rule.
  • Figure 3: An example illustrating the conditional statement simplification rule.
  • Figure 4: An example illustrating multi-conditional statement simplification rule.
  • Figure 5: An example illustrating for loops simplification rule.
  • ...and 6 more figures