Network topology is the pattern of connections between a model’s layers and operations. A simple topology stacks layers from one input to one output. Others branch, combine paths, or use residual connections. In Keras, these arrangements form a graph of layers represented by a Model. section 3.6.3
Start with a stack
For vector data, a straightforward topology passes the input through two Dense layers and then a single-unit output layer: inputs <- keras_input(shape = c(num_input_features)) outputs <- inputs |> layer_dense(32, activation = "relu") |> layer_dense(32, activation = "relu") |> layer_dense(1, activation = "sigmoid") model <- keras_model(inputs, outputs) model |> compile(optimizer = "rmsprop", loss = "binary_crossentropy") This configuration is for binary classification. The connections form a stack; the final activation and loss match the task. section 20.1.6
Topology is a consequential choice, not just a drawing. It defines the series of tensor operations through which inputs become outputs, restricting the functions the model’s weights can represent—its hypothesis space. A single Dense layer without an activation, for example, assumes that two classes are linearly separable. Convolution layers instead encode an assumption about patterns in images: their relevance does not depend on location. section 3.6.3 section 9.0
Useful patterns go beyond a plain stack:
- Branches and multiple heads connect layers along more than one path; residual connections are another common topology. section 3.6.3
- Convnet blocks reuse groups of layers. Feature hierarchies can grow deeper in filters while shrinking in spatial size; residual connections address a limit on stacking layers caused by vanishing gradients. section 9.1
- Architecture families suit different data structures: Dense networks commonly handle vectors, convnets images, and recurrent networks or Transformers timeseries. section 20.1.6
Figure 9.2 The “entry flow” of the Xception architecture: note the repeated layer blocks and the gradually shrinking and deepening feature maps, going from 299 × 299 × 3 to 19 × 19 × 728
Trace the repeated layer blocks and the changing feature-map sizes in an Xception convnet. section 9.1
Choose an architecture whose assumptions fit the data, then test it against a simple baseline. Once the model can overfit, try adding or removing layers and evaluate each revision on validation data. Reusing validation feedback too many times can itself lead to overfitting; reserve the test set for a final evaluation. In Keras, Sequential handles simple stacks, while the Functional API or Model subclassing can express more involved graphs. section 6.2.3 section 6.2.5 section 3.6.3


