BatCoder: Self-Supervised Bidirectional Code-Documentation Learning via Back-Translation

Jingwen Xu, Yiyang Lu, Zisu Huang, Changze Lv, Xiaohua Wang, Shizheng Li, Zhibo Xu, Zhengkang Guo, Zhengyuan Wang, Muzhao Tian, Xuanjing Huang, Xiaoqing ZhengarXiv 2026

TL;DR

BatCoder is a self-supervised reinforcement learning framework that trains LLMs on code-related tasks using only unlabeled source code. By implementing a back-translation loop—generating documentation from code, then reconstructing the original code from that documentation—it uses code similarity as an implicit reward to jointly optimize both code generation and documentation capabilities.

What Problem Does This Paper Address?

State-of-the-art large language models (LLMs) excel at code generation and summarization, but training them typically requires massive collections of high-quality, parallel code-documentation pairs. These pairs are expensive to curate manually and are notoriously scarce for low-resource or niche programming languages (like Ruby or Go).

While prior approaches have used data augmentation—leveraging powerful external teacher models (like GPT-4) to synthesize instructions or pseudo-labels—this creates a dependency on external APIs and prevents a target model from natively self-improving. BatCoder tackles this bottleneck by asking: Can a model learn to align code and natural language documentation purely by reading unlabeled code?

Methods

BatCoder introduces a self-contained, bidirectional learning paradigm based on back-translation, optimized via reinforcement learning (specifically the Reinforce++ algorithm).

The pipeline operates in two sequential stages:

  1. Stage 1 (Code-to-Documentation): Given an unlabeled code snippet, the model generates a natural language document describing it.
  2. Stage 2 (Documentation-to-Code): The model takes its own generated documentation and attempts to reconstruct the original source code.
Figure 1. BatCoder training pipeline via self-supervised back-translation. Given an unlabeled code snippet c, the model first generates multiple documentation candidates in Stage 1 (code-to-documentation). After extracting content and filtering for structural validity, each valid candidate is used to sample a single reconstructed code in Stage 2 (documentation-to-code). Rewards consist of code similarity and document format compliance, allocated differently to the two stages. Both directions are jointly optimized via Reinforce++ algorithm.

Key Technical Innovations:

  • Asymmetric Sampling Strategy: To capture the diverse ways natural language can describe code, Stage 1 samples $K$ different documentation candidates. To keep compute and memory overhead low, Stage 2 samples only a single reconstructed code snippet per valid document.
  • Implicit Reward Design: The framework uses CSSG (Code Similarity with Semantic Graphs), a metric that evaluates structural and semantic similarity between the original and reconstructed code.
  • Stage 2 Reward: Purely based on the CSSG similarity score.
  • Stage 1 Reward: The CSSG similarity score multiplied by a Format Factor (derived via regex matching) that penalizes the model if the generated documentation fails to follow structural constraints or contains redundant text.

Datasets

  • Training: The authors utilized raw code snippets from the Code-Text task of the CodeXGLUE benchmark, spanning Python, Ruby, and Go. Crucially, they discarded all existing text/docstrings, training the model strictly on the unlabeled code.
  • Evaluation:
  • Python: Evaluated on standard benchmarks HumanEval and MBPP, as well as their stricter, test-augmented variants HumanEval+ and MBPP+.
  • Multilingual (Ruby & Go): Evaluated using MultiPL-E, which translates HumanEval and MBPP problems into other programming languages.

Key Insights and Ideas

  • Code as the Ultimate Ground Truth: The core philosophy is that well-formed documentation must preserve enough semantic information to allow a faithful reconstruction of the code. Therefore, code-reconstruction fidelity serves as a proxy for text quality, eliminating the need for gold-standard human documentation during training.
  • The Power of Joint Optimization: Ablation studies revealed that optimizing both stages simultaneously is critical. When the authors blocked parameter updates for Stage 1 (treating the generated documentation as fixed), the model's performance gains collapsed. Explicitly rewarding the model for generating reconstructible documentation is what drives the framework's success.
  • Bootstrapping from Zero: The framework proves exceptionally potent for low-resource languages where base models struggle significantly, demonstrating that self-supervision can unlock latent capabilities already buried within a model's pre-trained weights.

Key Results

BatCoder was evaluated using 3B and 7B variants of Qwen2.5-Instruct, yielding substantial performance leaps:

  • Python Benchmarks: The BatCoder-7B model achieved 83.5% pass@1 on HumanEval and 81.0% on MBPP, outperforming its base model (81.7% and 78.6% respectively) and surpassing much larger open-source models like the 33B DeepSeek-Coder-Instruct.
  • Low-Resource Languages (Ruby & Go): The most dramatic improvements occurred here. On MultiPL-E Ruby, the base 3B model scored a literal 0.0% pass@1, completely failing the benchmark. After BatCoder training, its score jumped to 10.6%. At the 7B scale, Ruby performance improved from 3.1% to 13.0%. Go also saw solid gains, climbing from 34.4% to 39.0% at the 7B scale.
Training dynamics showing steady alignment between Stage 1/2 rewards and downstream Pass@1 performance on Ruby.

As shown in the training dynamics curves, the mean rewards for both stages steadily increase alongside downstream task performance, confirming that the back-translation reward is stable and highly correlated with actual coding capability.

Limitations and Future Work

Despite its strong performance, the authors note a few limitations:

  1. Hyperparameter Tuning: The same hyperparameter profile was applied to both the 3B and 7B models without extensive tuning, suggesting that performance could be pushed even higher with tailored optimization.
  2. Narrow Reward Signals: The framework relies entirely on a single code-similarity metric (CSSG) and basic regex formatting rules.

Future Directions: The authors plan to explore more diverse reward signals, test alternative reinforcement learning algorithms, investigate how the framework scales with even larger training corpora, and extend the method to tasks like code completion and code-to-code translation.

Summary updated

BibTeX
@misc{xu2026batcoder,
  author = {Jingwen Xu and Yiyang Lu and Zisu Huang and Changze Lv and Xiaohua Wang and Shizheng Li and Zhibo Xu and Zhengkang Guo and Zhengyuan Wang and Muzhao Tian and Xuanjing Huang and Xiaoqing Zheng},
  title = {{BatCoder: Self-Supervised Bidirectional Code-Documentation Learning via Back-Translation}},
  year = {2026},
  eprint = {2602.02554},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.02554},
}
Figure