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.
Inspect the Transformer layer graph to see why model topology can extend far beyond a sequential stack. section 3.6.3
