Beyond Code Pairs: Dialogue-Based Data Generation for LLM Code Translation
This paper introduces an automated, dialogue-based dataset generation pipeline that leverages a dual-LLM Questioner-Solver design with compiler and runtime feedback to create verified code translations and reasoning dialogues, significantly enhancing the functional correctness of LLMs in low-resource domains like Fortran and CUDA.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine you are trying to teach a brilliant but inexperienced apprentice how to translate a complex recipe from an old, obscure language (like Fortran) into a modern one (like C++ or CUDA).
The Problem: The "Black Box" Translation
Traditionally, when we teach AI to translate code, we show it a "Source Code" and the "Target Code" side-by-side. It's like giving the apprentice a list of ingredients and the final dish, but never letting them see the cooking process. They might guess the right dish, but if they make a mistake, they don't know why or how to fix it. They just produce a result that looks right but might fail when you actually try to eat it (run the code).
The Solution: The "Questioner" and the "Solver"
This paper introduces a new way to train AI, called Beyond Code Pairs. Instead of just showing the start and finish, they created a system that records the entire conversation and struggle of the translation process.
Think of it like a kitchen with two distinct roles:
- The Questioner (The Chef's Critic): This AI doesn't write the code. Instead, it acts like a strict head chef. It looks at the current state, checks for errors (like a compiler error or a runtime crash), and asks specific questions: "Why did this crash?" or "Did you check the memory limits?" It uses real-world feedback from the computer to guide the process.
- The Solver (The Apprentice): This AI does the actual writing. It tries to translate the code, writes unit tests (like taste tests), and tries to fix the errors the Questioner points out.
The Process: A Dialogue, Not a Monologue
The paper describes a pipeline where these two AIs talk back and forth in a multi-turn dialogue:
- Step 1: The Questioner asks the Solver to write a test for the original code.
- Step 2: The Solver writes the test. The Questioner checks if it passes. If not, they argue and refine it until it works.
- Step 3: The Questioner asks for the translation. The Solver writes the new code.
- Step 4: The Questioner runs the new code. If it crashes, the Questioner says, "You forgot to handle this specific error!" The Solver then fixes it.
- Step 5: They repeat this until the code compiles, runs, and passes all tests.
The magic is that the researchers saved every single turn of this conversation. They didn't just save the final code; they saved the mistakes, the questions, the compiler error messages, and the fixes.
The Results: Small Models, Big Wins
The researchers used this method to generate thousands of these "conversations" for translating Fortran to C++ and C++ to CUDA (a language for graphics cards).
When they trained smaller, open-source AI models (like a 7-billion parameter model) on these conversations, the results were shocking:
- Functional Correctness: The models didn't just write code that looked right; they wrote code that actually worked. On the difficult task of translating C++ to CUDA, the success rate of passing tests jumped from 12.5% to 68.8%.
- Beating the Giants: A small, open-source model trained on this "dialogue" data performed better than massive, expensive, proprietary systems (like Google's Gemini or Meta's Llama 4) on key metrics like getting the code to compile and run without crashing.
The Takeaway
The paper argues that to teach AI to do complex tasks like code translation, you shouldn't just show them the answer. You need to show them the struggle, the questions, and the corrections. By training on these "conversations" rather than just static pairs of code, even smaller, cheaper AI models can learn to reason through errors and produce high-quality, functional software.
In short: Don't just teach the AI the answer; teach it how to think, argue, and fix its own mistakes.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.