liveBook · Manning

From_preset()

As explained in Deep Learning with Python, Third Edition

A constructor used to load a pretrained model’s weights, configuration, and tokenizer assets from a preset.

from_preset() is a KerasHub constructor for restoring a pretrained component from a named preset. It supplies the configuration and weights, and for language models can also load tokenizer assets, avoiding a hand-matched recreation of the architecture. section 15.4.2 section 8.3.1

Load RoBERTa or Xception

import keras_hub tokenizer = keras_hub.models.Tokenizer.from_preset("roberta_base_en") backbone = keras_hub.models.Backbone.from_preset("roberta_base_en") conv_base = keras_hub.models.Backbone.from_preset( "xception_41_imagenet", trainable=False, ) Use the matching preprocessing preset for image models: ImageConverter.from_preset("xception_41_imagenet", image_size=(180, 180)). section 15.4.2 section 8.3.1

Practical rules:

  • Choose a preset that identifies the pretrained checkpoint, such as roberta_base_en or xception_41_imagenet. section 15.4.2 section 8.3.1
  • Pair the restored backbone with its tokenizer or input converter so new inputs match pretraining. section 15.4.2 section 8.3.1
  • Set trainable=False when using the backbone for fixed feature extraction; otherwise connect it to a task-specific head for fine-tuning. section 8.3.1
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")

Inspect the compact KerasHub loading pattern for a tokenizer and RoBERTa backbone. section 15.4.2

How Deep Learning with Python, Third Edition covers it

How deep it goes
Explains constructor behavior and practical pairing, but stops short of preset-file formats or asset-resolution internals.
Examples
Uses RoBERTa tokenization, RoBERTa backbone loading, Xception feature extraction, and frozen convolutional bases.
What it assumes
Assumes familiarity with Keras models and pretrained checkpoints while demonstrating the loading workflow from named presets.
What you can do after
Apply it via KerasHub to load pretrained backbones, tokenizers, and preprocessing components for downstream models.
How it connects
Connects pretrained models with backbones, tokenizers, preprocessing, feature extraction, and fine-tuning.

Also explained in

Compare how 2 books explain from_preset() →

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.