Editor’s introduction
AST-based methods improve Java summary quality by 37% with significant token reduction but degrade in Python by up to 49%. Function signatures perform poorly in Java but excel in Python, achieving 83% token reduction while preserving quality. CrystalBLEU shows consistent cross-language performance with 60–72% token reduction. These results indicate that token selection strategies are highly language-dependent, challenging the assumption of universal optimization techniques. The study emphasizes that semantic relevance of tokens, not just volume, drives performance. FLOPs are not reported due to constant training instance counts across conditions, which renders them irrelevant for comparing token-level optimizations in this setup.
Introduction
Automated code summarization seeks to generate a Natural Language (NL) description of software artifacts, for purposes such as (re)documentation or supporting code comprehension. In this context, Large Language Models (LLMs) have shown remarkable capability to generate natural-language summaries from source code (code-to-NL) by processing code as sequences of tokens. However, this success hinges on the availability of high-performance hardware that can efficiently handle the vast number of tokens and parameters required for model training and inference.
Hardware accelerators—such as Graphics Processing Units (GPUs), Tensor Processing Units (TPUs), or custom AI chips—play a critical role in meeting the computational demands of modern LLMs. Nevertheless, relying solely on hardware advancements is neither scalable nor sustainable. Recent studies warn that the marginal gains from brute-force hardware scaling are diminishing, and the environmental cost of ever-larger models continues to rise. In addition to computational concerns, training datasets must be vast, diverse, and richly annotated–especially in domains like code intelligence. Scaling dataset size typically takes two forms: increasing the number of training examples or expanding the token footprint of individual inputs. Both approaches result in a large volume of tokens being processed during training, which amplifies memory requirements, energy consumption, and training time.
To improve code summarization, Shi et al. introduced CAT, a heuristic-driven method that cleans datasets by removing structurally defective examples such as trivial methods or summaries that simply mirror code. While filtering surface-level flaws, CAT overlooks deeper semantic inconsistencies between code and comments. Vitale et al. observed that many pairs passing CAT remain misaligned, often because developers neglect to update documentation when code changes (cf. Steidl et al. ). These misalignments weaken supervision, confuse models during training, and inflate computational costs. To address this, Vitale et al. employed the SIDE metric, which evaluates semantic alignment and prunes noisy examples. Their results revealed that removing up to half of the data preserved performance, underscoring that dataset quality outweighs sheer size.
This shift from quantity to quality motivates our own hypothesis: if dataset-level pruning already improves learning, then finer-grained control at the token level may yield even greater benefits. In particular, we argue that not all tokens contribute equally to the learning process—many are syntactically necessary but semantically uninformative for summarization. These low-utility tokens dilute meaningful training signals, inflate computational costs, and hinder the model’s ability to generate concise and insightful summaries.
To address the challenge of low-utility tokens, we propose token-level data optimization methods that identify and retain only the most informative content while discarding redundant or semantically weak tokens. These techniques leverage syntactical source code manipulation and equivalent code representations to transform the original input before feeding it to the model. Our goal is to strategically reduce training token volume, enhancing model efficiency while potentially improving summary quality. We present three distinct strategies: (i) CrystalBLEU-guided optimization, (ii) FS-based optimization, and (iii) AST-based optimization.
Optimizing Code Summarization Training Dataset via Token-Level Optimization Techniques
Motivated by recent calls for data-centric optimization in code-related tasks, we introduce three reduction methods grounded in fine-grained token editing and domain-specific transformations. These methods are guided by the hypothesis that semantically irrelevant tokens can be removed without impairing the model’s ability to generate meaningful summaries. In practice, filtering out such tokens preserves core semantics while reducing redundancy and noise. This principle applies both to deliberate pruning—where low-utility tokens are explicitly targeted—and to structural transformations that implicitly eliminate them. For instance, converting code into its Abstract Syntax Tree (AST) representation naturally discards superficial syntactic tokens (e.g., delimiters, formatting artifacts) while retaining essential structure.
Abstract Syntax Tree (AST) provides a structured, tree-based representation of source code based on the syntax and grammar of the programming language. Leaf nodes (terminals) denote low-level elements such as variable names and types, while non-terminals represent higher-level constructs including loops, expressions, and declarations. Due to its conciseness and structural fidelity, the AST is widely used as a proxy for raw code in downstream tasks. In this work, we utilize ASTs as input representations for code summarization, replacing the raw source code.
CrystalBLEU is a widely recognized evaluation metric designed to improve distinguishability in code summarization by discounting trivially shared common n-gram tokens that appear frequently across examples and contribute little to semantic differentiation. The core idea behind the metric is straightforward: first, identify the set of trivially shared n-grams, and then compute a modified BLEU score that excludes their influence. Inspired by this principle, our token reduction strategy utilizes CrystalBLEU to identify and eliminate trivially shared n-gram tokens from the input data, thereby reducing the overall training data volume while preserving semantically influential content for training.
To rigorously assess the impact of these reductions, we rely on Shannon entropy rather than a raw token count. Simply shortening sequences does not necessarily make them more efficient or more informative: two inputs of identical length can differ greatly in the amount of information they encode. Shannon entropy–a measure of the average information or uncertainty contained in a distribution of tokens–captures this nuance by quantifying how much meaningful content is carried by the retained sequence.
This distinction is central to our setting: in code summarization, the goal is not just to reduce sequence length but to retain those tokens most critical for guiding the model toward concise and accurate summaries. Entropy reduction, therefore, serves as a principled indicator of effective compression, where redundant or boilerplate elements are removed while semantically meaningful cues are preserved. Empirical evidence supports this interpretation: models trained on entropy-optimized inputs converge faster, require fewer computational resources, and produce summaries that maintain–or sometimes even improve–overall informativeness, as corroborated by presented qualitative examples (Section 8).
Results
The Function Signature-based optimization retains only 30.49% of tokens while reducing entropy by 29.82%. On CoderEval, BLEU decreases modestly from 6.32 (baseline) to 6.23–a minimal 1.4% decline despite eliminating 69.51% of input tokens. Similar patterns emerge for ROUGE-L and METEOR, which show proportionally small degradation relative to the substantial compression achieved. On the Mastropaolo et al. benchmark, this method maintains identical BLEU performance (1.88) to CrystalBLEU-guided optimization (the second-best technique) while showing slight reductions in ROUGE-L and METEOR scores.
Despite the expected performance trade-offs relative to the baseline, an intriguing cross-benchmark pattern emerges. Mastropaolo exhibits substantially lower baseline scores across all metrics (BLEU: 1.80 vs. 6.32 on CoderEval), indicating a considerably more challenging evaluation context—likely due to increased code complexity or reduced documentation quality. This observation aligns with our earlier statement regarding input complexity: Mastropaolo methods average 167.77 tokens, compared to CoderEval’s 69.00 tokens, representing 2.4 times more structural and lexical information that models must process to generate comparably sized summaries (15.00 vs. 12.24 tokens on average). Therefore, it looks like under these demanding conditions, compression-based approaches demonstrate unexpected robustness and, in some cases, improvement. This counterintuitive finding suggests that strategic token reduction may actually enhance model performance on structurally complex code. By distilling inputs to their most semantically dense components, compression techniques appear to help the model filter noise and focus on core semantic patterns that drive accurate summarization.
Finally, examining entropy reduction across semantically filtered data reveals a clear divergence: on CoderEval, AST’s moderate compression (44.31% token retention) achieves the strongest performance (BLEU: 7.04), whereas on Mastropaolo’s benchmark, optimal results are obtained without any token-reduction methods applied post-filtering. This outcome aligns with our earlier observations, underscoring that for complex, challenging code, preserving complete lexical and structural information is critical. Further compression beyond semantic filtering risks eliminating subtle cues necessary for accurate summarization.
These statistical patterns reinforce our primary findings: semantic filtering can serve as a foundation for aggressive token compression without compromising quality, and the type of tokens preserved (structural vs. lexical) is more important than the compression rate alone. Complete statistical results are available in our replication package.
Results
On PyBench, providing the model with only Python signatures as input also yields optimal results. We attribute this to the higher quality level of our benchmark resulting from the filtering process. This finding inverts the pattern observed in Java: while Function Signatures showed the steepest quality trade-offs for Java, they prove most effective for Python. This contrast suggests that Python’s more standardized and semantically rich function signatures contain sufficient information for accurate summarization, whereas Java’s more verbose syntax may require additional structural context.
CrystalBLEU provides moderate compression with 21.72% entropy reduction, retaining 39.24% of tokens. On CoderEval-Python, this yields a BLEU of 2.08 (80% of baseline), while on PyBench it achieves 1.95–a notable improvement over the challenging 1.74 baseline (112%). The consistent pattern of improvement on the harder PyBench dataset reinforces the observation from Java: aggressive token reduction can actually enhance model performance when dealing with complex or poorly documented code by helping models focus on essential signals rather than noise.
CrystalBLEU shows similar patterns with 21.97% entropy reduction (retaining 37.14% of tokens), achieving competitive performance on CoderEval (BLEU: 2.65, 86% of baseline) and maintaining quality on PyBench (BLEU: 1.99, 74% of baseline). However, AST continues to struggle–BLEU drops to 1.56 on CoderEval (51% of baseline) and collapses to 0.59 on PyBench, with ROUGE-L falling to 4.35 from 21.67 (80% degradation). This consistent AST underperformance across both standalone and cascaded settings, on both evaluation benchmarks, reveals a fundamental incompatibility between Python’s AST representation and the summarization task as implemented in our framework.
Taken together, these patterns suggest clear guidance for Python code summarization systems: Function Signature extraction emerges as the dominant strategy, offering 83% token reduction while maintaining or improving quality across diverse evaluation contexts. CrystalBLEU provides a fallback option with 60-63% compression and acceptable quality trade-offs when function signatures alone prove insufficient. AST-based optimization should be avoided for Python summarization, given its consistent catastrophic failures across all experimental conditions. Importantly, these recommendations stand in stark contrast to Java guidance (where AST dominated), underscoring the critical importance of language-specific validation before deploying token optimization strategies in production systems. Complete statistical results are available in our replication package.
Qualitative Examples
To illustrate the practical impact of token optimization strategies beyond aggregate metrics, we present a representative example of code summarization from our Python evaluation that demonstrates how different token reduction methods fundamentally alter the semantic content captured by trained models.
Function Signature extraction, retaining only [“def”, “_get_err_indices”, ”(”, “self”, ”,”, “coord_name”, ”)”, ”:”] (representing the method name and parameters), produces: “Get the indices for all possible errors”–the most semantically accurate summary despite extreme token reduction. The function name get_err_indices explicitly encodes the retrieval action and target (error indices), while the parameter coord_name signals filtering based on coordinate names. This combination proves sufficient for the model to accurately infer the function’s purpose. The slight generalization to “all possible errors” demonstrates reasonable semantic inference from limited but highly informative tokens. This example illustrates why Function Signatures excel in Python: descriptive naming conventions and meaningful parameter names encode functional intent that proves more valuable than implementation details.
CrystalBLEU optimization, retaining tokens like [“_get_err_indices”,…, “ind”, “dim”, “err_indices”], generates: “Get the list of files with the given name”–a semantically plausible but functionally incorrect summary. By preserving variable names (ind, dim, err_indices) while removing structural keywords (def, return, for, if), CrystalBLEU retains lexical elements but strips away the control flow that defines the function’s logic. Without keywords like return indicating what the function produces, or for/if revealing the filtering operation, the model misinterprets the retained tokens as file-related operations–possibly influenced by common patterns where get combined with list-like variables suggests file retrieval. This failure demonstrates that frequency-based pruning can eliminate structurally essential tokens (such as return, for, and if) that, despite being common, provide critical context for understanding program semantics.
AST-based representation, transforming the code into abstract tokens like [“Module”, “FunctionDef”,…, “BinOp”, “Name”, “Name”, “Return”, “Name”], generates: “Parse a source file without doing any semantic analysis”–a summary completely unrelated to the actual functionality. The AST preserves high-level syntactic structure (module, function definition, binary operation, return statement) but abstracts away all identifier information. Without access to tokens like get_err_indices, coord_name, or err_indices, the model cannot determine what the function operates on or returns. The hallucinated functionality (“parse a source file”) likely reflects the model’s attempt to match structural patterns (functions with iteration and conditionals) to memorized templates from training data, resulting in a semantically disconnected prediction.
When trained on full code tokens, the model generates: “Creates a formatted string representation of the event”—an accurate summary that captures both the formatting action and the target (event). With access to complete implementation details, including type information (String, LoggingEvent), method names (format, toString), and control structures (if, while), the model successfully infers the method’s purpose.
Implications
Our findings yield several important implications for code summarization research and practice, spanning representation design, cross-language generalization, and data-centric optimization strategies. The contrast with our Java results–where AST consistently dominated across all metrics–reveals fundamental differences in how languages encode semantic information. Java’s verbose syntax and structured type systems mean that AST representations capture class hierarchies, type declarations, and explicit interfaces that carry substantial semantic weight. Python’s concise syntax and dynamic typing shift semantic density toward identifier names and parameter choices, making lexical preservation more valuable than structural abstraction. This language-specificity, observed consistently across our quantitative evaluation, challenges the widespread assumption that syntactic representations like AST provide universal, task-agnostic code understanding.
The broader implication extends to code representation design for neural models. Our results demonstrate that optimal representations must align with both language characteristics and task requirements: structure-preserving representations (AST) suit verbose, explicitly-typed languages and structural tasks (bug detection, type inference), while identifier-preserving representations (Function Signatures) suit concise, descriptively-named languages and semantic tasks (summarization, intent inference). Practitioners deploying code models across languages must validate representation effectiveness per language rather than assuming transferability.
Furthermore, our findings highlight why aggressive token reduction can sometimes outperform full code inputs: by eliminating verbose implementation details and forcing models to rely on concentrated semantic signals (function names, parameters), compression can improve signal-to-noise ratios in training data. This suggests that token optimization serves dual purposes–computational efficiency and semantic focusing–particularly valuable when dealing with noisy or verbose codebases where implementation verbosity obscures functional intent. The observation that semantic filtering enables more aggressive token compression without quality loss further underscores the importance of multi-level data optimization: instance-level filtering (removing low-quality pairs) creates conditions under which token-level compression becomes viable, demonstrating that these optimization dimensions can offer complementary benefits.
Finally, our cross-language analysis signals that data-centric optimization strategies cannot be developed in isolation from language characteristics. The complete reversal of optimal strategies between Java and Python–where the best-performing method in one language becomes the worst in another–demonstrates that “one-size-fits-all” optimization is fundamentally misguided. Future work in code summarization and related tasks must adopt language-aware evaluation frameworks that validate techniques across diverse programming paradigms rather than generalizing from single-language studies. This principle extends beyond token optimization to broader questions of model architecture, training objectives, and evaluation metrics, all of which may require language-specific calibration to achieve optimal results.


