Skip to content

Multi-Layer Perceptron (MLP)

What an MLP is

An MLP is a feed-forward neural network with:

  • an input layer
  • one or more hidden layers
  • an output layer

false


  flowchart LR
  I[Input layer] --> H1[Hidden layer 1]
  H1 --> H2[Hidden layer 2]
  H2 --> O[Output layer]

false

Why hidden layers matter

Hidden layers + non-linear activations allow the model to learn:

  • curves
  • interactions
  • complex decision boundaries

Typical uses

MLP works best on:

  • tabular data (sometimes)
  • small image/text tasks (but CNNs/Transformers are usually better)

A tiny Keras example (conceptual)

MLP in Keras (conceptual)
# Note: This requires TensorFlow/Keras installed.
from tensorflow import keras
from tensorflow.keras import layers
 
model = keras.Sequential([
    layers.Dense(64, activation="relu"),
    layers.Dense(64, activation="relu"),
    layers.Dense(1, activation="sigmoid"),
])
MLP in Keras (conceptual)
# Note: This requires TensorFlow/Keras installed.
from tensorflow import keras
from tensorflow.keras import layers
 
model = keras.Sequential([
    layers.Dense(64, activation="relu"),
    layers.Dense(64, activation="relu"),
    layers.Dense(1, activation="sigmoid"),
])

Mini-checkpoint

If you remove non-linear activations from all hidden layers, what happens?

  • The whole network behaves like a linear model.

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did