Notes

Code Generation

Code is the one kind of writing where the reader can tell immediately whether the model got it right: you run it. Code generation is the use of a language model to write, complete, translate or repair source code from a natural-language request or from the surrounding file.

Why models are unusually good at it

Public code is abundant, highly structured, and arrives with its own grading function. Pretraining corpora include enormous volumes of source from public repositories, and after training a compiler or a test suite supplies an automatic, unambiguous verdict — something essay-writing never offers. That is why code models were among the first trained against execution feedback, and why the standard metric here is pass@k: whether any of k sampled attempts actually passes the unit tests.

How it shows up in practice
  • Inline completion in an editor, where the prompt is the open file and latency matters more than depth.
  • Chat-style authoring of a function, a query or a migration script from a description.
  • Translation between languages or framework versions, and writing tests for code that has none.
  • Repair: given a stack trace and an error message, propose a patch.
Where it breaks

The characteristic failure is code that looks idiomatic and even runs, but calls a library function that does not exist, mishandles an edge case silently, or reproduces an insecure pattern that was common in its training data. HumanEval measures the gap between plausible and correct on small functions and SWE-bench measures it on real repository issues; the gap is wide in both. Treat the output as a draft from a fast, extremely well-read colleague who has never executed a line of it.

Code generation is the use of a large language model to write, complete, translate or repair source code from a natural-language request or the surrounding file. It is the strongest commercial application of these models because training data is abundant and correctness is machine-checkable: compilers and unit tests grade the output, which is what benchmarks such as HumanEval exploit through the pass@k metric. The standing risk is confident code calling functions that do not exist.

Imagine a colleague who has read nearly every program ever published online and types instantly. You ask for a little tool that renames your holiday photos by date, and it appears in seconds. That is code generation — an AI writing computer instructions from a plain-English request.

It works unusually well here for a simple reason. With code you can just run it and see whether it does the job, so the machine could be trained against a clear right-or-wrong answer in a way that essays and opinions never allow. The catch is that the wrong answers look every bit as polished as the right ones, so a human still has to read the work before trusting it.