liveBook · Manning

Model architecture

As explained in Deep Learning with Python, Third Edition

The structural design of a deep learning model, here contrasted with approaches that adapt at test time rather than only scaling fixed architectures.

Model architecture is the choice of layers, their settings, and how they connect. It matters before training starts: the resulting graph defines the functions that gradient descent can search by adjusting the model’s weights. An unsuitable architecture can limit results even with more training data; a well-chosen one can make learning easier. section 9.0

A graph instead of a stack

Consider a support-ticket model that reads a title, a message body, and user-added tags. Their inputs can be combined into shared features, then split into two outputs: priority and department. That connectivity is part of the architecture. A Sequential stack cannot express this multi-input, multi-output graph; Keras’s Functional API can. section 7.2.2

Practical architecture decisions:

  • Choose a Sequential model for one input, one output, and a simple layer-by-layer stack. section 3.6.3
  • Use the Keras Functional API when layers branch or inputs and outputs multiply. Prefer it to model subclassing when the model can be expressed as a directed acyclic graph of layers. section 7.2.2 section 7.2.5
  • For complex ConvNets, look for modules arranged in a hierarchy and reused as blocks. Common patterns include residual connections, batch normalization, and depthwise separable convolutions. section 9.1 section 9.7
Listing 7.8 A simple Functional model with two Dense layers
inputs = keras.Input(shape=(3,), name="my_input")
features = layers.Dense(64, activation="relu")(inputs)
outputs = layers.Dense(10, activation="softmax")(features)
model = keras.Model(inputs=inputs, outputs=outputs, name="my_functional_model")

This small Functional model shows how calling layers on an input defines connectivity before the input and output are assembled into a Keras Model. section 7.2.2

Architecture also encodes assumptions about the problem. A single Dense layer without an activation assumes that two classes can be separated linearly; convolution layers encode an expectation that useful image patterns can occur at different locations. There is no guaranteed recipe for choosing well, so use established patterns and test whether they help the task at hand. section 3.6.3 section 9.0

How Deep Learning with Python, Third Edition covers it

How deep it goes
Defines layers, settings, and connectivity, then works through Functional graphs and ConvNet patterns; treats choosing an effective architecture as practice-dependent.
Examples
Uses a support-ticket model with three inputs and two outputs, a two-layer Functional model, and repeated ConvNet blocks.
What it assumes
Starts with layers and Sequential stacks before introducing more complex layer graphs.
What you can do after
Apply it via Keras’s Functional API to build layer graphs, and evaluate architecture choices against a problem’s assumptions.
How it connects
Connects hypothesis spaces and gradient descent to layer graphs, feature engineering, ConvNets, residual connections, and the Keras Functional API.

Also explained in

Compare how 13 books explain model architecture →

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.