Neural Networks Explained for Beginners

Artificial Intelligence Tutorials


A neural network is a model that combines numerical inputs through layers of calculations to produce an output. It can learn useful patterns from examples, but it is not a human brain and does not “understand” a task in the human sense. This lesson follows one small network from input to output.

Begin with a practical task

Imagine predicting whether an order may arrive late. Two possible input features are the distance and a traffic score. Before using them in a model, define how each number is measured and ensure it is available when the prediction is made. Other useful features might include weather or time of day; a later delivery status would leak the answer.

Two inputs pass through two hidden nodes to one output score, matching the runnable Python example.
Two inputs pass through two hidden nodes to one output score, matching the runnable Python example.

The diagram has an input layer, a hidden layer with two nodes, and an output layer. The input nodes hold feature values. Hidden nodes combine those values. The output node produces a score that a later decision rule can use.

What does a node calculate?

A node multiplies each incoming value by a weight, adds those products and a bias, then applies an activation function. For two inputs, the calculation before activation is w1 × x1 + w2 × x2 + b. Weights say how strongly each input contributes; the bias shifts the result.

Suppose x1 = 0.8 and x2 = 0.3. One hidden node uses weights 1.2 and -0.5 with a bias of 0.1. Its pre-activation value is 1.2 × 0.8 - 0.5 × 0.3 + 0.1 = 0.91. A different hidden node can learn a different combination of the same inputs.

Why use an activation function?

An activation function changes the weighted sum before it reaches the next layer. ReLU returns the larger of zero and its input, so ReLU(0.91) = 0.91 while ReLU(-0.4) = 0. Without nonlinear activations between layers, stacking only linear calculations would still act like one linear transformation; the model would lose an important way to represent more complex patterns.

For a binary output, a sigmoid activation maps a number to a score between 0 and 1. A value such as 0.74 can be compared with a decision threshold, but it is not automatically a trustworthy probability. The model must be trained and evaluated on suitable data before anyone relies on its scores.

Run a tiny forward pass in Python

This example uses two input values, two hidden nodes, and one output node. The weights are hand-picked only to demonstrate the arithmetic; the script does not train a model. Change an input or a weight and run it again to see the score change.

from math import exp


def relu(value):
    return max(0.0, value)


def sigmoid(value):
    return 1 / (1 + exp(-value))


x1, x2 = 0.8, 0.3
h1 = relu(1.2 * x1 - 0.5 * x2 + 0.1)
h2 = relu(-0.4 * x1 + 1.0 * x2 + 0.2)
score = sigmoid(1.5 * h1 - 0.8 * h2 - 0.2)

print(f"Hidden values: {h1:.2f}, {h2:.2f}")
print(f"Output score: {score:.2f}")

Output: Hidden values: 0.91, 0.18; Output score: 0.74. This calculation is called a forward pass: values move from inputs, through hidden nodes, to the output.

How does a network learn?

During training, the network makes a prediction for an example with a known answer. A loss function measures the difference between prediction and target. An optimization method adjusts weights and biases to reduce that loss across many examples. The process repeats over batches of training data.

Training loss alone does not tell us whether the network generalizes. Use separate validation data while choosing settings and untouched test data for a final estimate. A large network can overfit a small dataset, so model size and training time should match the problem and the available evidence.

Key points

  • Inputs are numerical features; hidden nodes combine them with weights, biases, and activations.
  • The output is a score or prediction whose meaning depends on the model and task.
  • Training changes the weights; the example above only demonstrates one fixed forward pass.
  • Evaluate on unseen examples before using the result to make decisions.


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram