liveBook · Manning

Build()

As explained in Deep Learning with R, Third Edition

The Keras build method creates a layer's state after receiving the shape of its input.

build() creates a Keras layer’s weights after the layer receives its input shape. This delayed setup matters because weight dimensions depend on that shape. The layer’s computation belongs in call(). section 3.6.2

Building a shape-dependent custom layer

A custom SimpleDense layer receives input_shape in build(), extracts the input dimension, and creates W and b. Its call() method then computes the output. Calling it with shape (2, 784) creates an output with shape (2, 32). section 3.6.2

Layers are built lazily:

  • A model can also be built explicitly with build(input_shape), allowing its weights and summary to be inspected before data passes through it. section 7.2.1
  • Providing input_shape in advance lets a Sequential model build while layers are added and supports shape-summary debugging. section 7.2.1

How Deep Learning with R, Third Edition covers it

How deep it goes
Explains lazy construction, input-shape-dependent weights, explicit model building, and summary inspection without descending into weight initialization internals.
Examples
Uses a custom SimpleDense layer, a (2, 784) input tensor, and Sequential models with explicit or automatic building.
What it assumes
Uses layers, tensors, weights, and input shapes while demonstrating shape-dependent state creation through a custom layer.
What you can do after
Builds custom Keras layers and debugs model weights, output shapes, and summaries before training.
How it connects
Connects build() to Layer, call(), weights, input shapes, and the Sequential model.

Also explained in

Compare how 2 books explain build() →

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.