Banaxi-Tech commited on
Commit
99fdd1b
·
verified ·
1 Parent(s): 072246b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +127 -53
README.md CHANGED
@@ -38,30 +38,52 @@ configs:
38
  path: klein_code_bench/data/max.jsonl
39
  ---
40
 
 
 
 
 
 
 
 
 
41
  # Klein-Code-Bench
42
 
43
- **260 tasks that ask a coding model to build a working Python project from an empty directory.** There are four subsets of exactly 65 tasks. A project is resolved only when **every acceptance test passes**, including process restarts where required. No Docker, container runtime, cloud model, or third-party runtime library is required by the evaluator.
 
44
 
45
- | Subset | Target model size | Project to build | Tasks |
 
 
 
 
46
  | --- | --- | --- | ---: |
47
- | easy | 2–8B | JSONL command-line tool with a domain algorithm and error recovery | 65 |
48
- | intermediate | 8–16B | Stateful document service with CRUD, listing and domain evaluation | 65 |
49
- | hard | 16–32B | Service with atomic batches, revision checks and nested transactions | 65 |
50
- | max | 60–200B | Durable service with forced-kill recovery, idempotency, history and pagination | 65 |
51
 
52
- **The parameter ranges are design targets, not measured capability thresholds.** Version 0.1.0 has no model leaderboard or empirical difficulty calibration. It is an initial benchmark release, not an extension of or an official result on SWE-bench.
 
53
 
54
- ## What the tasks measure
55
 
56
- Each of 65 domain families has one version in each subset. The higher versions require the entire lower-tier behavior plus additional service behavior. Domains include text processing, CSV and JSON tools, calendars, numerical utilities, graph algorithms, scheduling, ledgers, geometry, parsing and simulation. See [the task catalog](docs/CATALOG.md).
 
 
 
 
 
57
 
58
- A participant receives a complete specification and two examples, then creates `main.py` and any supporting files. There is no repository to fix, starter solution, injected implementation, or preinstalled dependency to discover. Tests run the finished project as a real subprocess, exchange JSONL requests, and check results and state transitions. Max-tier restart sessions force-kill the process immediately after its final acknowledged response and then reopen the same state directory.
 
 
59
 
60
- **Cross-tier overlap is intentional.** These are 260 project specifications across 65 families, not 260 unrelated algorithms. Shared service requirements and domain families make outcomes correlated; report each subset separately. Do not train on one tier and describe another tier as an uncontaminated evaluation. The easy subset includes some standard graph/DP algorithms; the target bands need calibration across actual local models.
 
61
 
62
- ## Quick start (Python 3.11+, Linux or macOS)
63
 
64
- Clone this Hugging Face dataset repository, then install the evaluator:
65
 
66
  ```bash
67
  git clone https://huggingface.co/datasets/klein-ml/klein-code-bench
@@ -69,75 +91,127 @@ cd klein-code-bench
69
  python -m pip install -e .
70
  klein-bench list --subset easy
71
 
72
- # Put the prompt outside the initially empty project directory.
73
  klein-bench prepare kcb-easy-001-word-frequency --output workspaces/first
74
- # Give workspaces/first/PROMPT.md to your coding model.
75
- # Have the model create files inside workspaces/first/project/.
76
 
 
77
  klein-bench evaluate kcb-easy-001-word-frequency \
78
  --solution workspaces/first/project --output results/first.json
79
  klein-bench score results/first.json
80
  ```
81
 
82
- `python -m klein_code_bench` is equivalent to `klein-bench`. A failed submission exits 1; an invalid invocation exits 2. `--public-only` runs examples as a smoke test and marks the result ineligible for scoring. The evaluator has no Python dependencies. Participants use only the Python standard library.
 
 
83
 
84
- Use your own coding agent, a local API endpoint, or the [banana-harness integration](docs/BANANA_HARNESS.md). Model size does not enforce access to a tier; evaluate any model on any subset and record its inference settings.
 
85
 
86
- ## Load with Hugging Face Datasets
87
 
88
  ```python
89
  from datasets import load_dataset
90
 
91
- easy = load_dataset("klein-ml/klein-code-bench", "easy", split="test")
92
- all_tasks = load_dataset("klein-ml/klein-code-bench", split="test")
93
- assert len(easy) == 65
94
- assert len(all_tasks) == 260
95
  ```
96
 
97
- Pin `revision` to a dataset commit when reporting results. All four named configurations expose a `test` split; the default configuration concatenates them. There is no training split. No dataset loading script or `trust_remote_code` is needed.
98
-
99
- The JSONL rows contain:
100
 
101
- | Field | Meaning |
102
  | --- | --- |
103
- | `task_id` | Stable unique identifier |
104
- | `subset`, `family`, `category`, `title` | Tier and project descriptors |
105
- | `target_model_parameters` | Intended parameter band, uncalibrated |
106
- | `language`, `entrypoint`, `protocol_version` | Python, main.py and contract version |
107
- | `prompt` | Entire participant-visible project specification |
108
- | `public_tests` | JSON-encoded list of example requests and responses |
109
- | `acceptance_tests` | JSON-encoded evaluator scenarios, with sessions, requests and expected responses |
110
- | `num_scenarios`, `num_assertions`, `timeout_seconds` | Evaluation sizes and per-session wall-clock limit |
111
 
112
- Tests are JSON strings to provide a stable Arrow schema across projects with different input and output structures. Decode with `json.loads`. `acceptance_tests` is evaluator-side information: **never include it in the model prompt, context or workspace**. The source and expected outputs are public for reproducibility, so these tests are not secret holdouts. Examples also occur in the full suite. Source code and evaluator references must be excluded from an agent's accessible benchmark materials in a controlled evaluation.
113
 
114
- ## Scoring and reproducibility
 
 
115
 
116
- The primary metric is **resolve@1**: one generated project per task, with all tests passing. Within a subset the score is resolved tasks / 65. Across the complete benchmark it is resolved tasks / 260. Missing submissions remain in that denominator. The report also includes the rate among submitted tasks and marks incomplete runs. Partial assertion success is diagnostic, never a resolved task.
117
 
118
- Every run starts each scenario with a fresh copy of the submission and empty state directory. Sessions within a max-tier scenario share that state directory. JSON comparisons preserve array order and distinguish booleans from numbers; finite floating point values use absolute/relative tolerance 1e-9. Exact integer comparisons avoid precision loss. The default limit is 10 seconds per session and 1 MiB of stdout. See [the evaluation protocol](docs/EVALUATION.md) for execution limits and score reporting requirements.
119
 
120
- The four dataset files contain **33,685 response assertions**: 3,075 easy, 5,415 intermediate, 9,705 hard and 15,490 max. Fixtures include 65 independently hand-authored golden outputs, boundary cases, 24 deterministically generated extra inputs per domain family, malformed requests, failure atomicity, nested rollback, revision conflicts and retry/restart sequences. Generated domain inputs are shared across tiers. The suite uses seed 1729; all expected results are materialized before grading, rather than computed inside a candidate process.
 
 
121
 
122
- ```bash
123
- # Unit/property tests for the benchmark and runner:
124
- python -m unittest discover -s tests -v
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
- # Regenerate data and manifest from authored source:
127
- klein-bench build
128
 
129
- # Export and run every trusted reference project, and reject every empty project:
130
- klein-bench validate --output results/validation.json
 
 
 
 
131
  ```
132
 
133
- The readable reference implementations are evaluator maintenance tools. They are not starter code and must never be supplied to participants. `klein-bench reference TASK_ID --output DIRECTORY` exports a self-contained reference for auditing. A published `validation-summary.json` records the checked dataset manifest and validation totals; it is not a model evaluation score.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
 
135
- ## Execution boundary
 
 
 
 
 
 
 
136
 
137
- This is a local host runner, **not a security sandbox**. It strips inherited credentials from the subprocess environment, copies submissions to temporary directories, rejects file symlinks, limits captured output and time, and kills process groups. Native processes can still access the host filesystem and network. Run generated code under a dedicated unprivileged account on an expendable machine if host access is unacceptable. No Docker workflow is required or provided. Timing and resource availability depend on your host; record them with results.
138
 
139
- ## Release, provenance and limitations
140
 
141
- Version 0.1.0 was authored specifically for this benchmark. No task was copied from SWE-bench, LiveCodeBench or another benchmark. This claim describes authoring provenance, not novelty of standard algorithms or proof against overlap with model training data. All prompts, fixtures and reference implementations are released under MIT. Some use Python standard-library semantics explicitly; the initial release evaluates Python projects only. The rubric measures behavioral correctness rather than UI quality, architectural elegance or production readiness. It does not require concurrent writers, fuzz external disk corruption, or simulate a power failure during a disk write.
 
 
 
142
 
143
- The fixed tests are not exhaustive. Reference validation and additional independent golden/property checks establish internal consistency; they cannot prove the absence of every specification or oracle error. Contributions should include a contract, meaningful boundary tests, an independent expected-output check, and a passing reference. Changing a contract or expected behavior requires a dataset version change; retain task IDs only for compatible corrections.
 
 
38
  path: klein_code_bench/data/max.jsonl
39
  ---
40
 
41
+ <p align="center">
42
+ <img src="https://cdn-avatars.huggingface.co/v1/production/uploads/69ae829a8408eeb0d7dd5491/943kN5YZ59lFCUN1jiKz5.png" width="180" alt="KleinML">
43
+ </p>
44
+
45
+ <p align="center">
46
+ <a href="https://kleinml.com"><b>Klein ML Website</b></a>
47
+ </p>
48
+
49
  # Klein-Code-Bench
50
 
51
+ Can a model build a working program from scratch? Klein-Code-Bench gives a coding model a specification and an
52
+ empty directory, and checks whether the finished Python project passes every acceptance test.
53
 
54
+ - **260 tasks** in four tiers of 65
55
+ - **Pass or fail per project:** a task counts only if all of its tests pass
56
+ - **Runs locally:** standard-library Python, no Docker, no cloud model, no extra dependencies
57
+
58
+ | Tier | Intended model size | What the model builds | Tasks |
59
  | --- | --- | --- | ---: |
60
+ | easy | 2–8B | A JSONL command-line tool with a domain algorithm and error recovery | 65 |
61
+ | intermediate | 8–16B | A stateful document service: CRUD, listing, domain evaluation | 65 |
62
+ | hard | 16–32B | A service with atomic batches, revision checks and nested transactions | 65 |
63
+ | max | 60–200B | A durable service that survives being force-killed, with idempotency, history and pagination | 65 |
64
 
65
+ The model sizes are design targets. Version 0.1.0 has not been calibrated against real models yet, and there is no
66
+ leaderboard. Any model can be run on any tier.
67
 
68
+ ## How a task works
69
 
70
+ 1. The model gets `PROMPT.md`: the full specification plus two examples.
71
+ 2. It writes `main.py` and any other files into an empty `project/` directory. There's no starter code and no
72
+ existing repository to fix.
73
+ 3. The evaluator runs the project as a subprocess, sends JSONL requests and checks every response and state change.
74
+ In the max tier, the process is force-killed right after its last acknowledged response, restarted on the same
75
+ state directory, and must continue correctly.
76
 
77
+ The 65 tasks per tier come from the same 65 domain families: text processing, CSV/JSON tools, calendars, numerical
78
+ utilities, graphs, scheduling, ledgers, geometry, parsing, simulation and more. Each tier adds service behavior on
79
+ top of the one below. Full list: [task catalog](docs/CATALOG.md).
80
 
81
+ Because the tiers share families, results across tiers are correlated. Report each tier separately, and don't
82
+ train on one tier and then present another as an uncontaminated evaluation.
83
 
84
+ ## Quick start
85
 
86
+ Requires Python 3.11+ on Linux or macOS.
87
 
88
  ```bash
89
  git clone https://huggingface.co/datasets/klein-ml/klein-code-bench
 
91
  python -m pip install -e .
92
  klein-bench list --subset easy
93
 
94
+ # Create a workspace: PROMPT.md, plus an empty project/ directory for the model
95
  klein-bench prepare kcb-easy-001-word-frequency --output workspaces/first
 
 
96
 
97
+ # Give workspaces/first/PROMPT.md to your model and let it write into workspaces/first/project/, then:
98
  klein-bench evaluate kcb-easy-001-word-frequency \
99
  --solution workspaces/first/project --output results/first.json
100
  klein-bench score results/first.json
101
  ```
102
 
103
+ - `python -m klein_code_bench` works the same as `klein-bench`.
104
+ - Exit code 1 means a failed submission, 2 an invalid invocation.
105
+ - `--public-only` runs just the two examples as a smoke test. Those results can't be scored.
106
 
107
+ Bring your own agent or local API endpoint, or use the [banana-harness integration](docs/BANANA_HARNESS.md).
108
+ Record the model's inference settings with your results.
109
 
110
+ ## Loading the dataset
111
 
112
  ```python
113
  from datasets import load_dataset
114
 
115
+ easy = load_dataset("klein-ml/klein-code-bench", "easy", split="test") # 65 tasks
116
+ all_tasks = load_dataset("klein-ml/klein-code-bench", split="test") # 260 tasks
 
 
117
  ```
118
 
119
+ Each tier is its own config with a single `test` split; the default config contains all four. There is no
120
+ training split, and no loading script or `trust_remote_code` is needed. Pin `revision` to a commit when you
121
+ report results.
122
 
123
+ | Field | Content |
124
  | --- | --- |
125
+ | `task_id` | Stable unique ID |
126
+ | `subset`, `family`, `category`, `title` | Tier and task description |
127
+ | `target_model_parameters` | Intended model-size band (not calibrated) |
128
+ | `language`, `entrypoint`, `protocol_version` | Python, `main.py`, protocol version |
129
+ | `prompt` | The full specification the model sees |
130
+ | `public_tests` | Example requests and responses (JSON string) |
131
+ | `acceptance_tests` | Evaluator scenarios: sessions, requests, expected responses (JSON string) |
132
+ | `num_scenarios`, `num_assertions`, `timeout_seconds` | Test counts and the per-session time limit |
133
 
134
+ The test fields are stored as JSON strings so that all tasks share one schema; decode them with `json.loads`.
135
 
136
+ **Never put `acceptance_tests`, the reference implementations or the evaluator source into the model's prompt,
137
+ context or workspace.** They're public for reproducibility, so the benchmark depends on you keeping them away from the
138
+ model.
139
 
140
+ ## Scoring
141
 
142
+ The metric is **resolve@1**: one project per task, and it counts only if every test passes.
143
 
144
+ - **Per tier:** resolved tasks / 65. **Overall:** resolved tasks / 260.
145
+ - Missing submissions count as failures. The report also shows the rate among submitted tasks and flags incomplete runs.
146
+ - Partial assertion success is reported for diagnosis, but it never counts as resolved.
147
 
148
+ Each scenario starts from a fresh copy of the submission and an empty state directory; sessions within a max-tier
149
+ scenario share that directory. JSON comparison keeps array order and tells booleans apart from numbers. Floats use
150
+ an absolute and relative tolerance of 1e-9; integers are compared exactly. Default limits are 10 seconds per session
151
+ and 1 MiB of stdout. Details: [evaluation protocol](docs/EVALUATION.md).
152
+
153
+ | Tier | Assertions |
154
+ | --- | ---: |
155
+ | easy | 3,075 |
156
+ | intermediate | 5,415 |
157
+ | hard | 9,705 |
158
+ | max | 15,490 |
159
+ | **total** | **33,685** |
160
+
161
+ The tests cover:
162
+
163
+ - 65 hand-written golden outputs
164
+ - 24 generated inputs per family (seed 1729, shared across tiers)
165
+ - boundary cases and malformed requests
166
+ - failure atomicity, nested rollback and revision conflicts
167
+ - retry and restart sequences
168
 
169
+ All expected outputs are computed before grading, never inside the candidate's process.
 
170
 
171
+ ### Verifying the benchmark itself
172
+
173
+ ```bash
174
+ python -m unittest discover -s tests -v # unit and property tests for the benchmark and runner
175
+ klein-bench build # regenerate data and manifest from source
176
+ klein-bench validate --output results/validation.json # every reference must pass, every empty project must fail
177
  ```
178
 
179
+ The reference implementations exist to maintain the evaluator. Export one for auditing with
180
+ `klein-bench reference TASK_ID --output DIR`. The published `validation-summary.json` documents the dataset
181
+ manifest and validation totals; it is not a model score.
182
+
183
+ ## Security
184
+
185
+ The runner is **not a sandbox**. It does the following:
186
+
187
+ - removes inherited credentials from the environment
188
+ - runs each submission from a temporary copy
189
+ - rejects symlinks
190
+ - limits time and output
191
+ - kills the whole process group when it's done
192
+
193
+ Generated code can still reach your filesystem and network. Run it under a separate unprivileged user, on a machine
194
+ you can afford to lose. Timing depends on the host, so record your hardware with your results.
195
+
196
+ ## Provenance and limitations
197
 
198
+ - **Origin:** every task was written for this benchmark. None were copied from SWE-bench, LiveCodeBench or other
199
+ benchmarks. That covers how the tasks were authored; it doesn't guarantee that standard algorithms in the easy tier
200
+ never appear in a model's training data.
201
+ - **Scope:** Python only. The tests measure behavioral correctness, not code quality, architecture or UI. They don't
202
+ cover concurrent writers, disk corruption or power loss during a write.
203
+ - **Coverage:** the reference implementations and independent golden checks make the dataset internally consistent,
204
+ but the tests can't prove that no specification or expected output contains an error.
205
+ - **License:** MIT for prompts, test data and reference implementations.
206
 
207
+ ## Contributing
208
 
209
+ A new task needs:
210
 
211
+ - a contract (the specification)
212
+ - meaningful boundary tests
213
+ - an independent check of the expected outputs
214
+ - a reference implementation that passes
215
 
216
+ Changes to a contract or expected behavior require a new dataset version. Task IDs stay the same only for
217
+ backward-compatible fixes.