liveBook · Manning

Keras model

As explained in Deep Learning with R, Third Edition

The Keras Model class is an API class representing a trainable neural-network model with methods for training, evaluation, prediction, and export.

A Keras model is a graph of layers that maps input tensors to output tensors and provides a trainable hypothesis space. Sequential models are simple one-input, one-output stacks; broader topologies include branches, multiple heads, residual connections, and Transformers. section 3.6.3

Keras supports progressively more customizable ways to construct and train models:

  • Build a simple stack with Sequential. section 3.6.3
  • Use the Functional API for complex connected topologies. section 3.6.3
  • Subclass Model when custom behavior or training logic is needed. section 7.4.4
  • Train with fit(), or override train_step() to retain callbacks, optimization, and distributed-training support while changing the learning algorithm. section 7.4.4

Custom training with fit()

A custom Model subclass can override train_step() to compute predictions, evaluate loss, apply gradients, update a loss metric, and return logs. The resulting model can still be compiled and trained with fit(train_images, train_labels, epochs = 3). section 7.4.4

Figure 3.5 The Transformer architecture. There’s a lot going on here. Throughout the coming chapters, we’ll build up the concepts you need, and by the end of chapter 15, you’ll understand this architecture.
figure

Inspect the Transformer layer graph to see why model topology can extend far beyond a sequential stack. section 3.6.3

How Deep Learning with R, Third Edition covers it

How deep it goes
Descends from model topology and hypothesis spaces to custom train_step internals, while deferring full training loops to backend-native code.
Examples
Demonstrates a dense classifier with dropout and softmax, then custom TensorFlow, PyTorch, and JAX training steps.
What you can do after
Apply it via Sequential, the Functional API, subclassing, fit(), or an overridden train_step().
How it connects
Connects Sequential models, the Functional API, subclassing, callbacks, custom training loops, and backend-native TensorFlow, PyTorch, and JAX workflows.

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.