Views
No views yet
Research Artifact — Not Production-ReadyThis model verifies code implementation responses using structural binary features. It achieves AUROC 0.867 on the held-out test set (Exp 89 reference: 0.9096). It detects common off-by-one, wrong-initialization, and wrong-logic bugs — not arbitrary code errors.
E(x) = -(b^T s + s^T J s) s = 2x - 1 ∈ {-1, +1}^200range(1, n + 1)" is strongly coupled to correctness in sum-range tasks).| Hyperparameter | Value |
|---|---|
| Training pairs | 400 (80% of 500 generated) |
| Feature dimension | 200 binary features |
| Learning rate | 0.01 |
| L1 regularization | 0.0 |
| Weight decay | 0.005 |
| Epochs | 300 |
| Source | Exp 62 (domain CD) + Exp 89 (self-bootstrap) |
| Function | Correct pattern | Bug pattern |
|---|---|---|
| sum_range | range(1, n + 1) | range(1, n) (off-by-one) |
| find_max | result = lst[0] | result = 0 (wrong init) |
| is_even | n % 2 == 0 | n % 2 == 1 (inverted) |
| factorial | base case n == 0 | base case n == 1 (misses 0!) |
| reverse_string | s[::-1] | s[::1] (no-op) |
| count_vowels | s.lower() | missing lower() |
| fibonacci | base case n <= 0 | base case n == 1 |
| binary_search | lo = mid + 1 | lo = mid (infinite loop) |
| is_palindrome | s == s[::-1] | s == ''.join(sorted(s)) |
| flatten | result.extend(flatten(item)) | result.extend(item) (shallow) |
| Metric | This export | Exp 89 reference |
|---|---|---|
| AUROC (test) | 0.8669 | 0.9096 |
| Accuracy (test) | 88.0% | 88.0% |
| Test set size | 100 | 25 |
| Baseline AUROC | 0.5 | 0.5 |
1import numpy as np
2from carnot.inference.constraint_models import ConstraintPropagationModel
3
4# Load model
5model = ConstraintPropagationModel.from_pretrained(
6 "exports/constraint-propagation-models/code"
7)
8
9# Encode a code response
10from scripts.export_constraint_models import encode_answer
11question = "Write a function that returns the sum of integers from 1 to n."
12correct_code = "def sum_range(n):\n total = 0\n for i in range(1, n + 1):\n total += i\n return total"
13buggy_code = "def sum_range(n):\n total = 0\n for i in range(1, n):\n total += i\n return total"
14
15x_correct = encode_answer(question, correct_code)
16x_buggy = encode_answer(question, buggy_code)
17
18print(f"Correct energy: {model.energy(x_correct):.2f}") # should be lower
19print(f"Buggy energy: {model.energy(x_buggy):.2f}") # should be higher
20print(f"Correct score: {model.score(x_correct):.3f}") # should be higher
21print(f"Buggy score: {model.score(x_buggy):.3f}") # should be lowerrange(1, n + 1)" or "has isinstance" — does not execute or parse the code.| File | Description |
|---|---|
model.safetensors | Coupling matrix J (200×200) and bias b (200,) as float32 |
config.json | Training metadata and benchmark results |
README.md | This file |
1@misc{carnot2026constraint_code,
2 title = {Carnot Constraint Propagation Model: Code},
3 author = {Carnot-EBM},
4 year = {2026},
5 url = {https://github.com/ianblenke/carnot}
6}pip install carnot