Foundations
Vectors, matrices, and dot products
Vectors hold state, matrices are learned maps, and dot products score alignment; inside Qwen3.8-27B one token's state at one layer is a vector of 5120 numbers.
Updated
01 · Concept
Concept
Open the configuration file that ships with Qwen3.8-27B and one entry appears more often than any other in this course: the hidden size is 5120. Everything in the next several tracks is a consequence of that number, so it is worth knowing exactly what it means before meeting any terminology. It means that inside the model, at every one of its 64 layers, each token of your prompt is represented by a list of 5120 numbers. Not a word, not a symbol, not a lookup key. Five thousand one hundred and twenty floating-point values. The lesson’s job is to make that object ordinary.
A vector is an ordered list of numbers, and order is part of its identity: is not . In geometry a two- or three-dimensional vector draws as an arrow with direction and length. In machine learning it usually has hundreds or thousands of coordinates and represents a token, an image patch, a hidden state, or a gradient. You cannot picture 5120 axes, and you do not need to. Every operation below is defined coordinate by coordinate and behaves the same at any width.
Vectors add component by component and scale by a number. If and , then , and . The Euclidean length is . Magnitude and direction carry different information, and neural networks are constantly reshaping both. A Qwen hidden state is exactly this object with 5120 slots instead of two; in bfloat16 it occupies two bytes per number, which is ten kibibytes for a single token at a single layer.
The dot product collapses two equal-length vectors into one scalar:
For the vectors above, . Each matching pair contributes positive evidence when the signs agree and negative evidence when they oppose. Geometrically, : aligned vectors score positively, perpendicular ones score zero, opposed ones score negatively. This single operation is the atom of everything downstream. Attention scores are dot products between queries and keys. A logit is a dot product between a hidden state and one row of the output matrix. When lesson 0.1 said the model produces 248,320 scores, it meant it performs 248,320 dot products, each against a 5120-dimensional state.
Now a wrong turn worth taking on purpose. Suppose you are comparing two token representations and one pair scores 340 while another scores 12. It is tempting to conclude the first pair is far more related. Work it out instead. Let and : their dot product is , though the angle between them is 45 degrees. Let and : their dot product is , and the angle is exactly zero, perfect alignment. The large score came from length, not agreement. Cosine similarity repairs this by dividing the lengths out, , giving for the first pair and for the second. Embedding comparisons in lesson 1.5 usually want cosine; attention deliberately keeps the raw scaled dot product, because there magnitude is part of the learned computation rather than a nuisance.
A matrix is a rectangular array of numbers, written rows by columns. A matrix maps a four-component input to a three-component output, and each output coordinate is the dot product of one matrix row with the input. That is why matrix-vector multiplication is the workhorse: it computes many learned weighted questions about the same input at once. Inside our specimen, the projection that produces attention queries takes the 5120-dimensional state and emits a 12288-dimensional one — 24 heads of 256 dimensions each, and then the same again for a gate that rides beside them. That mismatch is a real property of the model and not a typo, and lesson 4.2 explains why the temptation to round it back to 5120 wrecks the arithmetic.
Shapes function as a type system. An matrix times an -vector yields an -vector, and the inner dimensions must agree. For batched data, rows usually index examples or token positions, so a matrix of shape sequence-by-features multiplies a weight matrix of shape features-by-output. Writing the shapes beside the equation catches most bugs before the code runs, and it is the single habit that most reliably separates people who can read model code from people who cannot.
The bridge to the rest of the course is now short. An embedding lookup returns a 5120-dimensional vector for a token identifier. Projection matrices turn that state into queries, keys, values, or vocabulary logits. Query-key dot products create attention scores. Gradients are vectors pointing toward local change in the loss. Once vectors are states, matrices are learned maps, and dot products are weighted alignment, most of a Transformer reads as linear algebra with a few carefully placed nonlinear interruptions.
02 · Analogy
Analogy
A sound engineer describes every recording with a row of faders: bass, low-mid, high-mid, presence, air. The fader positions are a vector. A listener's taste is another vector over the same faders. Their dot product is a compatibility score, large when strong recording features meet strong preferences and negative when they oppose. A matrix is the whole mixing console: it takes one row of faders and produces a different row. Qwen3.8-27B has a console with 5120 faders, and no one labelled any of them.
03 · Teach it back
Teach it back
Say what a vector, a matrix, and a dot product each are, then describe what the number 5120 means inside Qwen3.8-27B.
Compare with a model answer
A vector is an ordered list of numbers representing one state. A matrix is a rectangular array whose multiplication defines a linear map from one coordinate space to another. A dot product multiplies matching components and sums them into a single scalar measuring aligned, weighted evidence. In Qwen3.8-27B the hidden size is 5120, meaning that at each of the 64 layers, each token in the sequence is represented by a vector of 5120 numbers. That vector is the token's entire state at that depth: everything the model has worked out about that position so far has to be encoded in those 5120 coordinates, and the layer's job is to produce a better version of it.
04 · Check your understanding
Check your understanding
Complete the teach-back and answer the quiz correctly to finish this lesson.
◎ · Evidence marker
Sources
- Ian Goodfellow, Yoshua Bengio, and Aaron Courville (2016). Deep Learning.
- Qwen Team (2026). Qwen3.8-27B Model Card.