liveBook · Manning

Sequential model

As explained in Deep Learning with Python, Third Edition

A Keras class for building models as a linear stack of layers.

A Sequential model is the approachable Keras choice for a simple linear stack of layers: one input flows through each layer to one output. It is essentially a Python list of layers, so it works best when the model does not need branches, multiple inputs or outputs, or other graph-like connections. section 3.6.3 section 7.2

Build a small classifier

Create the stack directly, or add layers incrementally. This model transforms three input features through a 64-unit ReLU layer and produces ten softmax outputs: model = keras.Sequential([ layers.Dense(64, activation="relu"), layers.Dense(10, activation="softmax"), ]) The equivalent incremental form uses model.add(...), much like list.append(...). Give the model an input shape with keras.Input(shape=(3,)) when you want it built immediately and summarized as layers are added. section 7.2.1

Use the model-building and debugging workflow deliberately:

  • Remember that layers create their weights only when the input shape is known. Calling the model on data or calling build(input_shape=...) builds it. section 7.2.1
  • Call summary() after building to inspect output shapes and parameter counts; this is especially useful when layers transform inputs in complex ways. section 7.2.1
  • Switch to the Functional API for directed acyclic graph architectures, or to model subclassing when you need low-level control. section 7.2 section 7.2.5
Figure 7.1 Progressive disclosure of complexity for model building
progressive disclosure of complexity models

Use the complexity spectrum to compare Sequential models with the Functional API and model subclassing before choosing a construction style. section 7.2

How Deep Learning with Python, Third Edition covers it

How deep it goes
Explains direct and incremental construction, delayed weight creation, input-shape building, summaries, naming, and architecture limits.
Examples
Demonstrates Dense classifiers, incremental add calls, explicit input shapes, build(), weights, summary(), and named layers.
What it assumes
Assumes Python list-like usage and Keras layers while teaching input-dependent building and model inspection.
What you can do after
Build it from scratch with keras.Sequential, inspect its structure, and choose a more flexible API when the architecture outgrows a stack.
How it connects
Connects layer stacks with the Model class, Functional API, model subclassing, tensor operations, and network topology.

Also explained in

Compare how 2 books explain Sequential model →

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.