Generates structured decision training data in the Jev three-primitive format (choice/noul/score) from a user-supplied policy document (PDF, e.g. a compliance manual or employee handbook).
中文文档: README_zh.md
Reference file: sql-console-for-n4ze3m-typed-decisions-synth.json
Each sample contains:
state_id: unique identifiergenerator: generator versiondomain: domain namen_questions: number of questionsstate: state description as a JSON stringstate_is_json: whether the state is JSONquestions: question definitions (type/criteria/instructions)gold: deterministic gold answerteacher: teacher model probabilistic predictionteacher_model: teacher model name
| Type | Description | Gold format | Teacher format |
|---|---|---|---|
| choice | Pick-one decision | option name | {"probabilities": {"option1": 0.7, ...}} |
| noul | yes/no judgment | true/false | {"noul": 0.8} |
| score | ordinal rating | index/name | {"probabilities": {"low": 0.2, ...}} |
questions/gold/teacherare all JSON strings (not nested objects); parse withjson.loads.- score gold: integer index into the criteria list (0-based).
- score teacher: probabilities keyed by index strings (
"0","1", ...), normalized to sum to 1.0. - choice teacher: probabilities keyed by option name; noul teacher:
{"noul": float}. generator:v1-{domain}(e.g.v1-compliance).- Dual output: JSON array file (e.g.
dataset_50.json) + incremental JSONL (dataset_50.jsonl, one self-contained JSON object per line, used for resume). A fresh run (without--resume) deletes any existing<output>.jsonlfirst, so old samples never mix into a new dataset. - For fine-tuning, feed the
.jsonl— trainers such as Unsloth read line-delimited JSON directly; the.jsonarray is a single JSON document and cannot be parsed line by line. The.jsonfile is for human inspection, evaluation (evaluate_dataset.py), and reference-format alignment. - The output is already the target fine-tuning data format (field-aligned with the reference file); training pipelines that consume this format can use it directly, no extra conversion needed.
This dataset targets System One / Jev-style decision models (encoder + decision head architecture, e.g. the open-source Laya) — not conversational SFT data: such models take a state + typed questions and directly output probability distributions, with no text generation and no parsing.
Field mapping to the training schema (see Jev Cookbook Chapter 10 FINETUNING.md):
| Dataset field | Training schema | Notes |
|---|---|---|
state |
state |
state visible at decision time |
questions |
qs |
typed questions (choice/noul/score); one question asks exactly one thing |
gold |
y |
deterministic label (choice=option name, score=candidate index, noul=bool); the trainer maps it to index/0-1 per its own schema |
teacher |
soft |
soft target probability distribution, used for masked soft cross-entropy training |
Public benchmark dataset with the same schema: LocalLLaMA/typed-decisions (one state answered by multiple typed questions at once; every answer is a probability distribution).
Use generate_config.py to generate the domain config from the policy document, and call the LLM once to generate document-driven question templates, appended to templates/{domain}.json (deduplicated by key):
python generate_config.py --pdf <path-to-policy-doc>.pdf --domain complianceOutputs:
config_compliance.json: containskeywords(keyword list for extracting relevant sections),state_prompt_template(state generation prompt template),document_summary(document summary), etc.templates/compliance.json: newly generated question templates appended (with facts specs, deduplicated by key)
Offline mode (skip LLM template generation, config only):
python generate_config.py --pdf <path-to-policy-doc>.pdf --domain compliance --skip-templatesUse generate_dataset.py to load the config and generate training data:
python generate_dataset.py --pdf <path-to-policy-doc>.pdf --domain compliance --target 50 --output dataset_50.json [--resume] [--concurrency N] [--ensemble-n N]--concurrency: number of concurrent workers, default 1 (keep at 1 if your LLM server only supports sequential calls)--ensemble-n: number of teacher samples averaged; 3 = the reference file's "x3 mean"--resume: continue from an existing JSONL up to target (already-completed samples are not regenerated)
python evaluate_dataset.py --input dataset_50.jsonThe program configures three independent LLM endpoints; state_model and teacher_model are actively used, while gold_model is reserved (currently unused — gold answers are derived deterministically by rules in gold_rules.py, no LLM call):
| Model | Purpose | Config keys |
|---|---|---|
| state_model | generates scenario states | state_model.name, state_model.api_key, state_model.base_url |
| teacher_model | provides probabilistic predictions | teacher_model.name, teacher_model.api_key, teacher_model.base_url |
| gold_model | reserved (unused: gold is rule-derived) | gold_model.name, gold_model.api_key, gold_model.base_url |
See config.json; environment variable overrides are supported (STATE_MODEL_NAME, TEACHER_API_KEY, GOLD_BASE_URL, etc.).
- state_model (scenario state generation): a smaller model is fine — it only needs to produce structured scenario states from the prompt.
- teacher_model (probabilistic prediction): use a larger/stronger model in practice, to guarantee prediction quality.
--ensemble-n 3corresponds to the reference file's "x3 mean": sample 3 times and average the probabilities.
77 built-in Jev three-primitive question templates across multiple domains:
| Domain | Templates | Key topics |
|---|---|---|
| compliance | 23 | account opening, AML, trade execution, privacy, fraud, complaints, records, cognitive ability, advertising, ERISA, registration, business continuity |
| healthcare | 8 | patient consent, treatment plans, medical records, prescription risk, infection control, patient safety, emergency care, discharge planning |
| education | 8 | plagiarism, assignment compliance, academic integrity, grading fairness, special needs, attendance, behavior, learning outcomes |
| e-commerce | 8 | product listing, returns, seller compliance, review authenticity, payment fraud, shipping, refunds, disputes |
| hr | 30 | onboarding compliance, performance review, harassment complaints, leave approval, payroll compliance, offboarding, training, code of conduct, remote work, data privacy, overtime, workplace safety, hiring bias, promotion fairness, benefits, engagement, conflicts of interest, discipline, ... |
| File | Description |
|---|---|
generate_dataset.py |
main program: three-model architecture, multi-domain support, config-driven |
generate_config.py |
step 1: generate config + document-driven question templates from the policy document |
evaluate_dataset.py |
dataset quality evaluation (schema validation, type distribution, gold/teacher agreement) |
llm_client.py |
OpenAI-compatible LLM client (chat/chat_json, retries and JSON extraction) |
template_store.py |
per-domain template load/save (templates/{domain}.json, deduplicated merge by key) |
gold_rules.py |
deterministic gold derivation from state-embedded facts (identity/map/count_gte/gte/lte/eq/in) |
teacher.py |
teacher probability validation, normalization and ensemble averaging |
config_loader.py |
three-model endpoint config loading (config.json + env var overrides) |
templates/{domain}.json |
per-domain question templates (the single source of truth; e.g. 23 for compliance) |
question_templates.json |
pre-migration backup (old format), no longer read by the program |
scripts/split_templates.py |
splits the old question_templates.json into per-domain templates/ files |
tests/ |
unit tests (gold_rules, template_store, teacher, schema validation, etc.) |
config.json |
three independent LLM endpoint configs |
# 1. Generate config + document-driven templates
python generate_config.py --pdf <path-to-policy-doc>.pdf --domain compliance
# 2. Generate the dataset
python generate_dataset.py --pdf <path-to-policy-doc>.pdf --target 10 --domain compliance --output dataset_10.json
# 3. Evaluate the dataset
python evaluate_dataset.py --input dataset_10.json{
"state_id": "synth-xxx",
"generator": "v1-compliance",
"domain": "compliance",
"n_questions": 3,
"state": "{\"description\": \"...\", \"client_info\": {...}, ...}",
"state_is_json": true,
"questions": "{\"account_compliant\": {\"type\": \"choice\", \"instructions\": \"Determine whether this account opening process complies with company compliance policy.\", \"criteria\": {\"compliant\": \"...\", \"non-compliant\": \"...\", \"needs-review\": \"...\"}}}",
"gold": "{\"account_compliant\": \"compliant\"}",
"teacher": "{\"account_compliant\": {\"probabilities\": {\"compliant\": 0.95, \"non-compliant\": 0.03, \"needs-review\": 0.02}}}",
"teacher_model": "Qwen3.6-35B-A3B"
}Note: questions / gold / teacher are JSON strings (as shown above); consumers must parse them with json.loads.
To add a new domain (e.g. "finance"), modify the following:
-
templates/finance.json— create the Jev three-primitive question template list for the domain (every template must carry afactsspec, otherwise it does not participate in question selection):[ { "key": "loan_approval", "type": "choice", "instructions": "Determine whether the loan application meets approval criteria.", "criteria": {"approved": "...", "rejected": "...", "needs-review": "..."}, "facts": {"field": "loan.status", "rule": {"op": "identity"}}, "policy_keywords": ["Loan Approval", "Credit"] } ] -
generate_config.py— add domain-specific information in the following places:domain_keywordsdict: keyword list for the domaindomain_field_namesdict: field names of the state dictionarydefault_decision_pointsdict: default decision pointsdomain_namesdict: display name and document name of the domaindomain_keywords_for_extractiondict: keywords used for section extraction
-
Generate config and test:
python generate_config.py --domain finance --pdf <path-to-finance-manual>.pdf python generate_dataset.py --target 10 --domain finance --output dataset_finance_10.json
- Generating large sample counts takes a long time; run in batches (5–10 per batch)
- Make sure the LLM server is running and the model is available
- Generated data is for training purposes only; review it manually before production use
- The program extracts the decision-relevant sections of the policy document by default (~30K characters)
- Each sample contains 1–3 randomly selected questions (default
--questions-per-sample 3) covering different topics - The teacher model uses Qwen3.6-35B-A3B with temperature=0.3 to obtain probabilistic predictions
- gold is derived deterministically from state-embedded facts by rules; a question that cannot be derived is skipped, and if no question in a sample is derivable the sample is dropped and counted as a degradation
--resumecontinues from an existing JSONL up to target (already-completed samples are not regenerated)- After 3 consecutive state-generation failures the program aborts; completed work is kept in the JSONL and can be resumed with
--resume - If 3 consecutive batches are entirely degraded (no derivable question in any sample, e.g. states keep missing the required fact fields), the program also aborts; completed work is kept in the JSONL
- A fresh run (without
--resume) deletes the existing<output>.jsonlfirst, so old samples never mix into a new dataset - Samples that produce no questions at all are counted as degradations (reported on the completion line) and are not written to the dataset
- Templates without a facts spec do not participate in question selection (only templates with facts enter the sampling pool)
- Python 3.8+
- requests
- pdfminer.six (for PDF text extraction)
pip install requests pdfminer.six