Dictionary of Applied Machine Learning: 114 machine-learning terms, each with a definition, a figure, citations and a Python demo · All terms · Demos · Start here

fine-tuning

Updated on 2026-10-29

Readiness 100/100

▶ Run the Python demo Open in Colab Typeset PDF LaTeX source Markdown Cite this entry

See also pretraining transfer learning self-supervised learning empirical risk minimization gradient descent regularization overfitting validation error

Fine-tuning continues the training of a model on a task-specific dataset, starting from model parameters obtained by pretraining on a larger dataset. It solves an empirical risk minimization (ERM) problem over a small training set under the constraint that the model parameters stay close to the pretrained ones. One form of fine-tuning runs a few gradient descent (GD) steps on the small training set, started at the pretrained model parameters. Forcing the model parameters to stay close to the pretrained ones is a form of regularization, since it limits the effective hypothesis space that is searched during fine-tuning. For a linear model, the generalization gap grows in proportion to how far the model parameters may move from the pretrained ones, which is why a small training set suffices.

Figure produced by the Python demo of the entry fine-tuning
Figure written by the entry's Python demo finetuning.py, which recomputes what the entry states: the script block by block · open in Colab

Definition

B-warmConsider daily weather at Krems an der Donau. A linear model that predicts the maximum daytime temperature from the morning minimum is trained on 360 days of one year, which yields a pretrained hypothesis. The task-specific datasets are the temperature measurements of a single month, and one task is to learn a forecaster tailored to that month. For a single month, thirty gradient descent (GD) steps on that month's 30 days adjust the model parameters, starting from those learned on the whole year (Fig. 1). Fine-tuning is this second step: it continues the training of a model on a task-specific dataset, starting from model parameters obtained by pretraining on a larger dataset (Bishop and Bishop, 2024, Sect. 6.3.4).

Figure 1 of the entry finetuning
Figure 1: Pretraining and fine-tuning of a linear model that predicts the maximum daytime temperature from the morning minimum at Krems an der Donau. (a) Twenty of the 360 days of one year, every 18th day (gray dots), and the hypothesis $\learnthypothesis^{(\mathrm{pre})}$ learned from all 360 (dashed line). (b) to (d) Every other day of January, May and November, 15 of each month's 30 (black dots; all three panels on the same temperature range), the pretrained hypothesis (dashed line), and the hypothesis obtained by thirty GD steps on all 30 days of that month starting from the pretrained model parameters (solid line). Each fine-tuned hypothesis lowers the month's average squared error below that of the pretrained hypothesis while moving the model parameters by less than $1.5$. Data generated by pythondemos/finetuning.py
Formally, let $f({\mathbf w})$ denote the average loss on the task-specific training set $\mathcal{D}^{(\rm train)} = \{{\mathbf z}^{(r)}\}_{r=1}^{m}$, \[ f({\mathbf w}) := \frac{1}{m} \sum_{r=1}^{m} L\left({\mathbf z}^{(r)},{\mathbf w} \right) \text{.} \] Fine-tuning solves the empirical risk minimization (ERM) problem for $f$ not over the whole hypothesis space but under the constraint that the model parameters stay within a radius $B$ of the pretrained ones $\widehat{{\mathbf w}}^{(\mathrm{pre})}$, \[ \widehat{{\mathbf w}} \in \mathop{\mathrm{arg\,min}}_{{\mathbf w} \in \overline{\mathcal{B}}_{B}(\widehat{{\mathbf w}}^{(\mathrm{pre})})} f({\mathbf w}) \text{.} \] Here, $\overline{\mathcal{B}}_{B}(\widehat{{\mathbf w}}^{(\mathrm{pre})}) := \{{\mathbf w} : \Vert {{\mathbf w} - \widehat{{\mathbf w}}^{(\mathrm{pre})}} \Vert \leq B\}$ is the closed ball of radius $B$ around $\widehat{{\mathbf w}}^{(\mathrm{pre})}$ (see Fig. 2).
Figure 2 of the entry finetuning
Figure 2: Fine-tuning in the space of model parameters. The model parameters the method can return lie in the ball $\closedball{\widehat{\weights}^{(\mathrm{pre})}}{B}$ (dashed circle) rather than anywhere in the hypothesis space; a few GD steps on a small training set cannot carry them further. Reaching the same region from an arbitrary initialization (dotted path) would take far more labeled data points
The radius $B$ is what makes a small training set enough. Consider a linear model, whose hypotheses are $h^{({\mathbf w})}({\mathbf x}) = {\mathbf w}^{\top} {\mathbf x}$. Let the feature vectors have norm at most $R$, and let the loss be $\rho$-Lipschitz in the prediction and bounded by $c$ on the ball, as the hinge loss is. Let the data points be realizations of independent and identically distributed (i.i.d.) random variables (RVs). Then, with probability at least $1 - \delta$, every ${\mathbf w} \in \overline{\mathcal{B}}_{B}(\widehat{{\mathbf w}}^{(\mathrm{pre})})$ satisfies \[ \bar{L} \big( h^{({\mathbf w})} \big) \leq f({\mathbf w}) + \frac{2 \rho B R}{\sqrt{m}} + c \sqrt{\frac{2 \ln(2/\delta)}{m}} \text{.} \] This is the bound of Shalev-Shwartz and Ben-David (2014, Thm. 26.12) for model parameters of norm at most $B$, applied to the shifted model parameters ${\mathbf w} - \widehat{{\mathbf w}}^{(\mathrm{pre})}$. The shift adds the fixed number $(\widehat{{\mathbf w}}^{(\mathrm{pre})})^{\top} {\mathbf x}$ to the prediction for each data point, which the contraction step of the proof allows, as it admits a separate $\rho$-Lipschitz function per data point (Shalev-Shwartz and Ben-David, 2014, Lemma 26.9). The second term follows from the Rademacher complexity of the ball, which is at most $B R / \sqrt{m}$ (Shalev-Shwartz and Ben-David, 2014, Lemma 26.10).

The generalization gap between risk and training error $f({\mathbf w})$ therefore grows in proportion to the radius $B$ and not with the number $d$ of model parameters. A gap of at most $\varepsilon$ is guaranteed by $m = \big\lceil \big(2 \rho B R + c \sqrt{2 \ln(2/\delta)}\big)^{2} / \varepsilon^{2} \big\rceil$ data points, a number that falls with $B$. The constraint restricts the model the method searches, which is what regularization achieves by pruning a hypothesis space. The difference is that the pruned set is centered at the pretrained model parameters instead of at an arbitrary initialization.

B-distanceGD with few steps and a small step size, started at the pretrained model parameters, implements this constraint without enforcing it explicitly. Each step moves the model parameters by $\eta$ times the norm of the gradient. After $T$ steps with step size $\eta$, started at ${\mathbf w}^{(0)} = \widehat{{\mathbf w}}^{(\mathrm{pre})}$, \[ \Vert {{\mathbf w}^{(T)} - \widehat{{\mathbf w}}^{(\mathrm{pre})}} \Vert \leq \eta \sum_{t=0}^{T-1} \Vert {\nabla f({\mathbf w}^{(t)})} \Vert \leq \eta T G \text{,} \] where $G$ bounds the norm of the gradient along the iterates. The iterate therefore lies in the ball of radius $B = \eta T G$ around $\widehat{{\mathbf w}}^{(\mathrm{pre})}$. Limiting the number of iterations is thus a form of regularization: it limits the effective hypothesis space that is searched during fine-tuning, with the step size and the iteration count in the role of the radius.

Fine-tuning is useful when the task-specific dataset is small. A hospital has a few hundred annotated scans and needs a tumor detector. Training a deep net from an arbitrary initialization on that many labeled data points usually ends in overfitting; starting from model parameters already learned from millions of unrelated photographs achieves a lower validation error (Yosinski et al., 2014). Large language models (LLMs) are adapted the same way: one pretrained on unlabeled text is fine-tuned on each task it is wanted for (Devlin et al., 2019). A common variant freezes some layers and adapts only the remainder (Yosinski et al., 2014); parameter-efficient fine-tuning restricts the update to a low-dimensional set of new model parameters while leaving $\widehat{{\mathbf w}}^{(\mathrm{pre})}$ untouched (Hu et al., 2022).

The experiment pythondemos/finetuning.py measures the effect on synthetic data for linear regression with $m = 15$ data points and $d = 30$ model parameters. GD started at the pretrained model parameters with step size $\eta = 0.02$ falls to a validation error below twice the noise level after $T = 16$ steps. It has then moved the model parameters a distance $0.32$, inside the ball of radius $\eta T G = 0.72$. The same iteration from an arbitrary initialization drives the training error to zero yet ends with a validation error more than four times larger, having moved a distance $2.6$. Fig. 3 sketches the same effect on a schematic task-specific dataset of four data points.

Figure 3 of the entry finetuning
Figure 3: Fine-tuning on a task-specific dataset of four data points. The pretrained hypothesis (dashed line) is already close to the task; a few GD steps on the four data points of the task training set (dots) move it to the solid curve. From an arbitrary initialization, the four data points alone would have to determine the whole curve

Synonyms: fine tuning.

See also: pretraining, transfer learning, foundation model, self-supervised learning, empirical risk minimization, gradient descent, regularization, Rademacher complexity, overfitting, generalization gap, validation error.

References

  1. Bishop and Bishop (2024). Deep Learning: Foundations and Concepts. Springer Nature. doi.org/10.1007/978-3-031-45468-4
  2. Shalev-Shwartz and Ben-David (2014). Understanding Machine Learning: From Theory to Algorithms. Cambridge Univ. Press. doi.org/10.1017/cbo9781107298019
  3. Yosinski et al. (2014). How Transferable Are Features in Deep Neural Networks?. Adv. Neural Inf. Process. Syst. (NIPS).
  4. Devlin et al. (2019). BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding. Proc. 2019 Conf. North American Chapter Assoc. Computational Linguistics: Human Lang. Technologies, Volume 1 (Long and Short Papers). doi.org/10.18653/v1/N19-1423
  5. Hu et al. (2022). LoRA: Low-Rank Adaptation of Large Language Models. Int. Conf. Learn. Represent. (ICLR).

Cite this entry

@misc{dictml_finetuning,
  author = {Jung, Alexander},
  editor = {Olioumtsevits, Konstantina and Schnoor, Ekkehard},
  title = {fine-tuning},
  howpublished = {Dictionary of Applied Machine Learning (course edition)},
  year = {2026},
  doi = {10.5281/zenodo.21569296},
  note = {ISBN 978-952-64-3013-3, CC BY 4.0, retrieved 2026-11-03},
  url = {https://dictionaryofml.org/terms/finetuning.html}
}