SLM-125M-SFT · legal/financial Q&A

A 125M-parameter language model, trained from scratch and fine-tuned to answer legal/financial questions — grounded in a passage you supply, or from general knowledge.

model card

Architecture

125.8M
parameters
16,384
vocab size
1,024
context length
~16.0
tokens per parameter
full architecture spec
parametervaluewhat it means
total parameters125.8Msize of the model — small enough to run inference on CPU with no GPU
vocabulary size16,384number of unique tokens the custom byte-level BPE tokenizer can produce
hidden size768width of each token's internal representation as it flows through the network
layers12number of stacked transformer blocks the input passes through
attention heads12parallel attention patterns computed per layer (head dim 64, standard multi-head attention)
feed-forward size3,072width of the expansion layer inside each block (SwiGLU activation)
context length1,024maximum number of tokens the model can attend over at once
tied embeddingsyesinput and output embedding matrices share weights, reducing parameter count
tokens per parameter~16.02.02B training tokens ÷ 125.8M params — a Chinchilla-style ratio; ~20 is considered compute-optimal
training

How it was built

1. Pretraining — from random weights

Next-token prediction only, no instruction data. Teaches the model to speak the legal/financial register fluently.

2.02B
training tokens (1 epoch)
~10.4
val perplexity
8×H100
~13 min compute
≈$6.60
compute cost (est., list price)
case law — 35.5% SEC filings — 41.5% fineweb-edu — 23.0%
optimizer & schedule
learning rate6e-4 → 6e-5step size for weight updates; cosine decay from a high starting rate
warmup200M tokensgradually ramps up the learning rate at the start to avoid early instability
global batch size524,288 toktotal tokens averaged per optimizer step, via gradient accumulation
weight decay0.1regularization that discourages overly large weights
gradient clipping1.0caps the gradient norm to prevent destabilizing update spikes

2. Fine-tuning (SFT) — teaching Q&A

Continues training from the pretrained checkpoint on Q&A pairs generated by Gemini, at a much lower learning rate.

11,989
Q&A examples used
317.8K
answer tokens learned
2.54→1.28
val loss
12.7→3.6
val perplexity
99.3%
grounding accuracy (judged sample, n=1,281)
1×H100
<$0.50 (est.)
grounded (passage-based) — 9,980 open-domain (no passage) — 2,009

The open-domain slice was added after the first fine-tune reflexively refused every no-passage question — see "What this is" below. Grounding accuracy is a separate quality check: a second LLM pass verified whether each generated answer was actually supported by its source passage, on a partial judged sample taken early in generation (full-dataset judging was skipped afterward since accuracy was already high, deferred to a later spot-check).

optimizer & schedule
epochs3full passes over the fine-tuning dataset
learning rate2e-5 → 2e-6much lower than pretraining, since we're adapting an already-trained model
warmup30 stepsshort ramp-up — fine-tuning starts from an already-stable checkpoint
weight decay0.01lighter regularization than pretraining
head-to-head

vs. Gemma-2-2B (QLoRA)

Both models generated answers to the identical 200 held-out questions (never trained on by either model — same shuffle seed used for both). A blinded LLM judge graded each answer independently against the reference answer, never told which model produced it.

metricnSLM-125MGemma-2-2BGemma-RQ (compressed)
grounded accuracy15551.6%92.9%92.9%
open-domain accuracy4515.6%80.0%86.7%
grounding / faithfulness rate15557.4%93.5%93.5%

Gemma wins clearly on every axis — expected given the ~21x parameter gap (125M vs. 2.64B) and Google's much larger pretraining. This isn't a fair fight on raw quality: 125M-from-scratch-and-fully-fine-tuned vs. 2.64B-pretrained-and-QLoRA-adapted differ in more than one variable at once (different tokenizers — 16K custom BPE vs. 256K SentencePiece, so the val-loss numbers above aren't comparable across the two models — full fine-tune vs. adapter, and pretraining scale). Try both side by side on the Gemma demo, or see Gemma's base and fine-tuned weights on Hugging Face. The Gemma-RQ column is the same fine-tuned Gemma with its 590M-parameter embedding compressed to 3.59 bits/param via a unified residual codebook — quality essentially unchanged; see the compression demo.

playground

Try it

80% of random pulls come from the 45 held-out questions never used in training (a true generalization test); 20% come from the ~1,964 open-domain training questions (more variety, but the model may recall a memorized answer). Each pull is labeled below.

ready
Pick a model above — the answer will appear here.
honest limitations

What this is

This model was fine-tuned on two distinct skills. With a passage, it's a grounded reader — it reads whatever text is in the passage box at that moment and answers strictly from it, including saying "Not stated in the passage." when the answer genuinely isn't there. It isn't recalling memorized facts about that passage; it's doing live in-context extraction, the same skill it would apply to any new text, including the random excerpts pulled above.

With no passage, it answers from general legal/financial knowledge learned during pretraining and reinforced by ~2,000 open-domain Q&A examples — added after the model's first version reflexively refused every no-passage question, since none of its original fine-tuning examples omitted a passage.

At 125M parameters it can miss specific numbers, repeat itself, or give an imperfect answer in either mode — treat answers as a starting point, not a citation.