Datasets:
File size: 8,955 Bytes
072246b 99fdd1b 5b085c4 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b 072246b 99fdd1b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | ---
language:
- en
license: mit
pretty_name: Klein-Code-Bench
task_categories:
- text-generation
tags:
- code
- benchmark
- project-generation
- small-language-models
- local-models
- python
size_categories:
- n<1K
configs:
- config_name: default
default: true
data_files:
- split: test
path: klein_code_bench/data/*.jsonl
- config_name: easy
data_files:
- split: test
path: klein_code_bench/data/easy.jsonl
- config_name: intermediate
data_files:
- split: test
path: klein_code_bench/data/intermediate.jsonl
- config_name: hard
data_files:
- split: test
path: klein_code_bench/data/hard.jsonl
- config_name: max
data_files:
- split: test
path: klein_code_bench/data/max.jsonl
---
<p align="center">
<img src="https://cdn-avatars.huggingface.co/v1/production/uploads/69ae829a8408eeb0d7dd5491/943kN5YZ59lFCUN1jiKz5.png" width="180" alt="KleinML">
</p>
# Klein-Code-Bench
Can a model build a working program from scratch? Klein-Code-Bench gives a coding model a specification and an
empty directory, and checks whether the finished Python project passes every acceptance test.
- **260 tasks** in four tiers of 65
- **Pass or fail per project:** a task counts only if all of its tests pass
- **Runs locally:** standard-library Python, no Docker, no cloud model, no extra dependencies
| Tier | Intended model size | What the model builds | Tasks |
| --- | --- | --- | ---: |
| easy | 2–8B | A JSONL command-line tool with a domain algorithm and error recovery | 65 |
| intermediate | 8–16B | A stateful document service: CRUD, listing, domain evaluation | 65 |
| hard | 16–32B | A service with atomic batches, revision checks and nested transactions | 65 |
| max | 60–200B | A durable service that survives being force-killed, with idempotency, history and pagination | 65 |
The model sizes are design targets. Version 0.1.0 has not been calibrated against real models yet, and there is no
leaderboard. Any model can be run on any tier.
## How a task works
1. The model gets `PROMPT.md`: the full specification plus two examples.
2. It writes `main.py` and any other files into an empty `project/` directory. There's no starter code and no
existing repository to fix.
3. The evaluator runs the project as a subprocess, sends JSONL requests and checks every response and state change.
In the max tier, the process is force-killed right after its last acknowledged response, restarted on the same
state directory, and must continue correctly.
The 65 tasks per tier come from the same 65 domain families: text processing, CSV/JSON tools, calendars, numerical
utilities, graphs, scheduling, ledgers, geometry, parsing, simulation and more. Each tier adds service behavior on
top of the one below. Full list: [task catalog](docs/CATALOG.md).
Because the tiers share families, results across tiers are correlated. Report each tier separately, and don't
train on one tier and then present another as an uncontaminated evaluation.
## Quick start
Requires Python 3.11+ on Linux or macOS.
```bash
git clone https://huggingface.co/datasets/klein-ml/klein-code-bench
cd klein-code-bench
python -m pip install -e .
klein-bench list --subset easy
# Create a workspace: PROMPT.md, plus an empty project/ directory for the model
klein-bench prepare kcb-easy-001-word-frequency --output workspaces/first
# Give workspaces/first/PROMPT.md to your model and let it write into workspaces/first/project/, then:
klein-bench evaluate kcb-easy-001-word-frequency \
--solution workspaces/first/project --output results/first.json
klein-bench score results/first.json
```
- `python -m klein_code_bench` works the same as `klein-bench`.
- Exit code 1 means a failed submission, 2 an invalid invocation.
- `--public-only` runs just the two examples as a smoke test. Those results can't be scored.
Bring your own agent or local API endpoint, or use the [banana-harness integration](docs/BANANA_HARNESS.md).
Record the model's inference settings with your results.
## Loading the dataset
```python
from datasets import load_dataset
easy = load_dataset("klein-ml/klein-code-bench", "easy", split="test") # 65 tasks
all_tasks = load_dataset("klein-ml/klein-code-bench", split="test") # 260 tasks
```
Each tier is its own config with a single `test` split; the default config contains all four. There is no
training split, and no loading script or `trust_remote_code` is needed. Pin `revision` to a commit when you
report results.
| Field | Content |
| --- | --- |
| `task_id` | Stable unique ID |
| `subset`, `family`, `category`, `title` | Tier and task description |
| `target_model_parameters` | Intended model-size band (not calibrated) |
| `language`, `entrypoint`, `protocol_version` | Python, `main.py`, protocol version |
| `prompt` | The full specification the model sees |
| `public_tests` | Example requests and responses (JSON string) |
| `acceptance_tests` | Evaluator scenarios: sessions, requests, expected responses (JSON string) |
| `num_scenarios`, `num_assertions`, `timeout_seconds` | Test counts and the per-session time limit |
The test fields are stored as JSON strings so that all tasks share one schema; decode them with `json.loads`.
**Never put `acceptance_tests`, the reference implementations or the evaluator source into the model's prompt,
context or workspace.** They're public for reproducibility, so the benchmark depends on you keeping them away from the
model.
## Scoring
The metric is **resolve@1**: one project per task, and it counts only if every test passes.
- **Per tier:** resolved tasks / 65. **Overall:** resolved tasks / 260.
- Missing submissions count as failures. The report also shows the rate among submitted tasks and flags incomplete runs.
- Partial assertion success is reported for diagnosis, but it never counts as resolved.
Each scenario starts from a fresh copy of the submission and an empty state directory; sessions within a max-tier
scenario share that directory. JSON comparison keeps array order and tells booleans apart from numbers. Floats use
an absolute and relative tolerance of 1e-9; integers are compared exactly. Default limits are 10 seconds per session
and 1 MiB of stdout. Details: [evaluation protocol](docs/EVALUATION.md).
| Tier | Assertions |
| --- | ---: |
| easy | 3,075 |
| intermediate | 5,415 |
| hard | 9,705 |
| max | 15,490 |
| **total** | **33,685** |
The tests cover:
- 65 hand-written golden outputs
- 24 generated inputs per family (seed 1729, shared across tiers)
- boundary cases and malformed requests
- failure atomicity, nested rollback and revision conflicts
- retry and restart sequences
All expected outputs are computed before grading, never inside the candidate's process.
### Verifying the benchmark itself
```bash
python -m unittest discover -s tests -v # unit and property tests for the benchmark and runner
klein-bench build # regenerate data and manifest from source
klein-bench validate --output results/validation.json # every reference must pass, every empty project must fail
```
The reference implementations exist to maintain the evaluator. Export one for auditing with
`klein-bench reference TASK_ID --output DIR`. The published `validation-summary.json` documents the dataset
manifest and validation totals; it is not a model score.
## Security
The runner is **not a sandbox**. It does the following:
- removes inherited credentials from the environment
- runs each submission from a temporary copy
- rejects symlinks
- limits time and output
- kills the whole process group when it's done
Generated code can still reach your filesystem and network. Run it under a separate unprivileged user, on a machine
you can afford to lose. Timing depends on the host, so record your hardware with your results.
## Provenance and limitations
- **Origin:** every task was written for this benchmark. None were copied from SWE-bench, LiveCodeBench or other
benchmarks. That covers how the tasks were authored; it doesn't guarantee that standard algorithms in the easy tier
never appear in a model's training data.
- **Scope:** Python only. The tests measure behavioral correctness, not code quality, architecture or UI. They don't
cover concurrent writers, disk corruption or power loss during a write.
- **Coverage:** the reference implementations and independent golden checks make the dataset internally consistent,
but the tests can't prove that no specification or expected output contains an error.
- **License:** MIT for prompts, test data and reference implementations.
## Contributing
A new task needs:
- a contract (the specification)
- meaningful boundary tests
- an independent check of the expected outputs
- a reference implementation that passes
Changes to a contract or expected behavior require a new dataset version. Task IDs stay the same only for
backward-compatible fixes. |