Note 04 of 09
Learning

Machine Learning & Neural Networks

How machines learn from data instead of following hand-coded rules — from simple linear models to deep networks with billions of parameters that power modern AI.

CORE CONCEPTREADING · 18–24 MINPREREQUISITE · NOTES 01–03KNOWLEDGE BASE · 04 / 09
Start here

The paradigm shift from programming to learning.

Traditional software is explicitly programmed: a human writes rules, and the machine follows them. Machine learning inverts this — the machine discovers its own rules from data. This shift is the engine behind nearly every modern AI breakthrough, from image recognition to language models.

Learning objectives

By the end of this note, you should be able to:

  • Explain how machine learning differs from traditional programming
  • Distinguish supervised, unsupervised, and reinforcement learning
  • Describe neural network architecture: layers, nodes, activation functions
  • Explain how deep learning builds hierarchical representations
  • Understand the training→inference lifecycle and why optimization matters
  • Articulate what makes transformers and GPT models architecturally distinct
01 — Fundamentals

Learning from data, not from instructions.

Machine Learning
A subset of artificial intelligence in which systems improve their performance on a task through experience with data, without being explicitly programmed with rules for that task.

Intuition: teaching by example

Imagine teaching a child to recognize cats. You don't describe whisker lengths, ear shapes, and fur patterns in precise measurements. You show them many cats and say "this is a cat" — eventually, they learn. Machine learning works similarly: instead of coding rules, you feed a system thousands of labeled examples, and it discovers the patterns that distinguish cats from dogs.

Technical: the learning problem

Formally, machine learning seeks a function f that maps inputs X to outputs Y, such that f generalizes well to unseen data. The system is given a training set of input-output pairs, a loss function that measures prediction error, and an optimization algorithm that adjusts internal parameters to minimize that loss.

Why this matters

Machine learning shifted AI from brittle, hand-crafted rule systems (→ Note 03: Traditional Techniques) to adaptive systems that improve automatically. This is why modern AI can handle tasks too complex for humans to specify rules for — like understanding natural language or recognizing faces in varied conditions.

Data

The raw material. More data generally means better models, provided the data is relevant, diverse, and properly labeled.

Model

The mathematical structure that learns patterns — from simple linear regressions to neural networks with billions of parameters.

Loss Function

A measure of how wrong the model's predictions are. Training minimizes this function across the training data.

02 — Pipeline

From raw data to predictions.

Every machine learning system follows a common pipeline: collect data, prepare it, train a model, evaluate its performance, and deploy it for inference on new data.

DataCollect, clean, label
→
TrainingFit model to data
→
ModelLearned parameters
→
InferencePredict on new data
→
OutputDecisions, predictions
Training vs. inference

Training is the expensive, one-time process of learning from data — it can take days or weeks on powerful GPUs. Inference is the fast, repeated process of using the trained model to make predictions on new inputs. This distinction is fundamental to understanding AI system costs and capabilities.

03 — Types of Learning

Three paradigms for learning from experience.

Machine learning systems are categorized by the type of feedback signal they receive during training. Each paradigm suits different kinds of problems and available data.

ParadigmTraining SignalGoalExample Tasks
Supervised LearningLabeled input-output pairsLearn mapping from inputs to known outputsImage classification, spam detection, translation
Unsupervised LearningUnlabeled data onlyDiscover hidden structure and patternsClustering, dimensionality reduction, anomaly detection
Reinforcement LearningReward/penalty signals from environmentLearn optimal sequence of actions (policy)Game playing, robotics, autonomous driving

Supervised Learning

Intuition: A teacher provides the correct answer for each example.

Technical: Given a dataset of (x, y) pairs, learn a function f(x) → y that generalizes to new x values. Common algorithms: linear regression, decision trees, support vector machines, neural networks.

Example: Email spam detection — trained on thousands of emails labeled "spam" or "not spam," the model learns which features (keywords, sender patterns) predict spam.

Unsupervised Learning

Intuition: Finding patterns in data with no answer key.

Technical: Given unlabeled data X, discover latent structure — clusters, distributions, or compressed representations. Common algorithms: k-means clustering, PCA, autoencoders, GANs.

Example: Customer segmentation — grouping shoppers by purchasing behavior without predefined categories, revealing natural market segments.

Reinforcement Learning

Intuition: Learning by trial and error with rewards and penalties.

Technical: An agent interacts with an environment, taking actions and receiving rewards. It learns a policy — a strategy mapping states to actions — that maximizes cumulative reward. Key algorithms: Q-learning, policy gradients, PPO.

Example: AlphaGo learned to play Go by playing millions of games against itself, receiving +1 for wins and −1 for losses (→ Note 02: Goals).

The data dependency

Supervised learning requires large labeled datasets, which are expensive to create. This bottleneck drove the rise of self-supervised learning (a form of unsupervised learning) — where models create their own training signal from unlabeled data. This is how GPT and other large language models are trained: by predicting the next word in text, requiring no human labels.

04 — Neural Networks

The architecture that powers modern AI.

Artificial neural networks are computing systems loosely inspired by biological neural networks. They consist of interconnected nodes (neurons) organized in layers, where each connection has an adjustable weight that is tuned during training.

Neural Network
A computational model composed of layers of interconnected nodes, where each node applies a weighted sum of its inputs followed by a nonlinear activation function to produce an output signal.
INPUT LAYER HIDDEN LAYERS OUTPUT LAYER x₁ x₂ x₃ x₄ h₁ h₂ h₃ h₄ h₅ h₆ h₇ y₁ y₂ pixel pixel pixel pixel cat: 0.92 dog: 0.08 EACH NEURON COMPUTES: output = σ(w₁x₁ + w₂x₂ + ... + b) σ = activation function, w = weights, b = bias
Figure 01 · Feedforward neural network: input layer → hidden layers → output layer

Architecture components

Layers

Input layer: receives raw data (pixels, words, sensor readings). Each node represents one feature of the input.

Hidden layers: perform computations. Each layer transforms the data, extracting increasingly abstract features. More hidden layers = "deeper" network.

Output layer: produces the final prediction (classification probabilities, regression values, generated text).

Activation Functions

Non-linear functions applied at each neuron, enabling networks to learn complex patterns. Without them, any number of layers would collapse to a single linear transformation.

ReLU (Rectified Linear Unit): f(x) = max(0, x) — the most common choice, simple and effective.

Sigmoid: f(x) = 1/(1+e⁻ˣ) — squashes output to [0,1], used in output layers for binary classification.

Softmax: converts raw scores to probability distributions across classes.

Weights and biases

Each connection between neurons has a weight (how much influence one neuron has on another) and each neuron has a bias (a baseline activation level). Training adjusts these millions or billions of parameters to minimize prediction error. A network with 1 billion parameters has 1 billion numbers to tune — this is why training requires enormous computation.

05 — Deep Learning

Layers that build understanding.

Deep learning uses neural networks with many hidden layers — sometimes hundreds. Each layer learns to represent the data at a different level of abstraction, building a hierarchy from simple features to complex concepts.

Deep Learning
A subset of machine learning that uses multi-layer neural networks to learn hierarchical representations of data, enabling automatic feature extraction and pattern recognition at multiple levels of abstraction.
Layer 1 Raw pixels → Layers 2–3 Edges & textures → Layers 4–8 Parts (eyes, ears) → Layers 9–16 Objects (cat, dog) ↑ Layers 17+ Semantic concepts ABSTRACTION INCREASES → Each layer combines features from the layer below to form more complex, higher-level representations.
Figure 02 · Hierarchical feature learning: each layer builds on the previous one

Key architectures

Convolutional Neural Networks (CNNs)

Intuition: Sliding a filter across an image to detect local patterns like edges, then combining those into larger structures.

Technical: Use convolutional layers with learnable filters that detect spatial features. Pooling layers reduce dimensionality. Shared weights make them parameter-efficient for image data.

Example: ImageNet-winning models like AlexNet, ResNet. Used in medical imaging, autonomous driving, facial recognition.

Recurrent Neural Networks (RNNs)

Intuition: Processing sequences one element at a time, maintaining a "memory" of what came before.

Technical: Each step takes the current input and the previous hidden state, producing a new hidden state. Variants like LSTM and GRU address the vanishing gradient problem for long sequences.

Example: Language modeling, time series prediction, speech recognition. Largely replaced by transformers for NLP tasks since 2017.

Representation learning

The core insight of deep learning: instead of hand-engineering features (→ Note 03: Traditional Techniques), let the network learn the best features automatically. A CNN trained on images learns edge detectors in early layers and object-part detectors in later layers — no human specified what "edges" or "parts" should look like.

06 — Transformers & GPT

The architecture behind modern language AI.

Generative Pre-trained Transformers (GPT) represent the dominant architecture in modern AI. Built on the transformer architecture introduced in 2017, these models process language by attending to all parts of the input simultaneously — rather than reading sequentially like RNNs.

Transformer
A neural network architecture that uses self-attention mechanisms to weigh the importance of different parts of the input when producing each output element. Enables parallel processing and captures long-range dependencies in sequences.

Self-Attention

The key innovation. For each word in a sentence, the model computes how much it should "attend to" every other word. In "The cat sat on the mat because it was tired," attention links "it" to "cat" — resolving ambiguity that sequential models struggled with.

Mathematically: Attention(Q,K,V) = softmax(QKT/√d)V — queries, keys, and values derived from the input, scaled by dimension.

Generative Pre-training

Pre-training: Train on massive text corpora with a simple objective — predict the next token. No labels needed. The model learns grammar, facts, reasoning patterns, and world knowledge implicitly.

Fine-tuning: Adapt the pre-trained model to specific tasks (summarization, coding, conversation) with small amounts of task-specific data or via instruction tuning (RLHF).

Scale is the key variable

GPT-2 (2019) had 1.5 billion parameters. GPT-3 (2020) had 175 billion. GPT-4 (2023) is estimated at over a trillion. As models scale, they exhibit emergent capabilities — abilities not present in smaller versions, like chain-of-thought reasoning, code generation, and few-shot learning. This scaling behavior is one of the most important phenomena in modern AI research. → Note 05: Modern AI Systems

07 — Training & Optimization

How networks actually learn.

Training a neural network is an optimization problem: find the set of weights and biases that minimizes the loss function across the training data. This is done iteratively through forward passes, loss computation, and backward propagation of errors.

Forward Pass

Input data flows through the network layer by layer. Each neuron computes a weighted sum of inputs plus bias, applies an activation function, and passes the result forward. The output layer produces a prediction.

Backpropagation

The core algorithm. After the forward pass, the loss function measures prediction error. Backpropagation computes the gradient of the loss with respect to every weight — using the chain rule of calculus — propagating error signals backward through the network.

Gradient Descent

The optimization algorithm. Each weight is adjusted by a small step in the direction that reduces loss. The step size is controlled by the learning rate. Variants like Adam, SGD with momentum, and AdaGrad improve convergence speed and stability.

Overfitting & Regularization

A model that memorizes training data but fails on new data is overfitting. Regularization techniques — dropout, weight decay, early stopping, data augmentation — prevent this by constraining the model's capacity to memorize noise.

The computational cost

Training GPT-4 is estimated to have cost over $100 million in compute alone, using tens of thousands of GPUs for months. This has concentrated AI development in well-funded organizations and raised questions about the sustainability of the current scaling approach.

Inference: using the trained model

Once trained, the model is deployed for inference — making predictions on new, unseen data. Inference is computationally cheaper than training (no gradients needed), but still requires significant resources for large models. Techniques like quantization, pruning, and distillation reduce model size for efficient deployment on edge devices.

End of note

Remember these ideas.

01

Machine learning learns patterns from data instead of following hand-coded rules — a paradigm shift that enables AI to handle tasks too complex for explicit programming.

02

Three learning paradigms: supervised (labeled examples), unsupervised (finding hidden structure), and reinforcement (trial-and-error with rewards).

03

Neural networks are layers of connected neurons — each computing weighted sums plus nonlinear activations. Weights are adjusted during training via backpropagation.

04

Deep learning adds many layers, each learning features at a higher level of abstraction — from pixels to edges to parts to objects to concepts.

05

Transformers replaced RNNs by using self-attention to process sequences in parallel. GPT models scale this architecture to billions of parameters with emergent capabilities.

06

The training-inference distinction is fundamental: training is expensive and one-time; inference is fast and repeated. Optimization (backprop + gradient descent) is how networks learn.

Reference

Glossary

Machine LearningSystems that improve performance on tasks through experience with data, without explicit programming.
Neural NetworkA computational model of interconnected layered nodes inspired by biological brains.
Deep LearningMachine learning using multi-layer neural networks to learn hierarchical representations.
BackpropagationAlgorithm that computes gradients of the loss function with respect to all weights, enabling training via gradient descent.
Activation FunctionA nonlinear function (ReLU, sigmoid, softmax) applied at each neuron, enabling networks to learn complex patterns.
Loss FunctionA mathematical measure of how far predictions are from true values — the objective training seeks to minimize.
Gradient DescentOptimization algorithm that iteratively adjusts parameters in the direction that reduces the loss function.
OverfittingWhen a model memorizes training data noise instead of learning generalizable patterns, causing poor performance on new data.
TransformerA neural network architecture using self-attention mechanisms to process sequences in parallel, powering modern language models.
GPTGenerative Pre-trained Transformer — large language models trained to predict the next token in a sequence.
InferenceUsing a trained model to make predictions on new, unseen data — distinct from the training phase.
CNNConvolutional Neural Network — uses learnable filters to detect spatial patterns, dominant in computer vision.