← Latest papers
💬 NLP

Teaching Language Models to Think in Code

The paper introduces ThinC, a framework that shifts language model reasoning from interleaved natural language and code to a code-centric paradigm where code itself acts as the primary reasoner, achieving state-of-the-art performance on competition-level math benchmarks by distilling code trajectories and employing supervised fine-tuning followed by reinforcement learning.

Original authors: Hyeon Hwang, Jiwoo Lee, Jaewoo Kang

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

Original authors: Hyeon Hwang, Jiwoo Lee, Jaewoo Kang

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 solve a very tricky math puzzle. You have two ways to do it:

  1. The Old Way (Interleaved Reasoning): You talk to yourself in English, figuring out the steps. "Okay, first I need to multiply 500 by 0.12..." Then, you get a little unsure, so you ask a calculator (the code tool) to check your work. But here's the catch: if you made a mistake in your English thinking (like saying 500 times 0.12 is 50 instead of 60), you might accidentally type that wrong number into the calculator. The calculator just does what you tell it; it doesn't know you made a mistake. It calculates based on your wrong number, and you get a wrong answer.
  2. The New Way (THINC): You take a tiny moment to plan your strategy in English ("I need to find the area of this shape"), and then you immediately hand the entire job over to a robot programmer. The robot writes code, runs it, sees the result, writes more code based on that result, and keeps going until the answer pops out. You don't do any math in your head or in English sentences; the robot does all the heavy lifting.

This paper introduces THINC (Thinking in Code), a new way to teach AI models to solve math problems by letting the code itself be the thinker, rather than just a tool the AI uses to check its work.

The Problem with the Old Way

The authors say current AI models that mix English thinking with code (called Tool-Integrated Reasoning) have three main flaws, which they call "structural limitations":

  • The "Post-Hoc" Verifier: The AI often writes out the whole solution in English first, then runs code just to say, "Yep, that's right." The code isn't actually doing the thinking; it's just a stamp of approval at the end.
  • The "Silent Error": If the AI makes a math mistake in its English thoughts (like calculating 12% of 500 as 50 instead of 60), it might copy that wrong number into the code. The code then calculates with the wrong number, and the AI never realizes it. The error is "silent" because the code just follows orders.
  • The "Double Work": The AI often writes a long English explanation of how to solve the problem, and then writes code that does exactly the same thing. It's like writing a recipe in English and then writing the exact same recipe in French, just to prove you know how to cook. It's redundant and confusing.

The THINC Solution

THINC changes the rules of the game. Instead of the AI talking about the math, the AI talks in the math (via code).

  • The Plan: The AI starts with one short English sentence to set the strategy (e.g., "I will loop through numbers to find the answer").
  • The Work: After that one sentence, everything happens in code blocks. The AI writes a piece of code, runs it, sees the output, and then writes the next piece of code based on that output.
  • The Result: The final answer comes directly from the computer's calculator (the interpreter), not from the AI guessing in English.

How They Taught the AI

The researchers didn't just tell the AI to do this; they taught it through a three-step process:

  1. Distillation (The Teacher): They took a very smart, large AI model and asked it to solve math problems using this new "Code-First" style. They collected 12,200 examples of these perfect "Code-First" solutions.
  2. Supervised Fine-Tuning (The Student): They taught two smaller AI models (one with 1.7 billion "brain cells" and one with 4 billion) to mimic these examples. This taught the models the habit of thinking in code.
  3. Reinforcement Learning (The Coach): They let the models practice on thousands of math problems. If the model got the right answer, it got a "reward." If it failed, it learned to try a different code strategy. This made the models much smarter and more reliable.

The Results: Small Models, Big Wins

The paper tested these new models on very hard, competition-level math contests (like AIME and HMMT).

  • Beating the Giants: The small 4-billion-parameter THINC model scored 78.1% on average. This is better than the 1.7B model, better than other "Tool-Integrated" models, and even better than a massive 235-billion-parameter model that only thinks in English!
  • Reliability: In 99.2% of the cases, the final answer was directly pulled from the computer's code output. The AI didn't guess; it calculated.
  • Bouncing Back: If the code made a mistake and crashed (an error), the THINC model was surprisingly good at fixing it in the next code block without needing to "talk" its way out of it. Other models that mix English and code tend to fall apart when they hit a code error.

The Bottom Line

The paper claims that by forcing the AI to stop "talking" about the math and start "doing" the math in code, the models become more accurate, make fewer silly arithmetic mistakes, and solve hard problems more efficiently. It's like switching from a human trying to do long division in their head to a human who knows how to program a calculator to do it for them, step-by-step, without ever making a mental math error.

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 →