What is a code model?
A code model is a language model trained or fine-tuned on large amounts of source code and code-related text, specialised in generating code from natural language descriptions, completing, explaining and translating code and finding bugs.
Unlike a coding agent, a system combining such a model with tools to read files, run commands and retry until tests pass, a code model produces code or explanations for a given input. General large language models can code too; a code model is a domain-specific model for that purpose.
- Topic
- Machine learning, models and training
- Also known as
- Code LLM
How a code model works
- The model is trained on code from open source repositories and documentation, or a general model is fine-tuned on code.
- A function description, code snippet or error message is given; the model produces the following code or a fix.
- Success is usually measured by functional correctness, whether generated code passes unit tests.
- Sampling several solutions per problem and selecting by tests can markedly raise success.
In more detail
Fill-in-the-middle training
Many code models are trained with a Fill-in-the-Middle (FIM) objective alongside standard left-to-right next-token prediction. By reordering prefix, suffix and middle spans during training, the model can complete code at the cursor while conditioning on both preceding and following lines inside an IDE.
The pass@k metric and execution-based evaluation
Functional correctness is typically measured with pass@k, the probability that at least one of k generated samples passes all unit tests, using an unbiased estimator over n >= k samples. Relying solely on text-similarity metrics such as BLEU fails because syntactically different code can be functionally equivalent or subtly broken.
Repository-level context
Production code models go beyond single-file prompts by incorporating repository-level context via RAG over codebases, symbol graphs or Language Server Protocol (LSP) metadata. Balancing long context windows against inference latency and KV-cache memory is essential for accurate cross-file imports and API usage.
Licence, memorisation and supply chain risks
Code models trained on public repositories risk memorising restrictive copyleft snippets or reproducing outdated, insecure API patterns. Enterprises therefore apply training-data filtering, output licence and similarity scanners and automated SAST and secret checks before accepting generated code.
Commonly confused terms
| Term | How it differs |
|---|---|
| Static code analysis | Traditional static analysers and linters check deterministic syntax, type and security rules without generating new logic; a code model probabilistically predicts or refactors code and must still be verified by deterministic analysers and tests. |
Why a code model matters for on-premises AI
Code models can raise developer productivity, but their code needs human review. The 2021 Codex paper reports it solved 28.8% of HumanEval problems with one attempt and 70.2% with 100 samples per problem. On security, a study found about 40% of 1,689 programs generated across 89 scenarios for high-risk weakness types were vulnerable. An in-house code model keeps source code from leaving the organisation.
A bank's software team runs an open-weight code model in-house for completion suggestions; suggested code is not merged into the main branch without static security scanning and human code review.
Common questions
How does a code model differ from a coding agent?
A code model generates code. A coding agent combines a model with tools to read files, run commands and test.
Is code from a code model secure?
Not always. Research shows a significant share contains vulnerabilities, so scanning and human review are needed.
Related terms
- Coding agent
- Large language model
- Domain-specific model
- Code execution tool
- Insecure AI code generation
- Fine-tuning
Sources
- Chen et al., Evaluating Large Language Models Trained on Code, 2021
- Pearce et al., Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributions, 2021
In the glossary: Glossary, A to C