PseudoBridge: Pseudo Code as the Bridge for Better Semantic and Logic Alignment in Code Retrieval

Yixuan Li, Xinyi Liu, Weidong Yang, Ben Fei, Shuhao Li, Mingjie Zhou, Lipeng Ma · OpenReview

TL;DR

This paper introduces PseudoBridge, a novel framework that uses pseudo-code as an intermediate representation to bridge the gap between natural language queries and actual code. By generating and aligning pseudo-code, and then creating diverse code styles for the same logic, PseudoBridge significantly improves code retrieval accuracy and robustness, especially in challenging zero-shot scenarios.

What Problem Does This Paper Address?

The core challenge in code retrieval is aligning natural language (NL) queries with programming language (PL) code. While modern approaches using large language models (LLMs) have made strides, they still struggle with two key issues:

  1. Semantic Gap: There's a fundamental difference between the ambiguous, intent-rich nature of human language and the precise, logic-driven nature of code. LLMs often capture surface-level semantics but miss the deeper execution logic.
  2. Code Style Diversity: The same functionality can be implemented in many different ways, leading to diverse syntactic structures. Current models can be sensitive to these stylistic variations, hindering their ability to retrieve relevant code consistently.

These limitations impact the effectiveness of LLMs in downstream tasks like retrieval-augmented generation and in-context learning, where accurate code retrieval is crucial.

Methods

PseudoBridge tackles these challenges with a two-stage framework:

  1. Pseudo-code Generation and Alignment (Stage 1):
    • An advanced LLM (like GPT-40) is used to synthesize pseudo-code from pairs of NL queries and their corresponding code snippets.
  2. This pseudo-code acts as a semi-structured "semantic anchor," explicitly bridging the NL intent and the PL logic.
  3. The framework then aligns the NL query with this generated pseudo-code.
  4. Logic-Invariant Code Style Augmentation (Stage 2):
    • Leveraging the synthesized pseudo-code, the LLM generates multiple code implementations that are functionally equivalent but stylistically diverse.
  5. This "multi-style code generation" strategy helps the model learn to focus on invariant logical structures rather than superficial syntactic features.
  6. The pseudo-code is then aligned with these diverse code variants, enhancing robustness to code style variations and improving generalization.

The framework also incorporates an "Evaluate and Refine" mechanism at each stage to ensure the quality of the generated pseudo-code and code variants.

Datasets

The research utilizes the following datasets:

  • CodeSearchNet: A large-scale function-level dataset comprising code and documentation across six programming languages (Go, Java, JavaScript, PHP, Python, Ruby). This dataset is used for training and evaluating the core framework.
  • XLCOST: A dataset collected from GeeksForGeeks, used for evaluating zero-shot cross-lingual generalization. The study specifically uses its C++ and C# subsets.
  • Solidity: A language designed for smart contracts, used to assess performance on domain-specific code retrieval tasks.

Key Insights and Ideas

  • Pseudo-code as a "Semantic Anchor": The paper strongly advocates for pseudo-code not just as a descriptive tool, but as a crucial intermediate representation that explicitly captures algorithmic logic and bridges the semantic gap between NL and PL.
  • Logic Invariance is Key: By generating diverse code styles for the same pseudo-code logic, PseudoBridge forces models to learn underlying logic rather than surface-level syntax, leading to better generalization.
  • Transformative Impact on Weak Models: PseudoBridge provides significant performance boosts for models that initially struggle with code retrieval, effectively turning them into high-performing systems.
  • Complementary to Advanced Techniques: Even for models that already incorporate structural information (like ASTs), PseudoBridge offers further improvements, demonstrating its orthogonal value.
  • Robustness to LLM Capabilities: The framework shows strong performance even when using smaller, open-source LLMs for data generation, highlighting that the core mechanism is the primary driver of improvement.

Key Results

  • Significant Performance Gains: PseudoBridge consistently outperforms baseline models across various PLMs and programming languages. For example, CodeBERT's Recall@1 on Python improved from a negligible 0.0029 to 0.7946.
  • Strong Zero-Shot Generalization: The framework shows exceptional performance on specialized datasets like Solidity and XLCOST without task-specific fine-tuning. For instance, CodeBERT's Recall@1 on C++ improved from 0.0022 to 0.2625 after PseudoBridge fine-tuning.
  • Efficiency Maintained: Despite enhancing accuracy, PseudoBridge does not introduce significant inference latency, making it suitable for real-time applications.
  • Cost-Effective Data Synthesis: The paper demonstrates that synthesizing high-quality training data using LLMs is economically feasible, with a total cost of approximately $0.0446 per sample.

Limitations and Future Work

  • LLM Reliability: The performance of PseudoBridge is ultimately constrained by the reliability and reasoning capabilities of the LLMs used for generation. Future work aims to explore fine-tuning specialized models and integrating advanced reinforcement learning for more robust generation.
  • Distributional Bias: LLMs can inherit biases from their training data. PseudoBridge attempts to mitigate this through prompt engineering and style constraints, but future work will focus on integrating diverse LLMs and establishing fine-grained benchmarks for low-resource languages.
  • Scope of Evaluation: While evaluated across six languages and ten models, future work aims to expand the range of programming languages and explore emerging architectures for more comprehensive validation.
  • Downstream Task Potential: The core concept of using pseudo-code as an intermediate representation holds promise for other tasks like code generation, summarization, and translation.

Summary updated

BibTeX
@misc{li2025pseudobridge,
  author = {Yixuan Li and Xinyi Liu and Weidong Yang and Ben Fei and Shuhao Li and Mingjie Zhou and Lipeng Ma},
  title = {{PseudoBridge: Pseudo Code as the Bridge for Better Semantic and Logic Alignment in Code Retrieval}},
  year = {2025},
  eprint = {2509.20881},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.20881},
}
Figure