AI Layers and Activation Functions

A neural network gets its power not from a single neuron but from stacking many neurons into layers, each layer's output reshaped by an activation function before it moves on.

From One Neuron to a Network

A single artificial neuron (or perceptron) takes some inputs, multiplies each by a weight, adds them up along with a bias, and produces one number. On its own, that is not very useful - it can only draw a straight dividing line between two outcomes. The real power of a neural network comes from arranging many of these neurons into layers and connecting layer to layer, so that the output of one layer becomes the input to the next.

Input, Hidden, and Output Layers

Every network has an input layer, which simply holds the raw data (pixel brightness values, word counts, sensor readings) without doing any calculation. Between the input and the final answer sit one or more hidden layers, where the actual pattern-detection happens - each hidden neuron combines signals from the previous layer in a slightly different way. Finally, the output layer produces the network's answer, shaped to match the task: a single number for a price prediction, a yes/no probability for a binary decision, or a list of probabilities for a multi-class decision.

  • Input layer - holds the raw features, performs no computation
  • Hidden layer(s) - combine and transform signals from the previous layer to detect patterns
  • Output layer - produces the final prediction, shaped to fit the task

Why a Network Needs Activation Functions

If every neuron only computed a weighted sum, stacking ten layers would mathematically collapse into the same thing as one layer - weighted sums of weighted sums are still just a weighted sum. An activation function is a small nonlinear function applied to each neuron's output before passing it forward. That nonlinearity is what lets a deep stack of layers represent curves, thresholds, and complex decision boundaries instead of only straight lines.

FunctionWhat It DoesTypically Used In
ReLU (Rectified Linear Unit)Passes positive values through unchanged and outputs zero for negative valuesHidden layers of most modern networks
SigmoidSquashes any input into a range between 0 and 1Output layer for a single yes/no probability
SoftmaxConverts a list of raw scores into probabilities that add up to 1Output layer choosing one class among many
TanhSquashes any input into a range between -1 and 1Hidden layers, especially in older or recurrent networks

Example

import numpy as np

def relu(x):
    return np.maximum(0, x)

def sigmoid(x):
    return 1 / (1 + np.exp(-x))

raw_scores = np.array([-2.0, -0.5, 0.0, 1.5, 3.0])

print("ReLU output:", relu(raw_scores))
print("Sigmoid output:", sigmoid(raw_scores))
Note: As a rule of thumb: use ReLU in hidden layers by default, sigmoid for a single yes/no output, and softmax for an output layer that must choose one class among several.

Layers also vary in width - the number of neurons inside a single layer. A wider layer can hold more distinct patterns at once, while a deeper stack of narrower layers can build up more complex ideas step by step by combining simpler ones from the layer before it. Choosing how wide and how deep to make a network is part of designing its architecture.

Note: Sigmoid and tanh squash their output into a narrow range, which can make the training signal shrink to almost nothing as it passes back through many layers - a problem known as the vanishing gradient. This is one reason ReLU became the default choice for hidden layers in modern deep networks.