7 Model specialization
This chapter covers
- Adapting models to structured outputs
- Replacing long prompts through fine-tuning
- Efficient fine-tuning with LoRA and DoRA
- Specializing LLMs without losing capabilities
Throughout the previous chapters we've worked on the model's structure through pruning and distillation to gain speed without losing general capability. Now the focus shifts: we're going to adapt the LLM's behavior to our specific data and formats.
To specialize a model, you can use RAG (retrieval-Augmented Generation) to inject external knowledge, or fine-tuning to modify its responses and instincts. Fine-tuning solves a wide spectrum of problems: from changing how a model that already has the necessary knowledge responds, to injecting vocabulary and concepts from a specialized domain it barely saw during pretraining.
One clear example is adapting the LLM’s response to structured formats. A generalist LLM tends to converse and add unnecessary explanations—like "Here's the JSON..."—that break production pipelines. Fine-tuning corrects this at the root by transferring the instructions from the prompt directly into the model's weights. The result is robust, predictable outputs that eliminate the need for lengthy prompts.