← govind p lal
AI and ML Bootcamp · Lecture 2 · lecture notes

AI and ML: From Rules to Transformers

In short — How did we get from hand-written rules to ChatGPT? This lecture walks through learning, knowledge and intelligence, then rule-based systems, statistical ML, embeddings, RNNs/LSTMs and their forgetting problem. It lands on the Transformer (parallel processing + attention), how next-word prediction generates text, and parameters and compute make models better.">scaling laws.

What does it mean to learn?

Learning is changing yourself based on experience.

repeatTryFeedbacke.g. fell off the bikeAdjust
The learning loop.

Knowledge and intelligence

TypeMeaningExample
Explicit knowledgeDefined by rules or factsCapital of India is Delhi
Implicit knowledgeLearned from experience, no clear rulesRecognising a friend's face

Intelligence - ability to perform well across a very wide range of situations. A calculator is great at arithmetic only. Therefore not intelligent.

AI - making computers intelligent across general tasks (sarcasm, answering any question), not one rule-definable skill.

Rule-based systems

builds on Lecture 1: Week 0 - AI and ML | Orientation | 09/01/2026

First attempt (1950s-60s): write explicit rules. -> Rule-based systems

Reasons to fail

Machine learning from data

builds on Lecture 1: Week 0 - AI and ML | Orientation | 09/01/2026

Machine learning - machine writes rules for itself from data, without us explicitly coding them.

repeat millions of timesShow exampleRandom guessFeedbackright or wrongAdjust itself
How a machine learns from examples.

Example: weather data (above a threshold means hot), email (money word followed by a weird link means spam; meeting link with time and attendees means important).

Early wins: spam filters, recommendations (Netflix, Amazon), Google search, basic image recognition.

Deep learning - subset of ML that relies on neural networks, designed to mimic brain neurons.

Why early ML was limited

Why AI boomed again

CNN (convolutional neural network) - uses convolution on a matrix to understand images. Designed first by Yann LeCun. Solved CAPTCHAs.

CNNs only classify into fixed classes (e.g. man, woman, dog, cat). No description or context. Unseen classes fail. Not real intelligence.

ImageNet (2012) - ~1 million images in many classes. AlexNet, a CNN trained with heavy NVIDIA compute, topped it and restarted the boom.

Core idea of attention came from the Bahdanau attention paper. Google used it in the Transformer ('Attention Is All You Need').

Why language is hard

Natural Language Processing (NLP) - the field of making computers work with language.

"I saw the man with the telescope" - who has the telescope? Humans resolve it. Machines see words as random numbers.

Approach 1: dictionary of every word. Fails.

Approach 2: statistical patterns (n-grams).

Word embeddings

Convert a word into a list of numbers. -> Embedding (vector). Words are really handled as tokens, which can be sub-word pieces and differ per company.

Each number is a position on one dimension of meaning. Apple: high on red, very low on square.

WordRoyaltyMaleEdible
King0.98highlow
Queen0.97lowlow
Applelownonehigh

Word math

Problem

"I went to the bank to deposit cash" vs "I sat on the bank of the river". Each word has one fixed vector, so bank is identical in both. Words do not talk to each other.

Solution

Process the whole sequence so context changes the meaning. -> Sequence models.

Sequence models: RNN, LSTM, GRU

RNN (recurrent neural network) - reads one word at a time and carries a memory of earlier words. Memory changes the vector for bank depending on what came before and after.

The Problem

"The cat which was sitting on the mat that I bought from the store near the old church on the corner was happy". By the time we reach happy, the subject cat is forgotten.

LSTM (long short-term memory) - adds a gate on each word to decide remember or drop. Keeps more than RNN but still fails on much longer text. GRU is a similar variant.

Sequence model family: RNN, LSTM, GRU, and later the Transformer. Mamba is another, but did not scale as widely.

Transformer: parallel processing + attention

Two ideas

Who was happy? Attention jumps from happy straight to cat, ignoring the rest.

Example

"The animal didn't cross the street because it was too tired" -> it attends to animal. "The animal didn't cross the street because it was too wide" -> it attends to street. One word changes the context, and attention follows.

RNNs and LSTMs would lose this on long text. LSTM keeps ~50% of the info; attention picks only the few relevant words.

Why it took over: everything is a sequence (text, pixels, audio), so the same architecture spread. -> Vision Transformer for images, audio transformers, diffusion transformers for images and video.

!

The Transformer is built entirely on attention. No recurrence, no convolution.

LLMs and SLMs

builds on Lecture 1: Week 0 - AI and ML | Orientation | 09/01/2026

Language model - takes text as input and continues it by predicting the next word.

Large -> number of parameters (neurons): billions to a trillion. Small language models (SLMs) have around 1-5 billion or fewer, so they can run offline on a phone. Same Transformer architecture.

How ChatGPT generates text

A language model can only do one thing: predict the next word. -> Next-word predictor. Answering questions comes from post-training on top.

Output is a list of words with probabilities, e.g. 80%, 10%, 5%, 2%.

append and repeatInput sentenceTransformerWord probabilitiesPick a word
Generation is an iterative loop.
Example

"The quick" -> brown; "The quick brown" -> fox; then jumps, over, the lazy dog.

Does prediction mean understanding? In a mystery novel, predicting the killer's name correctly at the end needs the whole story. So good prediction needs real understanding of context.

Scaling laws, foundation models, reasoning, agents

builds on Lecture 1: Week 0 - AI and ML | Orientation | 09/01/2026

Scaling laws - more data, more parameters and more compute reliably make the model better.

Foundation model - big general-purpose model trained on almost everything. Base for many tools.

Reasoning - give the model more compute and tokens to think at inference time for more accurate answers.

Function calling - model calls a function (e.g. get a name) and uses its output in the answer. -> Basis for agents.

Agent - an application on top of an LLM that takes user input plus context and does work, e.g. Claude Code, OpenCode, travel planning agent.

Training data and tools mentioned

builds on Lecture 1: Week 0 - AI and ML | Orientation | 09/01/2026

Training data: companies scrape the internet with web crawlers, copy every page into a database, and train on it.

A visualiser of GPT models shows nanoGPT (~85,000 parameters), GPT-2 small, GPT-2 XL, GPT-3. In it you can see input embeddings, Q, K, V vectors, attention matrix, repeated attention layers and the final next-word output.

Google Colab / Jupyter notebook - runs Python in separate cells; variables persist, and you can rerun one cell without rerunning everything.

def add(a, b):
    return a + b

print(add(2, 3))  # 5

Glossary

Embedding
A vector of numbers representing a word, each number a dimension of meaning.
Attention
Mechanism letting the model focus on the most relevant words regardless of distance.
RNN
Recurrent neural network that reads word by word and keeps a memory.
LSTM
RNN variant with a gate deciding what to remember.
CNN
Convolutional neural network, used for images.
Scaling laws
More data, parameters and compute make models better.
Parameters
The neurons/weights of a model; measure of its size.
Agent
Application built on an LLM that takes input and performs work.
AI winter
Period when funding collapsed because early ML lacked data and compute.