Legal & financial language, learned from nothing.
Trained from a random initialization on 2.04 billion tokens of US case law, SEC filings and educational web text, then asked to keep writing.
Everything we built, at a glance
Three origins — a 125M we pretrained from noise, the mentor's 500M we adopted, and Google's Gemma 2 2B off the shelf — each run through the same five-phase pipeline: pretrain, SFT, RAFT, DPO, and RLAIF. Twenty-two models in all. Everything below is live.
Complete the passage
Give it the opening of a brief, a filing, or an opinion, then watch the model continue it, one token at a time. These are the real 125M model weights, generating live.
This is a base model: it continues text, it does not answer questions. It will confidently invent case names, citations and figures. Never rely on its output as legal, financial or factual advice.
Now ask it a question
Fine-tuned on 5,846 grounded legal & financial Q&A pairs, the same 125M model stops rambling and starts answering. It is a separate model, legal-slm-125m-sft ↗, that streams its reply as you watch.
Ask a legal or financial question. Pick a starter below or type your own.
Three SFT models on the same Q&A data: our 125M and 500M (full fine-tune) and Gemma 2B (QLoRA). The smaller ones will confidently invent case names and figures; the bigger ones are more fluent. Not legal or financial advice.
Now ground it in your context
One more layer. legal-slm-125m-raft ↗ was RAFT-tuned (Retrieval-Augmented Fine-Tuning) to answer from context you provide, quote the exact source, and ignore unrelated distractor text. Paste a passage, add some noise, and ask.
RAFT (Retrieval-Augmented Fine-Tuning): the model answers from the context you provide and ignores distractors. Faithfulness scales: the 125M can't reliably tell when the answer is absent (it will make one up), the 500M starts to, and Gemma declines cleanly — ask about something not in the context and compare. Not legal or financial advice.
Preference-tuned: DPO and RLAIF
After SFT and RAFT, one more layer: align the model to preference. Pick a method — direct preference optimization (DPO), or a reward model plus GRPO (RLAIF) — a base stage to build on, and a size. Twelve real models, live on the GPU.
Every combination is a real model on Hugging Face: DPO or RLAIF (reward model + GRPO), on top of the SFT or RAFT version, at 125M, 500M, or 2B. Preference optimization mostly tunes tone and structure, so read for quality, not just correctness. Not legal or financial advice.
Same data, two very different models
We ran the identical SFT and RAFT datasets through a real pretrained model — Gemma 2 2B ↗ — using QLoRA (4-bit base, only 0.79% of weights trained). Pick it in the model selectors of the Chat, RAFT, and Alignment panels above, next to our 125M and 500M. Here is exactly what each phase costs and trains.
Our SLM · 125M
from scratch- Trainable
- 125.8M · 100%
- Train tokens
- 4.08B · 2 epochs
- Compute
- 8×H100
- Cost
- ~$36
- Trainable
- 125.8M · 100%
- Train tokens
- 1.06M · 2 epochs · 5,846 Q&A
- Compute
- 1×L4
- Cost
- ~$0.05
- Trainable
- 125.8M · 100%
- Train tokens
- 5.42M · 2 epochs · 3,866 ctx
- Compute
- 1×L4
- Cost
- ~$0.30
Gemma 2 · 2B
pretrained · QLoRAThe trade is the whole lesson. Our 125M was built from a random init for ~$36 and is small enough to run in a browser tab — but it is a toy. Gemma borrows a $millions Google pretraining for free, trains 20.8Madapter weights instead of all 2.6B, and answers far more fluently — but it needs a GPU to serve, and every token it "knows" came from someone else's pretraining, not ours.
Every model, one scoreboard
Every model on the same held-out sets, in two views. Quality is an independent LLM judge (DeepSeek-V3, which made none of our training data) scoring each answer out of 10 against a gold reference and its evidence — reference-grounded, so it is checkable rather than vibes, and it finally makes the DPO/RLAIF work visible. Capability is the tokenizer-fair side: bits-per-byte language modeling plus exact-match accuracy. Both include Gemma 2 2B off the shelf, so you can see what a real pretrained model scores with zero legal training.
| Model | Mean /10 ↑ | QA ↑ | Grounded ↑ | Refusal ↑ | Quote valid ↑ | Over-refusal ↓ |
|---|---|---|---|---|---|---|
Gemma RAFT2.61B | best8.13 | 5.80 | best8.70 | best10.00 | best94% | 25% |
Gemma RAFT + RLAIF2.61B | 8.04 | 6.50 | 7.97 | best10.00 | 67% | 93% |
Gemma RAFT + DPO2.61B | 7.94 | 5.77 | 8.28 | best10.00 | 61% | 28% |
Gemma 2B (off-the-shelf)2.61B | 7.23 | 3.97 | 7.95 | best10.00 | — | 23% |
500M RAFT517M | 6.24 | best6.73 | 6.30 | 5.56 | 84% | 25% |
500M RAFT + DPO517M | 6.13 | 5.80 | 6.40 | 6.08 | 79% | 25% |
Gemma SFT2.61B | 6.02 | 5.87 | 5.80 | 6.56 | — | best0% |
Gemma SFT + RLAIF2.61B | 5.88 | 5.17 | 5.75 | 6.96 | — | best0% |
500M RAFT + RLAIF517M | 5.77 | 5.57 | 6.38 | 5.04 | 79% | 25% |
Gemma SFT + DPO2.61B | 5.55 | 4.77 | 5.03 | 7.32 | — | best0% |
500M SFT + RLAIF517M | 4.80 | 4.20 | 2.75 | 8.80 | — | best0% |
Our SFT + RLAIF125.8M | 4.47 | 2.47 | 3.25 | 8.84 | — | 3% |
500M SFT + DPO517M | 4.21 | 3.87 | 2.88 | 6.76 | — | best0% |
Our SFT + DPO125.8M | 4.14 | 2.90 | 2.33 | 8.52 | — | best0% |
500M SFT517M | 3.95 | 3.60 | 2.92 | 6.00 | — | best0% |
Our SFT125.8M | 3.89 | 2.80 | 1.82 | 8.52 | — | 3% |
Our RAFT + DPO125.8M | 3.78 | 2.23 | 3.33 | 6.36 | 44% | best0% |
Our RAFT + RLAIF125.8M | 3.76 | 2.93 | 4.28 | 3.92 | 37% | best0% |
Our RAFT125.8M | 3.29 | 3.00 | 3.95 | 2.60 | 39% | best0% |
500M base (mentor)517M | 2.36 | 1.27 | 1.85 | 4.48 | — | best0% |
Our base125.8M | 1.95 | 1.17 | 1.43 | 3.72 | — | best0% |
Mentor base125.8M | 1.55 | 0.37 | 0.45 | 4.72 | — | best0% |
Mean /10 ↑ — Mean judge score across all held-out items, out of 10 (correctness 0-5 · completeness 0-2 · groundedness 0-2 · clarity 0-1).
QA ↑ — Closed-book QA — answer from the weights, no context.
Grounded ↑ — Grounded (RAFT) — answer with the relevant context provided.
Refusal ↑ — Unanswerable — the correct answer is to decline; fabricating scores near 0.
Quote valid ↑ — Of grounded answers that quote, the fraction whose quote really appears in the context (programmatic).
Over-refusal ↓ — Fraction of ANSWERABLE questions the model wrongly declines. Lower is better.
Judge: deepseek/deepseek-chat at temperature 0, blind and pointwise, graded against gold answers + evidence from a held-out corpus set (it made none of our training data). Green marks the best in each column. Re-judge self-agreement: 64% exact, 79% within one point.
Two things jump out. Grounded accuracy climbs at every stage — our tiny model goes 1.4% → 7.1% → 24.3% across base → SFT → RAFT, and Gemma lands highest at 37%. But watch the faithful-refusal column: Gemma off-the-shelf already declines 90% of unanswerable questions, our SFT step destroys that instinct (it learns to always answer, 0%), and only RAFT with abstention examples brings it back — to 100% for Gemma. And you can watch abstention emerge with scale: the 125M RAFT never learns to refuse (0%), the 500M RAFT starts to (20%), Gemma nails it (100%). Faithfulness isn't a prompt trick — past a point it's a capability that costs parameters.
The + DPO and + RLAIF rows are a full preference-optimization sweep on top of every SFT and RAFT model (DPO on ~4.7k AI-labeled pairs; RLAIF = a Bradley-Terry reward model then GRPO). Read them honestly: these methods tune response quality and style— helpfulness, structure, and, where the pairs teach it, faithfulness — which strict exact-match accuracy barely registers. So the capability columns hold roughly steady (they mostly don't regress), faithful refusal is preserved (Gemma RAFT stays at 100% through both), and where a model over-optimizes you can see it: Gemma RAFT + DPO's bits/byte balloons to 1.59 as it leans hard into the preferred abstain-heavy style. Quantifying the quality gain itself would need an LLM-judge win-rate — the natural next column.
What the whole thing cost
Every model on the board, every dataset, every GPU-hour — tracked. Building a base model from scratch is the expensive part; adapting one is cheap. Here is the honest ledger.
Estimated from GPU type × wall-clock on Modal (H100 ~$3.95/hr, A100-40 ~$2.10/hr, L4 ~$0.80/hr) plus OpenRouter and Gemini usage. The pretraining alone is ~45% of it; every fine-tune after that — SFT, RAFT, six DPO models, two reward models, six RLAIF models — together cost less than the base model did. The borrowed bases (the mentor's 125M and 500M, and Gemma 2B) cost us nothing to make — that is the whole economic case for building on pretrained models.
Making generation fast
Two optimizations every real serving stack uses, running live on GPUs. The first is exact and free; the second is exact but only pays off when a small model can guess what a big one will say.
Without a KV cache the model recomputes attention over the whole growing sequence every step. With it, each step reuses the stored keys/values. Raise the batch size (more concurrent "users") and watch the gap explode.
The small 0.5B draft proposes several tokens at once; the big 7B target verifies them in a single pass and keeps the longest prefix it agrees with. Same output as the 7B alone, but the speedup rides entirely on how often the draft is right.
The lesson in both: throughput is not one number. The KV cache turns a quadratic cost linear, and its payoff grows with how many users you batch together. Speculative decoding trades extra draft compute for fewer expensive target steps, and only wins when the draft agrees often enough — try a numbered list versus a poem and watch the acceptance rate, and the speedup, move together.
Small model, honest accounting
Perplexity, falling
Held-out perplexity measured on a 20.6-million-token validation set the model never trained on. Two epochs, 7,778 optimizer steps, from a random start to 9.13.
A Llama, in miniature
- Architecture
- Llama-style decoder
- Layers · dim · heads
- 12 · 768 · 12
- Head dimension
- 64 (multi-head)
- Context length
- 1,024 tokens
- Positional
- RoPE (θ = 10,000)
- Normalization
- RMSNorm (1e-5)
- Activation
- SwiGLU (silu)
- Vocabulary
- 16,384 byte-level BPE
- Embeddings
- tied input / output
- Precision
- bfloat16
Two billion tokens, hand-cleaned
Streamed from public datasets, then run through a deterministic pipeline: rule-based cleaning, an OCR-garble gate, MinHash-LSH near-duplicate removal, and 13-gram decontamination against the CaseHOLD and LexGLUE benchmarks.
- 35%US case lawHFforLegal/case-law
- 42%SEC filingsPleIAs/SEC
- 23%Educational webfineweb-edu
What this is, and is not
It is a base (pretrained) model, a next-token predictor. It has never been instruction-tuned, aligned, or shown a single question-answer pair.
It will fabricate case names, docket numbers, statutes and financial figures with total confidence. Everything it writes is fiction shaped like law.
English only, 1,024-token context, 125M parameters. It is a study in doing a lot with very little. It is not a product, and never legal or financial advice.
