Functional consistency of LLM code embeddings: A self-evolving data synthesis framework for benchmarking

Zhuohao Li, Wenqing Chen, Jianxing Yu, Zhichao LuExpert Systems with Applications 2025 · DOI · OpenReview

TL;DR

This paper introduces a novel framework, "Functionality-Oriented Code Self-Evolution," to generate diverse and challenging code datasets that better capture functional consistency. By creating code variants that vary syntactically and semantically, the framework addresses limitations in existing benchmarks and significantly improves the performance of LLM-based code embeddings on downstream tasks like code clone detection and retrieval.

What Problem Does This Paper Address?

Large Language Models (LLMs) have shown impressive capabilities in understanding and generating code. However, evaluating their true understanding of code functionality, especially when code snippets have different syntactic structures but perform the same task, remains a challenge. Existing benchmarks often focus on syntactic similarity, failing to adequately test the models' ability to grasp functional equivalence. This gap hinders the development of robust code intelligence systems that can reliably identify functionally similar code, regardless of its surface-level representation. Furthermore, current methods for generating diverse code examples often lack rigorous validation of functional correctness, leading to potentially misleading benchmarks.

Methods

The core contribution is the Functionality-Oriented Code Self-Evolution framework. This framework takes a single source code snippet and systematically generates four types of code variants:

  • Type I (Perturbation Evolving): Syntactically different but functionally equivalent code. This involves random code perturbations like changing variable names, comments, or adding dead code, while ensuring functionality remains unchanged ($\Delta_{sem} = 0, \Delta_{syn} > 0$).
  • Type II (Implementation Evolving): Syntactically different and functionally equivalent code. This aims to produce diverse implementations of the same functionality, where the code structure and style are significantly altered but the core intent is preserved ($\Delta_{sem} = 0, \Delta_{syn} \gg 0$).
  • Type III (Function Evolving): Syntactically and semantically different code. This generates code that performs fundamentally different functions, creating negative examples for functional consistency ($\Delta_{sem} > 0, \Delta_{syn} \gg 0$).
  • Type IV (Form-Preserving Functional Evolution): Syntactically similar but functionally different code. This creates deceptive samples that look structurally similar to the original but have different functionality ($\Delta_{sem} > 0, \Delta_{syn} \approx 0$).

To ensure the quality and reliability of the generated code, the framework employs a multi-stage validation process:

  1. Rule-based execution: Automated test cases verify executability and functional equivalence.
  2. Metric-based filtering: CodeBLEU is used to measure syntactic similarity, with a threshold determined empirically to filter variants.
  3. Human-based verification: A subset of samples is manually reviewed to confirm correctness.

Datasets

The paper introduces two new datasets:

  • POJ-Evl: Evolved from the POJ-104 dataset, this dataset expands the diversity of code scenarios for functional consistency analysis.
  • HumanEval-Evl: Evolved from the HumanEval benchmark, this dataset provides a more complex and challenging testbed for evaluating code understanding.

These datasets are designed to cover all four code types, offering a more comprehensive evaluation than existing benchmarks.

Key Insights and Ideas

  • Existing datasets are insufficient: Current code datasets heavily favor syntactic similarity and lack the complexity needed to truly evaluate LLMs' understanding of functional code equivalence, especially for challenging cases like Type III and Type IV.
  • Functional consistency is key: The ability of code embeddings to capture functional consistency, rather than just syntactic similarity, is crucial for many downstream code intelligence tasks.
  • Systematic data synthesis is powerful: The proposed "Functionality-Oriented Code Self-Evolution" framework provides a principled way to generate diverse and functionally rich code variants, significantly improving model performance.
  • Validation is critical: Rigorous validation, combining automated testing, metric-based filtering, and human review, is essential for creating high-quality, reliable code datasets.

Key Results

  • Training embedding models on the evolved datasets (POJ-Evl and HumanEval-Evl) led to significant performance improvements across three downstream tasks: code clone detection, code functional consistency identification, and code retrieval.
  • For instance, on the functional consistency task, the evolved dataset improved accuracy by nearly 300x for Type IV scenarios compared to existing datasets.
  • The framework demonstrated strong generalization capabilities, showing consistent gains on both POJ-104 and the more complex HumanEval benchmark.
  • When compared to rule-based augmentation methods, the proposed framework showed substantially larger improvements, particularly for the challenging Type III and Type IV code types.

Limitations and Future Work

  • Generalizability: While validated on widely used benchmarks, the framework's generalizability could be further improved by expanding evaluation to more programming languages and paradigms.
  • LLM Instruction Design: Variations in LLM instruction design might affect results, suggesting potential benefits from further optimization of these prompts.

Future work aims to:

  • Extend the framework to support multi-language scenarios.
  • Incorporate dynamic analysis techniques to enhance robustness.
  • Explore further optimization of LLM instruction design.

Summary updated

BibTeX
@misc{li2025functional,
  author = {Zhuohao Li and Wenqing Chen and Jianxing Yu and Zhichao Lu},
  title = {{Functional consistency of LLM code embeddings: A self-evolving data synthesis framework for benchmarking}},
  year = {2025},
  eprint = {2508.19558},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.19558},
}
Figure