C.W.K.
Stream
Lesson 05 of 07 · published

KerasHub

~9 min · transfer

Level 0Keras Apprentice
0 XP0/97 lessons0/20 achievements
0/120 XP to next level120 XP to go0% complete

One hub, one API, every modality

KerasHub is the unified pretrained-model hub that succeeded KerasCV + KerasNLP. Its win isn't just the catalog (BERT, GPT-2, Gemma, Llama, Mistral, T5, Whisper, Qwen, ResNet, ViT…) — it's that every model loads through the same from_preset() call, whether it's vision, NLP, or audio. Learn the pattern once and the whole zoo is open to you.

Presets carry more than weights

The reason keras.applications feels low-level next to KerasHub is that a preset bundles the whole package: the backbone weights, the matching tokenizer or preprocessor, and a task-specific head. When you call BertClassifier.from_preset("bert_base_en", num_classes=4), you get a model that already knows how to turn raw text into tokens and emit 4-class logits — no separate tokenizer wiring. That's why it's the modern default entry point for transfer learning.

LoRA: fine-tune big models cheaply

For large backbones, full fine-tuning is expensive. backbone.enable_lora(rank=4) switches on Low-Rank Adaptation: instead of updating the full weight matrices, it trains tiny low-rank update matrices alongside the frozen originals. You get most of the fine-tuning benefit for a fraction of the trainable parameters and memory — the standard trick for adapting LLM-scale models on a single GPU. The Code section shows the full load → LoRA → fit flow.

Code

Load a preset and fine-tune with LoRA·python
import keras_hub

# Load a pretrained NLP model
classifier = keras_hub.models.BertClassifier.from_preset(
    "bert_base_en",
    num_classes=4,
)

# Available models include:
# BERT, GPT-2, Gemma (1/2/3/4), Llama 2/3,
# Mistral, T5, Whisper, Qwen, and many more

# Fine-tune with LoRA for efficiency
classifier.backbone.enable_lora(rank=4)
classifier.compile(optimizer="adam", loss="sparse_categorical_crossentropy")
classifier.fit(train_ds, epochs=3)

External links

Exercise

Install keras-hub. Load three different presets: a ResNet, a ViT, a BERT. Print the parameter count of each. Note the API shape is identical across CV and NLP.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.