Keras Sequential API
Until now, we focused on understanding how deep learning models work conceptually — neurons, layers, loss functions, and optimization.
From this lesson onward, we begin translating those concepts into actual working deep learning code.
The Keras Sequential API is the simplest and most beginner-friendly way to build neural networks.
What Is Keras?
Keras is a high-level deep learning library built on top of TensorFlow.
Its main goal is to make neural network development simple, readable, and fast.
Instead of writing complex mathematical operations manually, Keras allows us to focus on model design and learning behavior.
What Is the Sequential API?
The Sequential API is used when your model is a simple stack of layers.
Each layer has exactly one input and one output, and data flows in a straight line — from input to output.
This makes it ideal for beginners and for many real-world problems.
When Should You Use Sequential API?
Use the Sequential API when:
• Your model is feed-forward • Layers are added one after another • There are no multiple inputs or outputs
Later in this course, we will learn when this approach is not sufficient.
Basic Structure of a Sequential Model
A Sequential model is created by adding layers step by step.
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
This imports the tools required to define and build a neural network.
Building Your First Neural Network
Let us build a simple neural network with one hidden layer.
model = Sequential()
model.add(Dense(16, activation='relu', input_shape=(10,)))
model.add(Dense(1, activation='sigmoid'))
Here is what is happening:
The first layer has 16 neurons and uses ReLU activation. It expects input data with 10 features.
The final layer outputs a probability using sigmoid activation.
Compiling the Model
Before training, the model must be compiled.
Compilation defines how the model learns.
model.compile(
optimizer='adam',
loss='binary_crossentropy',
metrics=['accuracy']
)
Here we define:
• Optimizer — how weights update • Loss function — what the model tries to minimize • Metrics — how performance is measured
Where Does Data Come In?
A neural network learns from data.
You can use any structured dataset, including the dataset provided for this course.
Download it here:
Download Deep Learning Practice Dataset
We will start using this dataset step-by-step in upcoming lessons.
Training the Model
Once compiled, training becomes straightforward.
model.fit(X_train, y_train,
epochs=20,
batch_size=32,
validation_split=0.2)
During training:
The model adjusts its weights to minimize the loss and improve accuracy.
Why Sequential API Is Important
Most production deep learning models start with this API.
It helps you quickly prototype, debug ideas, and understand learning behavior.
Once you master this, advanced APIs become much easier.
Mini Practice
Try answering this:
If your dataset has 20 input features, what should the input_shape be?
Exercises
Exercise 1:
What does the Sequential API assume about data flow?
Exercise 2:
Why must a model be compiled before training?
Quick Quiz
Q1. Which API is best for simple feed-forward models?
Q2. What does an optimizer control?
In the next lesson, we will explore PyTorch Basics and compare it with Keras.