πŸͺ· Prajna-CRNv2 β€” Safe Error Correction for Language Models

GitHub HF downloads Correction Degradation Base Hardware

Fix a frozen model's errors without breaking what it already does well.

Prajna-CRNv2 is a tiny correction module (34M params, 0.73% of the base) that sits on top of a fully frozen Gemma-4-E2B and learns to adjust its logits where it detects errors. The base model is never updated β€” not one gradient, not one weight. What you get is error correction with zero measurable capability loss, trained end-to-end on a Mac Mini M4.

corrected_logits = base_logits + gate * up(gelu(down(hidden)))

Built by eulogik Β· Code + paper: github.com/eulogik/prajna

✨ Why it matters

Fine-tuning fixes errors but causes forgetting β€” the correction–capability tradeoff. A LoRA baseline on the same exam corrects more (83.3%) yet destroys 30–75% of base capabilities (MMLU 62.5% β†’ 32%, car-wash 75% β†’ 0%). Prajna-CRNv2 corrects 53.3% while matching the frozen base exactly on every tested benchmark. For deployment, a model that fixes some errors and stays reliable beats one that fixes more and breaks reasoning.

πŸ† Results

CEHRI Original (60) CEHRI Reworded (120) MMLU (200) BoolQ (200) Car-wash (8)
Frozen base 11.7% β€” 62.5% 72.0% 75.0%
Prajna-CRNv2 53.3% 43.3% 62.5% (Ξ”=0) 72.0% (Ξ”=0) 75.0% (Ξ”=0)
LoRA baseline (6.6M) 83.3% 77.5% 32.0% (βˆ’30.5pp) 55.0% (βˆ’17pp) 0% (βˆ’75pp)

A hidden-state injection sweep (1.6M-param variant at layers 4/7) confirms ~53% as the ceiling for frozen-base methods β€” deeper injection helps (30% β†’ 50%) but never beats logit correction. See the paper for the full story, including ablations and limitations.

Correction: CRN v2 vs LoRA vs frozen base Capability preservation: CRN v2 matches base, LoRA collapses

Injection-depth sweep (experimental)

Variant Training CEHRI Original CEHRI Reworded Capability
Deep layer 4 (1.6M) SFT-only 30.0% 28.3% not probed
Deep layer 7 (1.6M) SFT-only 50.0% 55.8% intact (small probe)
Deep layer 7 (1.6M) SFT + DPO 50.0% 55.0% destroyed (MMLU 13%)
Logit CRN v2 (34M) SFT + DPO 53.3% 43.3% intact

Injection-depth sweep

πŸš€ Quickstart

pip install torch transformers
import torch, sys
sys.path.insert(0, ".")  # for crn_v2.py
from crn_v2 import CRNv2

model = CRNv2(device="mps" if torch.backends.mps.is_available() else "cpu")
model.load("crn_v2_dpo.pt")  # 34M correction weights (this repo)

print(model.generate("What is the capital of France?"))
# Or correct a draft answer:
print(model.correct("What is 2+2?", "5"))

Or use the interactive demo:

python inference.py
python inference.py --prompt "What is 2+2?" --draft "5"

Requirements: Python 3.10+, PyTorch 2.0+, ~10GB RAM (Gemma-4-E2B loads in float16; set HF_HOME to an external disk if space is tight).

πŸ“ Files

File Size Purpose
crn_v2_dpo.pt 130 MB Trained correction weights (rank-128, SFT+DPO, KL Ξ»=0.1)
crn_v2.py β€” Architecture (LogitCorrection + CRNv2)
crn_deep.py β€” Experimental hidden-state injection variant (code only)
inference.py β€” Interactive demo / single-shot correction
config.json β€” Model + training metadata

πŸ”¬ Training

  • Stage 1 β€” SFT (2,000 steps): anchor-weighted answer-only CE (anchor 4Γ—, EOS 5Γ—) + KL preservation (Ξ»=0.1) on 83,400 error-correction pairs. AdamW, LR 3e-4, cosine decay.
  • Stage 2 β€” DPO (500 steps): reference-free preference of the correct answer over the frozen base's wrong answer (Ξ²=0.1, LR 5e-6).
  • Hardware: Apple M4, 16GB, MPS β€” ~25 min end-to-end. Base frozen throughout.

πŸ€” FAQ

Is the base model modified? No. Every base parameter is frozen; only the 34M correction module trains.

Why 53.3% and not higher? Frozen-base correction has a real ceiling (~53% here) β€” closing the gap to weight-modifying methods costs capabilities. We publish the boundary as carefully as the headline; see Limitations in the paper.

Does it generalize? The exam prompts appear verbatim in training (in-distribution: 53.3%); the reworded exam measures near-duplicate correction (43.3%). Neither tests out-of-distribution generalization β€” stated openly.

Can I retrain it? Yes β€” full pipeline (data, SFT+DPO trainers, evals) in the GitHub repo.

πŸ“œ License

Weights + code released under Gemma terms (as required by the base model). Research use. See the paper for methods, ablations, and limitations.

πŸͺ· Prajna β€” "wisdom": fix errors, keep knowledge.

Downloads last month
147
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for eulogik/Prajna-CRNv2

Finetuned
(122)
this model

Evaluation results