The goal
Train a small model to consistently output structured JSON for a product-review analysis tool. The model must produce parseable JSON with the right fields on the first try, every time.
The recipe
- Base model: Llama 3.1 8B Instruct (good at instruction following).
- Training data: 500–1,000 product reviews paired with hand-crafted JSON outputs covering positive, negative, mixed, sarcastic, very short, and very long inputs.
- Method: QLoRA, r=16, all-linear, 3 epochs.
- Expected outcome: 99%+ JSON format compliance vs ~90% with prompting alone.
The 'adversarial' diet
The single biggest determinant of robustness: include 'adversarial' examples in your training data — reviews that are ambiguous, very short, contain sarcasm, mix multiple sentiments, or arrive in unexpected formats. The model becomes robust to real-world variation only by seeing real-world variation during training.