← Latest papers
💻 computer science

Contextualized Code Pretraining for Code Generation

This paper proposes "contextualized code pretraining," an invocation-aware framework that leverages static analysis to extract caller-callee pairs for training the CallerGen model, demonstrating that integrating calling context significantly improves code generation performance on realistic benchmarks compared to existing models.

Original authors: Chen Liu, Qingyuan Liang, Hanwen Zhang, Zeyu Sun, Yakun Zhang, Lu Zhang

Published 2026-05-19
📖 5 min read🧠 Deep dive

Original authors: Chen Liu, Qingyuan Liang, Hanwen Zhang, Zeyu Sun, Yakun Zhang, Lu Zhang

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

The Big Problem: The "Blank Canvas" Mistake

Imagine you are a master chef hired to cook a specific dish. Usually, when you ask an AI chef to cook, you give it a recipe card that says, "Make a spicy pasta." The AI looks at its massive library of pasta recipes and guesses what to do.

But in the real world of software development, things work differently. A developer rarely starts with a blank recipe card. Instead, they are usually already in the middle of a meal. They have written the main course (the "caller" code), and now they need to create a specific side dish (the "callee" function) that fits perfectly into that meal.

  • The Old Way: The AI is given the side dish name and asked to guess the ingredients. It might make a great pasta, but if the main course is a seafood stew, the AI might accidentally add cheese, ruining the whole meal.
  • The Real World: The developer has already written the main course. They are calling the side dish and saying, "I need you to take this sauce and turn it into a garnish." The AI needs to look at how the main course is using the side dish to know exactly what to make.

Current AI models are great at following the recipe card (the natural language description), but they are terrible at looking at the main course to understand what the side dish actually needs to do.

The Solution: "CallerGen" (The Context-Aware Chef)

The researchers at Peking University and other institutions built a new AI system called CallerGen. Think of CallerGen as a chef who was trained specifically to look at the main course before cooking the side dish.

Instead of just learning from recipe books, they taught CallerGen by showing it millions of real-world examples where a function (the side dish) was already being used by other parts of the code (the main course).

How they did it:

  1. The Detective Work: They used a special tool (static analysis) to scan huge libraries of real code. They acted like detectives, finding every time a function was "called" and looking at the code that called it.
  2. The Training: They taught the AI: "Here is the main course (the caller). Here is what it is asking the side dish to do. Now, you cook the side dish."
  3. The Result: The AI learned that the side dish isn't just a standalone recipe; it's a piece of a puzzle. It learned to pay attention to the "clues" in the calling code, like what data is being passed in and what the caller expects to get back.

The New Test: "CallerEval" (The Real-World Kitchen)

To prove their new chef was better, they couldn't just use the old recipe cards (standard benchmarks like HumanEval). Those tests are too simple; they don't have a "main course" to look at.

So, they built a new test kitchen called CallerEval.

  • In this test, the AI is given a task where the "main course" code is already written and waiting.
  • The AI must write the "side dish" (the missing function) so that it works perfectly with the existing code.
  • It's like a cooking competition where you aren't judged on how tasty your dish is in isolation, but on how well it blends with the dish already on the table.

The Results: Small Chefs, Big Wins

The paper tested CallerGen against other famous AI chefs (like CodeGen, DeepSeek, and Qwen).

  • The Surprise: Even though CallerGen was a "smaller" chef (using fewer computer resources), it outperformed much "larger" chefs that were trained on the old way (just recipe cards).
  • The Magic: When the AI was allowed to look at the calling context (the main course), its performance skyrocketed.
    • Analogy: It's like a small chef who knows exactly what the customer wants because they can see the customer's plate, beating a giant chef who is just guessing based on a vague order.
  • The Catch: If you take away the calling context (give them just the recipe card), the AI still does well, but it loses that extra edge. This proves that the "calling context" is a superpower that current models aren't fully using yet.

Why This Matters

The paper argues that software development is rarely about writing code in a vacuum. It's about fitting new pieces into existing puzzles.

  • Old AI: "Here is a function name. Make it work." (Often fails to fit the puzzle).
  • New AI (CallerGen): "Here is a function name, and here is exactly how the rest of the program is using it. Make it work for this specific situation." (Succeeds in fitting the puzzle).

By teaching AI to pay attention to the "calling context"—the clues left by the code that uses the function—the researchers created a system that generates code that is much more likely to work correctly in real-world projects, without needing massive amounts of computing power.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →