Instructions to use s-ttp/aiva-rlcd-modernbert with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use s-ttp/aiva-rlcd-modernbert with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="s-ttp/aiva-rlcd-modernbert")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("s-ttp/aiva-rlcd-modernbert", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download training/README.md from s-ttp/aiva-rlcd-modernbert: direct link, hf CLI and curl.
- Browser
- Download file 10.8 kB
-
https://huggingface.co/s-ttp/aiva-rlcd-modernbert/resolve/main/training/README.md
- Command line
-
hf download hf://s-ttp/aiva-rlcd-modernbert/training/README.md
-
curl -L -o README.md https://huggingface.co/s-ttp/aiva-rlcd-modernbert/resolve/main/training/README.md
RLCD training kit
A standalone version of the recipe behind s-ttp/aiva-rlcd-modernbert: write a rubric, build labelled
requests, train one encoder with one head per output, calibrate, evaluate, ship. Use it to retrain RLCD for
your own organisation, wording and taxonomy.
The published model was built with the AiVa proof of concept's internal pipeline. This kit is a standalone port of its recipe and settings. It differs in three ways:
- attachments are built from templates, or from your own
documents/<level>/*.txt, not from a synthetic world of records; - literal identifiers are caught by patterns, not by a DLP engine;
- it has no template-shaped rows.
It was tested end to end at small scale (see the end of this page). It has not been used to reproduce the published model at full size.
| File | What it does |
|---|---|
taxonomy.json |
The rubric and generation settings: heads, classes, definitions, tie-breaks, the sensitivity checklist, identifier formats, personas, styles, subjects and traps. The shipped file is the one the published model was built from. |
generate.py |
synth: synthetic labelled requests (code fixes the labels, an LLM writes the wording, code checks, a verifier gates). label: verifier labels for your own requests, for human review. |
train.py |
Trains ModernBERT with one head per output and fits one temperature per head. |
evaluate.py |
Accuracy, macro-F1, calibration, coverage/accuracy curves, sensitivity under- and over-classification with 95% intervals, and CPU latency. |
rlcd.py |
The loader the model card uses; train.py saves in its layout. |
pip install "torch>=2.4" "transformers>=4.48" safetensors huggingface_hub openai
1. Write your rubric
Edit taxonomy.json:
organisation,families(personas, channels, styles and app prompts),themesandtrapsdescribe your world. Keep two families: the test split is written by people, through channels and in styles that training never saw.attachmentslists the pasted-material kinds, the level each carries and the tasks that can use it. A policy question gets a policy excerpt; a billing question gets a bill. To use your own policy text, put excerpts indocuments/<level>/*.txtnext totaxonomy.json.not_qa_themes,complexity_capandidentifier_ruleskeep the specs coherent:- a question about a process is
rag, notqa; - a short answer is never a six-step plan;
- a confidential request that needs a lookup always names its subject's identifier.
The verifier rejects incoherent specs, so these rules decide how much of your spend becomes data.
- a question about a process is
headsholds each head's classes, in order, with a definition. Ordersensitivityandcomplexityfrom least to most.tie_breaks: write one wherever two reviewers would disagree. Add more after a pilot: the rejected rows show where the definitions are unclear. The published model's tie-breaks came from reading its rejected rows:agenticagainst a lookup came from its pilots;qaagainstrag, and the customer account number, came from the first build of its test split, which was then re-verified before it was frozen.
sensitivity_checklist: yes/no questions about what the text contains, in order, each with the level it implies. The verifier answers these, and code derives its level. In AiVa's pilot, a verifier asked to name a level directly skipped literal API keys and explicit national-security notices.placeholders: the identifiers code inserts, with the lowest level each implies and its format (#digit,?letter,*letter or digit;luhnadds a check digit;ibanadds country and check digits). Use your own countries' formats.
generate.py relies on what the four heads mean: the task drives what is asked, sensitivity drives the
subject and identifiers, complexity drives the number of steps, and context need drives retrieval and
pasted material. Rename, add or remove classes freely. Changing what a head means needs code changes.
2. Build data
Your own traffic is best. Label it with the verifier, then have people review it. Review every row where
the two verifier wordings disagree (agreed: false), and a sample of the rest:
python generate.py label --input my_requests.jsonl --out labelled.jsonl # {"messages": [...]} per line
Synthetic requests. Any OpenAI-compatible endpoint works. Pick a model that is neither the one you train nor one you route to. On the Hugging Face router, pin one provider for every split, so the splits do not differ by serving stack:
export GEN_API_KEY=... # or HF_TOKEN for the Hugging Face router (the default endpoint)
export GEN_MODEL=openai/gpt-oss-120b:deepinfra
python generate.py synth --split test --n 5000 --verifier-passes 2 --second-pass report \
--reserve my_spot_checks.txt --out data/test.jsonl --rejects data/test.rejects.jsonl
python generate.py synth --split validation --n 4000 --verifier-passes 2 --reserve my_spot_checks.txt \
--against data/test.jsonl --out data/validation.jsonl
python generate.py synth --split train --n 30000 --reserve my_spot_checks.txt \
--against data/test.jsonl --against data/validation.jsonl --out data/train.jsonl
This is how the published model's splits were built:
- Train: one verifier pass.
- Validation: a second, reworded pass, keeping only the rows both passes agree on (
--verifier-passes 2). - Test: one pass. The second wording is only recorded, as
twice_agreed(--second-pass report). Filtering the test split with both passes would remove its ambiguous rows and make scores read higher.
--reserve keeps rows that share an 8-word run with your own evaluation prompts out of the data.
--max-calls caps the LLM calls; by default the cap is the worst case, 5 per spec.
Expect about half of the specs to be kept with one verifier pass, and fewer with two. For the published model:
- 29,000 train specs gave 16,192 kept rows (55.8%).
- A second verifier wording kept 84.3% of the validation rows that passed the first.
- Generation cost 0.50–0.54 thousandths of a US dollar per kept row. The training and validation data came to about $10, and the test split to about $2 more, estimated from the provider-reported tokens at the router's list price.
Generate the test split first, freeze it, and never tune on it.
Read the rejects file after a pilot of a few hundred specs. The disagreed on … counts show which heads, and
which boundaries, need a clearer definition or tie-break.
3. Train
python train.py --data data/ --out rlcd-mine --balance-sensitivity 0.5 --bucket-by-length \
--prior public=0.146,internal=0.527,confidential=0.297,restricted=0.024,sovereign-only=0.006
- Rows have
text(ormessages) and one field per head. A row may leave a head out. - The defaults are the published model's recipe: 3 epochs, AdamW, learning rate 5e-5 with a cosine schedule, batch 32 and 1,024 tokens.
- Set
--priorto your production sensitivity mix. It weights the temperature fit. --init-from s-ttp/aiva-rlcd-modernbertcontinues from the published checkpoint. Heads whose classes are unchanged keep their weights; changed heads start fresh.- The learning rate then defaults to 2e-5.
- The encoder still moves, so a head your rows never label gets no training signal and can drift. The trainer warns about such heads. Label every head where you can, and score the unchanged heads on held-out rows before you ship.
- This path has not been tested at scale.
- Use a GPU. The published model's run of 38,118 rows took 13 minutes on one A100, about $0.58 of Hugging Face Jobs time.
4. Evaluate and decide
python evaluate.py --model rlcd-mine --data data/test.jsonl --latency 200 \
--prior public=0.146,internal=0.527,confidential=0.297,restricted=0.024,sovereign-only=0.006
evaluate.pyreports every figure as sampled. With--prior, it adds figures weighted to your traffic mix beside them, never instead.- Macro-F1 averages over every class, as the published figures do, so a class absent from the split scores 0.
For small or partial splits, use
--macro-f1-over present. - Add a
dlpfield (your DLP's level) to each test row to see the rate with DLP alongside.
Set the bar before you look at the results. The published model had 33 gates on its frozen test split, and passed all 33. Eight were regression floors on an older template test set, which this kit doesn't include. The macro-F1 gates were judged as sampled. The calibration and classification-safety gates were judged both as sampled and under a realistic prior. The others included:
| Measure | Target |
|---|---|
| Macro-F1: task / sensitivity / context need / complexity | ≥ 0.90 / 0.90 / 0.85 / 0.75 |
| Confidential-or-higher classified too low, RLCD or DLP | ≤ 2%, and ≤ 3% for each level |
| … RLCD alone | ≤ 5% |
| Public or internal raised to ≥ confidential / ≥ restricted / sovereign-only | ≤ 5% / 2% / 1% |
| Expected calibration error, every head | ≤ 0.05 |
| CPU p95 latency, 8 vCPU | ≤ 800 ms |
5. Ship
- The output folder loads with
rlcd.RlcdClassifierand the model card's loader. - Push it to a private repository and pin the revision you tested.
- Choose thresholds from
coverage_accuracy. - Check that your serving code gives the same probabilities as
evaluate.pyon a few rows.
How this kit was tested
All tests ran on a 4-vCPU machine with torch 2.14.1, transformers 5.19.0 and openai/gpt-oss-120b on
the Hugging Face router:
generate.pyOffline, on 3,000 specs per split:
- class quotas are exact, and train and test personas are disjoint;
- qa and rag respect their subject and complexity limits;
- attachments fit the task, and identifiers follow the rules;
- all 13 attachment kinds build at their levels and lengths;
- generated card numbers, ICCIDs and IBANs pass their check digits.
The checks catch literal identifiers and credentials, wrong placeholders, reserved prompts and material above the label.
Live, with the provider pinned, 28 specs through the router: 11 of 20 were kept with one verifier pass, and 5 of 8 with two.
train.py: 12 rows, 3 steps, run twice:- from the pinned ModernBERT-base, with balancing, length buckets and the prior;
- from this checkpoint, with sensitivity remapped to three classes. Only that head started fresh, the learning rate defaulted to 2e-5, and the trainer warned about the heads the rows left unlabelled.
Both outputs reloaded with
RlcdClassifier.evaluate.py: run on the published checkpoint and on the remapped model.
These runs show that the code works. Their scores are meaningless at this size.