liveBook · Manning

Sigmoid

As explained in Deep Learning with Python, Third Edition

A statistical classification method that models class probabilities with a linear predictor passed through a logistic function.

A sigmoid activation converts an arbitrary numeric value into the [0, 1] interval, producing a score that can be interpreted as a probability. In binary classification, place it on a final Dense layer with one unit. section 4.1.3 section 4.1.7

Binary image classification

A dogs-versus-cats ConvNet ends with `Dense(1, activation="sigmoid")`. Its single output represents the probability of one class or the other. Compile this arrangement with `binary_crossentropy`, commonly using the `adam` optimizer. section 8.2.3

Use sigmoid with these practical rules:

  • Choose one sigmoid output unit for two-class classification rather than separate outputs for both classes. section 4.1.7
  • Pair a single sigmoid output with binary crossentropy during model compilation. section 4.1.7 section 4.1.3
  • Do not use sigmoid for unrestricted scalar regression: it limits predictions to values between 0 and 1. section 4.3.3
Listing 8.7 Instantiating a small ConvNet for dogs vs. cats classification
import keras
from keras import layers

inputs = keras.Input(shape=(180, 180, 3))                           #1
x = layers.Rescaling(1.0 / 255)(inputs)                             #2
x = layers.Conv2D(filters=32, kernel_size=3, activation="relu")(x)
x = layers.MaxPooling2D(pool_size=2)(x)
x = layers.Conv2D(filters=64, kernel_size=3, activation="relu")(x)
x = layers.MaxPooling2D(pool_size=2)(x)
x = layers.Conv2D(filters=128, kernel_size=3, activation="relu")(x)
x = layers.MaxPooling2D(pool_size=2)(x)
x = layers.Conv2D(filters=256, kernel_size=3, activation="relu")(x)
x = layers.MaxPooling2D(pool_size=2)(x)
x = layers.Conv2D(filters=512, kernel_size=3, activation="relu")(x)
x = layers.GlobalAveragePooling2D()(x)                              #3
outputs = layers.Dense(1, activation="sigmoid")(x)
model = keras.Model(inputs=inputs, outputs=outputs)

Inspect the complete Keras ConvNet definition to see sigmoid attached to the final Dense layer after convolution and pooling stages. section 8.2.3

How Deep Learning with Python, Third Edition covers it

How deep it goes
Defines the output range and placement, but stops short of deriving the sigmoid formula or explaining its internals.
Examples
Uses sentiment classification and dogs-versus-cats image classification as concrete binary-output examples.
What it assumes
Assumes basic neural-network layers and training while clarifying activation functions, probability outputs, and binary classification choices.
What you can do after
Apply it via Keras by configuring one sigmoid output unit and binary crossentropy for binary classification.
How it connects
Connects sigmoid to binary classification, Dense layers, activation functions, binary crossentropy, and the Adam optimizer.

Also explained in

Compare how 16 books explain sigmoid →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.