Skip to content

Packs / llm-finetuning-public

prepare-chat-dataset

Turn raw chats into a clean fine-tune set: drop invalid rows, dedupe, strip PII (emails, phones, IDs, cards, IPs), render ChatML/Llama 3/Gemma templates and split train/valid JSONL.

L2 Checks passed 3 of 3 runsv0.1.0Tech-Realm/space-llm-finetuning-public

Install

logicpacks pack use llm-finetuning-public/prepare-chat-dataset
get_pack llm-finetuning-public/prepare-chat-dataset

The second line is the MCP tool call for the LogicPacks connector (Claude Code, Codex, Claude.ai and others). The first run of a pack someone else wrote asks for your yes.

Keys it needs (names only)

None.

Playbooks included

  • Spec: spec/SPEC.md (goal, steps, edge cases, don’ts)
  • Routes: python-stdlib
  • Checks: 3 in outcome/checks.yaml
  • Code: make_fixture.pyprep.py
  • Tools: python3

Usage, last 8 weeks

New: no recorded use yet.

Purpose (from spec/SPEC.md)

Goal

A train.jsonl/valid.jsonl pair in messages format with no duplicates, no PII and only valid conversations, plus a rendered preview in the target model's chat template.

Steps

  1. Export the raw chats to JSONL: one {"messages": [...]} per conversation.
  2. Run python3 code/prep.py --in raw.jsonl --out data --template <chatml|llama3|gemma> (pick the template of the base model).
  3. Read the stats line: kept / dupes / invalid / pii. If invalid is high, fix the export, not the filter.
  4. Open data/rendered.txt and check one example by eye (roles, special tokens).
  5. Hand data/ to lora-finetune-mlx, qlora-finetune-4090 or hosted-finetune-apis.

Edge cases

  • Roman Urdu and Urdu script are kept as is; only PII patterns are replaced.
  • Card numbers are replaced only when the Luhn check passes, so order numbers survive.
  • Gemma has no system role: the system message is dropped in the Gemma preview only (the JSONL keeps it).

Don'ts

  • Don't train on WhatsApp/customer chats without running this first.
  • Don't commit the real raw.jsonl or data/ to any repo; fixtures are synthetic.
  • Don't trust the PII filter blindly for names and addresses: spot-check.