Fine-tuning
Definición
El afinamiento continúa el entrenamiento de un modelo preentrenado con datos específicos de tarea o dominio. Full fine-tuning updates all parameters; parameter-efficient methods (por ej. LoRA, adapters) update a small subset to reduce cost.
Úselo cuando you need stable, task-specific behavior or style (por ej. domain language, output format) and have enough labeled data. For frequently updated knowledge or one-off questions, RAG or prompt engineering are often better. See LLMs for the full training pipeline.
Cómo funciona
You start from a base model (por ej. a pretrained LLM) and a dataset of task examples. You define a loss (por ej. cross-entropy for classification, next-token for generation) and run optimization (por ej. Adam) on your data. El resultado es un fine-tuned model whose weights are updated (fully or only adapters/LoRA). Instruction tuning uses (instruction, response) pairs so the model learns to follow prompts; domain fine-tuning uses in-domain text or labeled tasks. Validation and early stopping prevent overfitting; often only 1–5% of parameters are updated with LoRA to save compute.
Casos de uso
Fine-tuning is the right tool when you need a model to follow a specific style, domain, or task better than prompting alone.
- Adapting a base model to a specific domain (por ej. legal, medical)
- Teaching a consistent output format or style (por ej. JSON, tone)
- Improving performance on a narrow task with limited labeled data