liveBook · Manning

From_preset()

As explained in Deep Learning with R, Third Edition

from_preset() is a KerasHub constructor that loads a pretrained model together with its configuration, weights, and tokenizer assets.

from_preset() is a KerasHub constructor for loading a pretrained model together with its configuration, weights, and tokenizer assets from disk. section 15.4.2

Listing 15.20 Loading the RoBERTa pretrained model with KerasHub
py_require("keras-hub")
keras_hub <- import("keras_hub")

tokenizer <- keras_hub$models$Tokenizer$from_preset("roberta_base_en")
backbone <- keras_hub$models$Backbone$from_preset("roberta_base_en")

Load a RoBERTa tokenizer and backbone from the same preset, then use the tokenizer for text and the backbone for model inputs. section 15.4.2

RoBERTa and Xception presets

The preset name identifies the checkpoint to load. The RoBERTa example uses "roberta_base_en" for both tokenizer and backbone. For image feature extraction, "xception_41_imagenet" loads a convolutional base, optionally with trainable = FALSE, while ImageConverter$from_preset() matches image preprocessing to the checkpoint. section 15.4.2 section 8.3.1

A preset can provide the main components needed to use pretrained models:

  • Tokenizers convert text into integer sequences using the checkpoint's tokenization setup. section 15.4.2
  • Backbones provide pretrained task-independent model representations that can feed a task-specific head. section 15.4.2
  • ImageConverter presets rescale and resize images to match the pretrained checkpoint's expected input format. section 8.3.1

How Deep Learning with R, Third Edition covers it

How deep it goes
Defines the constructor and demonstrates tokenizer, backbone, preprocessing, and freezing, without explaining checkpoint internals.
Examples
Uses RoBERTa text loading and Xception image loading, preprocessing, feature extraction, and frozen-backbone classification.
What you can do after
Apply it via KerasHub to instantiate pretrained tokenizers, backbones, and preprocessing layers from named presets.
How it connects
Connects pretrained models with tokenizers, backbones, image preprocessing, transfer learning, and task-specific classifiers.

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 R, Third Edition. The section links point to the parts of the book it draws on.