liveBook · Manning

Foundational model

As explained in Deep Learning with Python, Third Edition

A model trained beforehand on large-scale data and then reused for downstream tasks or analysis without starting from scratch.

Training a large model from scratch is often unnecessary. A foundational, or foundation, model learns broadly useful representations from large-scale data, then serves many downstream tasks with little retraining or none. Such models are generally trained with self-supervision: for example, predicting missing or subsequent content from the input itself. A pretrained model is not automatically a foundation model; an ImageNet classifier can be useful for reuse without having been trained on broad data with a self-supervised objective. section 16.4.2 section 8.3

Reuse an image model for a smaller dataset

Suppose you have a small dogs-versus-cats dataset. Start with an Xception convolutional backbone pretrained on ImageNet, rather than learning every visual feature anew. Run images through its matching preprocessor and backbone, then train a new classifier on the resulting features. Reuse the backbone, not its original classifier: the latter predicts ImageNet classes, while convolutional feature maps retain more general visual information. section 8.3 section 8.3.1

Figure 8.12 Swapping classifiers while keeping the same convolutional base
swapping fc classifier

The diagram shows the key swap: keep a learned convolutional base and replace the task-specific classifier. section 8.3.1

Choose the amount of adaptation the new task needs:

  • Use the existing model directly when its capabilities fit the task. Prompting can elicit responses from generative models without retraining; SAM can segment new objects when given an example. section 1.8 section 11.3
  • Extract features and train a new head when the representations transfer but the outputs must change. For image tasks, earlier convolutional layers learn more generic features; later layers are more specialized. section 8.3.1
  • Fine-tune when the reused representations need adjustment. Add a head, freeze the base, train the head, then unfreeze appropriate base layers and train jointly. Do not start by training a random head against an unfrozen base: its large error signal can damage learned representations. section 8.3.2

Reuse also works beyond image classification. A pretrained ResNet backbone can supply features for an object detector, while a pretrained RoBERTa Transformer can gain a classification head for movie-review sentiment. For text, the tokenizer, architecture, and weights must match pretraining; differently assigned token IDs would undermine the learned representations. Loading a preset avoids rebuilding that combination by hand. section 12.2.2 section 15.4.2 section 15.4.4

Listing 15.20 Loading the RoBERTa pretrained model with KerasHub
import keras_hub
 
tokenizer = keras_hub.models.Tokenizer.from_preset("roberta_base_en")
backbone = keras_hub.models.Backbone.from_preset("roberta_base_en")

These two preset calls load the matching RoBERTa tokenizer and backbone for a downstream text task. section 15.4.2

Rule of thumb: reuse expensive pretraining, but budget for inference and adaptation. Large pretrained Transformers can outperform simpler classifiers while costing more to run. Pretraining a generative model can also demand substantial compute and electricity, which makes an existing model the practical starting point for many applications. section 15.4.4 section 16.3

How Deep Learning with Python, Third Edition covers it

How deep it goes
Defines foundation models and works through feature extraction and fine-tuning, while using pretrained weights rather than reproducing large-scale pretraining.
Examples
Uses ImageNet-pretrained Xception for image classification, RoBERTa for movie-review sentiment, and SAM for segmentation.
What it assumes
Assumes familiarity with model training and classifiers, while explaining why learned backbones transfer and how to adapt them.
What you can do after
Apply it via KerasHub presets to load matching pretrained components, attach task-specific heads, and fine-tune where needed.
How it connects
Connects self-supervised learning, prompting, feature extraction, fine-tuning, transfer learning, and multimodal models.

Also explained in

Compare how 21 books explain foundational model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.