Neural networks power today's most impressive AI: image recognition, speech-to-text, translation and large language models. They are built from a very simple unit - the artificial neuron.
A single neuron (perceptron)#
A neuron takes inputs x₁, x₂, ..., multiplies each by a weight, adds a bias, and passes the result through an activation function:
z = w₁x₁ + w₂x₂ + ... + b
output = activation(z)
The weights say how important each input is; the bias shifts the decision point. Learning means finding good weights and biases.
एक neuron हर input को उसके weight (महत्त्व) से गुणा करता है, सबको जोड़ता है, bias जोड़ता है और फिर activation function से फैसला करता है। Training का मतलब है ऐसे weights और bias खोजना जिनसे सही output आए। एक अकेला neuron सिर्फ़ एक सीधी रेखा से data बाँट सकता है, इसलिए XOR जैसे सवालों के लिए कई neurons की परतें (layers) चाहिए।
Activation functions#
z : [-3. -1. 0. 1. 3.] step : [0 0 0 1 1] sigmoid : [0.047 0.269 0.5 0.731 0.953] tanh : [-0.995 -0.762 0. 0.762 0.995] ReLU : [0. 0. 0. 1. 3.]
| Activation | Output range | Typical use |
|---|---|---|
| sigmoid | 0 to 1 | output layer for binary classification (a probability) |
| softmax | probabilities that add to 1 | output layer for multi-class classification |
| tanh | -1 to 1 | hidden layers (older networks, RNNs) |
ReLU max(0, z) |
0 to ∞ | hidden layers of most modern networks |
Without non-linear activations, any number of layers would still compute just one linear function - the network could only draw straight lines.
Multi-layer networks#
Neurons are arranged in layers:
input layer hidden layer(s) output layer
x₁ ──┐ ┌─ h₁ ─┐
x₂ ──┼──(W1,b1)─┼─ h₂ ─┼──(W2,b2)── ŷ
x₃ ──┘ └─ h₃ ─┘
Each layer computes activation(previous_layer @ W + b). This is the forward pass. A network with several hidden layers is "deep" - hence deep learning.
XOR solved with one hidden layer#
input [0 0] -> hidden [0 0] -> XOR 0 input [0 1] -> hidden [1 0] -> XOR 1 input [1 0] -> hidden [1 0] -> XOR 1 input [1 1] -> hidden [1 1] -> XOR 0
The hidden layer creates new features (OR, AND) in which XOR is linearly separable: XOR = OR and not AND.
How networks learn: loss, backpropagation, gradient descent#
- Forward pass - compute predictions with the current weights.
- Loss - measure how wrong they are (MSE for regression, cross-entropy for classification).
- Backpropagation - use the chain rule of calculus to compute how much each weight contributed to the loss (its gradient), from the output layer backwards.
- Update - move each weight a small step against its gradient (gradient descent).
- Repeat for many epochs (passes over the training data), usually in mini-batches.
Here is a complete two-layer network trained from scratch with NumPy to learn XOR:
epoch 1 loss 1.1836 epoch 100 loss 0.0385 epoch 1000 loss 0.0025 epoch 5000 loss 0.0005 predictions: [0. 0.999 0.999 0.001]
The loss falls and the predictions approach 0, 1, 1, 0. Libraries like PyTorch and TensorFlow/Keras compute these gradients automatically ("autograd"), so you only write the forward pass.
A real task: recognising handwritten digits#
scikit-learn's MLPClassifier (multi-layer perceptron) trains a neural network with backpropagation for you. The digits dataset has 1,797 images of 8×8 pixels:
layers: [64, 64, 32, 10] trained for 113 epochs weights to learn: 6570 test accuracy: 0.964 mistakes (true, predicted, count): [(1, 8, 1), (2, 1, 1), (2, 3, 1), (3, 2, 1), (3, 8, 1), (3, 9, 1), (4, 8, 1), (6, 1, 2), (8, 1, 2), (8, 3, 1), (8, 9, 1), (9, 3, 2), (9, 5, 1)]
Where to go next: deep learning frameworks#
| Network type | Specialised for | Examples |
|---|---|---|
| MLP (fully connected) | tabular data, small problems | what you trained above |
| CNN (convolutional) | images, video | face unlock, medical scans, crop disease detection |
| RNN / LSTM | sequences (older approach) | time series, early speech models |
| Transformer | text, code, images, audio | GPT, Claude, Gemini, translation |
For bigger networks use PyTorch or TensorFlow/Keras with a GPU - for example in Google Colab or Kaggle Notebooks, both free. A classic first deep-learning project is the MNIST (28×28 digits) or Fashion-MNIST dataset.
Neural networks need more data, more computing power and more tuning than classic models. On ordinary tabular business data, gradient boosting and random forests often beat them. Reach for deep learning with images, audio, text and very large datasets.
Summary#
- A neuron computes
activation(w·x + b); layers of neurons form a network. - Non-linear activations (ReLU, sigmoid, tanh) let networks learn complex patterns; one neuron cannot learn XOR, a hidden layer can.
- Training = forward pass → loss → backpropagation → gradient-descent update, repeated for many epochs.
MLPClassifiertrains small networks; PyTorch/TensorFlow handle deep learning (CNNs, Transformers).