Intro to AI : Part 3

Classifiers and Embeddings

Mehmet Kerem Turkcan
Associate Research Scientist
Center for Smart Streetscapes, Columbia University
New York, USA
keremturkcan.com;  mkt2126@columbia.edu

Move with the arrow keys, a presentation clicker, or the buttons at the bottom left; the gear at the bottom right opens the slide settings.

Where Parts 1 and 2 left us

  1. Tokens: text is cut into pieces the size of syllables, and each piece carries a whole number ID.
  2. The game: given the text so far, the model assigns a probability to every token in the vocabulary.
  3. The transformer: reads the whole window at once through attention, which we have named and will open in Part 9.
  4. The loop: the model writes by repeating predict, sample, append.

Today we open the machine at its two ends: the way in for tokens, and the way out for answers.

Is a tomato a fruit?

You: Is a tomato a fruit?
The model: Yes
Question for the class: the reply is one token. Which machinery from Part 1 chose it?
yes 0.91 no 0.05 all others 0.04
The same bars as always: the model scored every token in the vocabulary, and yes won. Illustrative numbers.
For the classroom: collect three more questions, each answered yes or no, from students before advancing; they return as test cases on the feedforward slide.

A vocabulary of two

Freeze the question and allow only two answers, and the giant game collapses: a vocabulary of 50,257 tokens becomes a vocabulary of 2.

the whole vocabulary yes no keep two answers the collapsed game yes 0.95 no 0.05
On the right, the two surviving probabilities are rescaled to add up to 1; all numbers illustrative.

A machine that assigns probabilities to a fixed set of answers is called a classifier.

For decades, spam filtering, loan screening, and medical screening ran on machines of exactly this kind, each task a game with two answers.

Three questions about one message

Our tiny machine will answer: is this message spam? It reads the message through three smaller questions, and it stores each answer as a number, 1 for yes and 0 for no.

FREE tickets!!! click now
question about the messageansweras a number
does it contain the word free?yes1
does it shout with !!! anywhere?yes1
is the sender in your contacts?no0

Numbers that answer questions about the input are called features. Hold onto this move; it returns at a smaller scale before the lecture ends.

For the classroom: have students propose a fourth question and predict whether its yes should push toward spam or away from it.

Weights, bias, score

Each question carries a weight, a number that says how strongly its answer should push, and in which direction. One extra number, the bias, sets where the machine stands before it reads anything.

\text{score} = w_1 x_1 + w_2 x_2 + w_3 x_3 + b
free? = 1 !!! ? = 1 contact? = 0 bias −0.5 Σ add them up score = 3.0 ×2.1 ×1.4 ×−3.0
\text{message A: }\; 2.1 \cdot 1 + 1.4 \cdot 1 + (-3.0) \cdot 0 + (-0.5) = 3.0
\text{message B, from a contact: }\; 2.1 \cdot 0 + 1.4 \cdot 0 + (-3.0) \cdot 1 + (-0.5) = -3.5

The weights here are illustrative; a real filter learns its own, as the coming slides show.

From score to probability

A score can be any number, while a probability must live between 0 and 1. The bridge is a fixed curve, called the sigmoid: feed it any score, and it returns a probability. Large positive scores land near 1; large negative scores land near 0; a score of 0 lands exactly on one half.

−6 −3 0 3 6 0 0.5 1 score probability of yes message A: 0.95 message B: 0.03 (0, 0.50)
For the curious: the curve is 1 divided by (1 plus e to the negative score); reading the graph is enough for everything we do.

So message A reports spam 0.95, leaving 0.05 for the other answer; message B reports spam 0.03.

For the classroom: ask what score a message must reach before the filter is 99 percent sure, and let students read the answer off the curve; anything past 4 earns the point (the exact answer is about 4.6).

The feedforward network

Because the signal flows from the features, through one weighted sum, to the answer, in a single pass with no loop, the design is called a feedforward network.

Training reuses the recipe from Part 2: show the machine a message with a known answer; when it says spam 0.95 for a real message from your friend, the mistake is large, so every weight gets nudged in the direction that shrinks it. After enough messages, the weights settle into values like ours.

Stacking several weighted sums and activation functions in a row, each feeding the next, lets the machine answer subtler questions than any single line can; the stack is still feedforward, and still one pass.

one sum, trained by nudging features (1, 1, 0) Σ answer the mistake travels back and nudges every weight a stack: still one forward pass features Σ Σ Σ Σ out
For the classroom: take the three student questions from earlier and ask which features each filter would need; every proposal is a row in a feature table.

1958: the perceptron

The machine on the last four slides is the original, give or take one detail: Rosenblatt's perceptron answered through a hard yes or no threshold, where ours reads a probability off the curve. In 1958 Frank Rosenblatt, at the Cornell Aeronautical Laboratory, published the perceptron and demonstrated it in simulation on an IBM 704; by 1960 his team had built it as hardware, the Mark I, whose weights were dials turned by electric motors. The press expected miracles.

"The navy revealed the embryo of an electronic computer today that it expects will be able to walk, talk, see, write, reproduce itself and be conscious of its existence"
The New York Times, July 1958, reporting a Navy demonstration of Rosenblatt's perceptron, simulated on an IBM 704.

In 1969, Marvin Minsky and Seymour Papert proved that a single weighted sum can never answer some simple questions, and funding for the whole direction collapsed for a decade. The repair was already known: stack layers. In 1986, David Rumelhart, Geoffrey Hinton, and Ronald Williams published the nudging recipe that trains a whole stack at once; your spam filter and the largest models of 2026 are trained with descendants of that recipe.

Number questions

You: What is 34 plus 33?
The model: 67

Under the hood nothing changed: 67 is one more token in the vocabulary, and the model scored it against every other token, exactly as it scored yes against no.

67 0.62 68 0.09 66 0.07 12 0.03 341 0.02 all others 0.17
Illustrative numbers.
Question for the class: the model sometimes answers 68. Is that better or worse than answering 341, and can the machinery we have so far even ask that question?

Two models, one score

model A 65 66 67 68 69 0.10 0.25 0.30 0.25 0.10 model B 8 9 67 341 0.35 0.15 0.30 0.20
Two models answering the same question, where both give the correct token, 67, a probability of 0.30. Illustrative numbers; each chart sums to 1.
Question for the class: which model would you trust with arithmetic, and could any number from Part 1 tell them apart?
A scorecard blind to nearness

"Track the probability of the correct answer." Both models score 0.30, yet model A stays within 2 of the truth, while model B is usually absurd; because a scorecard over pure symbols carries no notion of nearness, almost right does not exist for it. The counted chains of Part 1 lived entirely in this symbol world.

What if we mapped the token 67 to the number 67?

Attach to each number token the value it names: the token 67 carries the number 67. Nearness finally exists: 68 sits at distance 1 from the truth, while 341 sits at distance 274.

0 25 50 75 100 truth: 67 68 341 distance 1 distance 274

The two models from the last slide can now be told apart with one number each: on average, model A misses the truth by about 0.9, while model B misses it by about 84.

A machine judged by the distance of its number from the truth is doing regression, and the nudging recipe works unchanged, because distance supplies the measured mistake it needs.

For the classroom: students verify model A's average error from the bars: 0.10(2) + 0.25(1) + 0.30(0) + 0.25(1) + 0.10(2) = 0.9.

A second question: how many digits?

Ask one more question about each token: how many digits does it have? The token 67 now carries two numbers, (67, 2): its value, and its digit count. Two numbers place each token as a point in a plane, and every further question would add an axis.

tokens with two digits live in this band 0 50 100 341 1 2 3 value digits 3 7 8 12 67 68 95 341

Neighborhoods now mean something: 67 and 68 sit close on both axes, while 8 and 341 disagree on both.

The token embedding

The list of numbers a model attaches to a token is called the token's embedding. Ours has two slots, with questions we wrote ourselves: value, and digit count. A real model attaches a longer list: the 2019 language model whose tokenizer we met in Part 1, in its smallest version, gives every one of its 50,257 tokens a list of 768 numbers.

tokenslot 1slot 2slot 768
cat0.62−1.130.28
kitten0.58−1.090.31
671.020.44−0.77
681.050.47−0.74

Numbers illustrative; the pattern is the point: similar tokens carry similar rows, and reading a row is a table lookup.

In a real model nobody writes the questions. Because the slots are weights, gradient descent tunes them like every other weight, and the model discovers whichever questions help it predict the next token. Tokens that behave alike end up with similar lists, so they land near each other: cat near kitten, 67 near 68.

For the classroom: say the through line aloud: features answered questions about a message; embedding slots answer questions about a token.

Directions with meaning

In 2013, Tomas Mikolov and colleagues at Google trained token embeddings from raw text and then did arithmetic on the lists themselves. Starting from king, subtracting man, and adding woman lands nearest to queen; starting from Paris, subtracting France, and adding Italy lands nearest to Rome. Nobody programmed those facts; the learned slots turned out to include questions about royalty, gender, and country.

man king woman queen the royalty direction France Paris Italy Rome the capital direction
An illustrative projection of a learned space; the measured result is Mikolov and colleagues, 2013.
For the classroom: invite students to propose their own analogy pair and argue whether the space could support it.

The classroom embedding

For the classroom: eight tokens (cat, kitten, dog, puppy, car, truck, 7, 8) and two questions (how alive is it, from 0 to 1; how large is it, from 0 to 1). Students shout scores; the teacher plots each token as a point. Clusters appear without anyone asking for them, because similar answers place tokens side by side.
how alive is it? (0 to 1) how large is it? (0 to 1) 0 1 0 1 cat kitten dog puppy car truck 7 8 the pets end up side by side
The expected outcome, drawn ahead of class; scores are illustrative.
Question for the class: which third question would separate cat from kitten?

The reassembled pipeline

Read the whole machine from Part 2 again, with today's parts in place. Tokens enter and become rows of the embedding table. The middle, which reads the whole window through attention, stays a gray box until Part 9. At the far end a feedforward readout, built from the same weighted sums as your spam filter, gives every token a score, and the softmax, the sigmoid's sibling for many answers, maps the scores to the familiar bars.

the cat sat embedding table one row per token attention layers Part 9 feedforward readout token IDs in bars out
When the question is fixed and two answers remain, this same pipeline is your classifier. You built both ends today; only the middle remains.

Check for understanding

1. A filter scores a message at exactly 0. What probability does it report, and what does the bias contribute before any feature speaks?

One half; the bias sets where the machine stands before it reads anything, so it is the filter's starting lean.

2. Two models both give the correct token a probability of 0.30. What extra structure lets you prefer one, and which mapping created it?

Distance between answers, created by mapping each number token to the value it names.

3. In a real embedding, who writes the questions the slots answer?

Nobody; because the slots are weights, gradient descent tunes them until useful questions emerge.

For the classroom: reveal each answer only after the class commits; the three questions map to the three ideas of this unit.

Part 3 Overview

  1. Classifiers: an LLM with its answers frozen to a fixed set is a classifier, and two answers make the smallest interesting game.
  2. Feedforward: features times weights, plus a bias, mapped to a probability by the sigmoid; trained by nudging; born in 1958 as the perceptron.
  3. The missing distance: because symbols and counts carry no notion of nearness, almost right does not exist for them.
  4. Embeddings: attach a list of numbers to each token, where each slot answers a question; real models learn hundreds of slots, and similar tokens become neighbors.

Part 4 measures the mistake and traces it backward: loss functions and backpropagation.

Sources and further reading

  • F. Rosenblatt, 1958: the perceptron, published from the Cornell Aeronautical Laboratory; the Mark I hardware followed in 1960.
  • The New York Times, July 1958: the Navy demonstration report quoted here.
  • M. Minsky and S. Papert, 1969: Perceptrons; the limits of a single weighted sum.
  • D. Rumelhart, G. Hinton, and R. Williams, 1986: the backpropagation paper; training stacked layers, and learned internal representations.
  • T. Mikolov and colleagues, 2013: the word2vec papers; embedding arithmetic, king to queen and Paris to Rome.
  • A. Radford and colleagues, 2019: Language Models are Unsupervised Multitask Learners; 50,257 tokens, each carrying 768 numbers in the smallest model.

Slides: Mehmet Kerem Turkcan, Center for Smart Streetscapes, Columbia University; keremturkcan.com; mkt2126@columbia.edu

Intro to AI, Part 3: Classifiers and EmbeddingsM. K. Turkcan, Columbia University