AI & ML: An Introduction to Neural Networks
Inspired by the Brain, Built with Math
A neural network is a chain of simple calculations stacked into layers. The smallest useful unit is the perceptron: it multiplies inputs by weights, adds a bias, and pushes the sum through an activation function. Stack many of these units into layers and you get a network that can draw curved, complex boundaries that single lines cannot.
One Neuron at a Time
def neuron(inputs, weights, bias):
total = sum(a * b for a, b in zip(inputs, weights)) + bias
return max(0, total) # relu activationThe multiplication weights decide how much each input matters. The bias shifts the decision point. The relu activation lets negative sums collapse to zero and keeps positives flowing, which gives the network the ability to model non-linear patterns.
Layers and Depth
An input layer receives the raw features. Hidden layers sit between input and output and perform intermediate transformations. The output layer produces the final answer, a number for regression or a probability per class for classification.
input: [brightness, size, shape]
hidden_1: 64 neurons
hidden_2: 32 neurons
output: cats 0.92, dogs 0.08Deeper networks stack more hidden layers and can express more complex functions, which is why deep learning earned its name. Depth does not come free: more parameters mean more data, more compute, and more risk of overfitting.
How the Network Learns
Training a network is the same loop as other models, scaled up. Forward pass: push data through the layers and read the prediction. Loss: measure the gap between prediction and truth. Backward pass, or backpropagation: compute how each weight contributed to the error and nudge it a little downhill with gradient descent. Repeat across the whole dataset many times.
Training Tricks That Matter
- Epochs - how many full passes over the data.
- Learning rate - how big every weight step is.
- Batch size - how many samples are processed before an update.
- Dropout - randomly disabling neurons during training to fight overfitting.
Frameworks such as TensorFlow and PyTorch handle the details; your job is choosing the architecture, data, and hyperparameters and watching the validation curves.
Key Points
- Neurons multiply, bias, activate, and pass values onward.
- Hidden layers between input and output give networks expressiveness.
- Backpropagation plus gradient descent updates every weight.
- Frameworks handle the math; architects handle data and design.