liveBook · Manning

Fine-tuning

As explained in Domain-Specific Small Language Models

Training a pretrained model further on task- or domain-specific data to adapt it to a narrower use case.

Fine-tuning further trains a pretrained language model on a smaller, labeled, task-specific dataset. Updating the model’s weights adapts general capabilities to an organization’s domain or a narrower task, without training an entire model from scratch. section 2.3 section 1.4

Fine-tuning involves several practical choices:

  • Full fine-tuning updates all model parameters and requires more computation; parameter-efficient fine-tuning updates only a small subset. section 2.3
  • Prepare examples by formatting text, tokenizing it, assigning token IDs, padding or truncating sequences, and creating a data loader. section 2.1 section 2.1.2
  • Compare fine-tuning with retrieval-augmented generation: RAG suits up-to-date, traceable information, while fine-tuning suits complex specialized tasks. section 2.6
  • Treat data collection and preparation, computational power, evaluation, and deployment constraints as continuing costs rather than one-time setup details. section 1.4

Question-answering model

A DistilBERT model can be fine-tuned for question answering using question, context, and answer-position fields. The workflow splits data into training and test sets, tokenizes and truncates inputs, trains with Hugging Face Trainer, then extracts an answer span from start and end logits. section 2.3

Antibody generation

AntibodyGPT fine-tunes ProGen2 on 5,000 experimentally resolved antibody–antigen crystal structures. It generates antibody sequences from target antigen sequences, then uses domain-specific validation and deployment techniques such as GPU acceleration and 8-bit quantization. section 8.3 section 8.5

How Domain-Specific Small Language Models covers it

How deep it goes
Explains dataset preparation, tokenization, training, evaluation, inference, full fine-tuning, and PEFT, but defers detailed PEFT implementations.
Examples
Demonstrates DistilBERT question answering, GPT-2 data preparation, small-model code generation, and ProGen2-based antibody generation.
What it assumes
Assumes familiarity with pretrained models and labeled datasets while teaching tokenization, formatting, splitting, training, and prediction workflows.
What you can do after
Build it with Hugging Face Transformers and Datasets, train a task-adapted model, and run inference against new inputs.
How it connects
Connects transfer learning, pretraining, Transformers, tokenization, parameter-efficient fine-tuning, LoRA, and retrieval-augmented generation.

Also explained in

Compare how 37 books explain fine-tuning →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Domain-Specific Small Language Models. The section links point to the parts of the book it draws on.