Linear Algebra

Layer 1 · Intuition

Linear Algebra

Why every model — from a linear regression to GPT-4 — is fundamentally a pile of vectors and matrices being multiplied together.

5 min read40 XP

A matrix multiply is the single most common operation inside a neural network.

Strip away the hype and every neural network layer does the same thing: it takes a list of numbers (a vector), multiplies it by a grid of learned numbers (a matrix), and produces a new list of numbers. Stack enough of these transformations and you get a language model.

The vocabulary you actually need

  • Scalar: a single number, like a temperature reading.
  • Vector: an ordered list of numbers — a word embedding, an RGB pixel, a model's hidden state.
  • Matrix: a grid of numbers — a layer's learned weights, or a batch of vectors stacked together.
  • Tensor: the generalization to any number of dimensions — what PyTorch actually stores everything as.

Two vectors being 'similar' — the entire basis of search, recommendation, and attention — is measured by the dot product: multiply corresponding entries and sum them. Vectors that point in a similar direction get a large dot product; unrelated ones get close to zero.

Check your understanding

4 questions · answer all to submit

  1. 1.Which statement accurately defines a matrix?

  2. 2.Which vector operation quantifies the directional alignment between two vectors?

  3. 3.In the PyTorch framework, what primary data structure encompasses inputs, model parameters, and activation values?

  4. 4.How is a 4096-dimensional word embedding best conceptualized in a technical context?