Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Keras · Class

Sequential

Keras Sequential builds a Model from a linear stack of layers. It suits straightforward single-input, single-output architectures and supports training and inference.

How it works

Sequential constructs a model by arranging layers in one linear chain. Provide layers at creation time or append them with add(); an explicit Input builds the model as layers are added, while omitting it delays weight creation until the model is first called, trained, evaluated, or predicted.

Syntax

keras.Sequential(layers=None, trainable=True, name=None)

Parameters

NameTypeDescription
layerslist of layers or NoneOptional ordered list of layer instances forming the stack.
trainableboolWhether the model is trainable.
namestr or NoneOptional name assigned to the model.

Returns

A Keras Model representing the sequential layer stack.

Key points

  • The class represents a model whose computation follows one ordered layer stack.
  • Pass the complete layer sequence to the constructor when the architecture is known upfront.
  • Use the layers attribute to inspect the model's ordered layer collection.
  • The model supports list-like stack editing, including removing the final layer with pop().
  • After construction, the model exposes model-style layer connectivity, including input and output attributes.

Common mistakes

  • Use Sequential only for a linear single-input, single-output layer stack; choose the Functional API for branching or other non-linear architectures.
  • Without an explicit Input or manual build(), weights are created later, so inspect or summarize the model only after it has been built.

Example: Build a Sequential model

import keras
from keras import layers

model = keras.Sequential([
    layers.Input(shape=(16,)),
    layers.Dense(8, activation="relu"),
    layers.Dense(1)
])

model.compile(optimizer="sgd", loss="mse")

Creates a single-input, single-output stack and explicitly defines its input shape before compiling it.

When to use it

Plain layer stacks

A straightforward feed-forward network with one input and one output.

List-based model definition

A model whose layers are known before construction.

Interactive architecture building

Incrementally assembling and editing a stack during experimentation.

Interview questions

QWhat problem does Sequential solve?

Sequential is designed for a linear stack in which each layer has one input tensor and one output tensor. It provides the model's training and inference features through the resulting Model.

Follow-up: When should the Functional API be preferred? Prefer it when the architecture is not a plain stack, such as when it requires multiple inputs, multiple outputs, or branches.

QHow can a Sequential model be constructed and built?

The constructor accepts an optional list of layers, and layers can also be appended with add(). An explicit Input lets the model build continuously as layers are added; otherwise building is delayed.

Follow-up: How can delayed construction be completed manually? Call build(batch_input_shape) after adding layers without an input shape.

QWhat constraints apply when adding layers?

add() places a layer on top of the current stack. It rejects objects that are not layers, layers whose input shape is unknown, layers with multiple outputs, and layers already connected elsewhere.

Follow-up: What operation reverses add()? Use pop() to remove the last layer; the current API can rebuild the model after removal.

  • Model
  • Functional API
  • add method
  • pop method
  • Input layer
  • fit method
  • evaluate method
  • predict method

Source: The Sequential class. Checked 2026-10-15.