Tensors for Machine Learning
  • Home
  • Inicio
  • Handbook
  • Manual
  • Notebooks
  • Cuadernos
  • Interactive
  • Interactivo
  • Kahoot
  • Kahoot
  • References
  • Referencias
  • Slides
  • Diapositivas
  • Companion
  • Complemento
  • Teach
  • Enseñar
  • FAQ
  • FAQ
  • 🇬🇧 EN
  • 🇪🇸 ES

Interactive

No install and no account. Each of these runs in your browser, in English or Spanish, and answers a question the pages can only describe: move a control and the shapes, the strides and the numbers move with it. Every one is also linked from the section it belongs to, in the handbook and in the notebooks.

🧮 Broadcasting simulator

Type two shapes. Watch NumPy line them up from the right, pad the short one, and stretch every axis of size 1 — or refuse, and say which axis. Section 03.

Try shapes

🧊 The image tensor

Three real photos as one 4-D tensor, a cube per byte, up to 128 × 128. Transpose it and watch the cubes follow the new shape while not one byte of the buffer moves; reshape it and watch the picture break; rewrite the buffer C, Fortran or channels_last and watch only the memory move. Every click prints the NumPy and PyTorch that does it. Section 04.

Straight to transpose, reshape or the memory layout.

Open the image tensor

👁️ Attention, from words to weights

One four-word sentence, “I know you know”, followed through a single attention head with every number small enough to add up by hand: the words cut into tokens, the tokens coded as ids, the ids fetching rows of an embedding table, those rows projected into queries, keys and values, the scores, why they are divided by √d_k, softmax turning them into weights that sum to one, and the weighted average that is the output. Then more heads, and the batch a real model is handed. Every picture carries the NumPy that computes it. Sections 04 and 06, and Appendix B.

Straight to why √d_k, the scores, softmax or every head gets its own axis.

Open the attention stage

📐 Projection & SVD stage

Least squares is a projection: scroll, and watch a target vector’s shadow land on the plane its predictors span, with the residual meeting it at a right angle. Then the SVD portal, where a unit circle becomes an ellipse and A v = σ u stops being notation, and on to the eigenvectors, two nearly collinear columns and float32 dividing by exactly zero. One problem, sections 07, 08 and 09.

Straight to the SVD portal, the eigenvectors or float32 dividing by zero.

Open the projection & SVD stage

🎙️ The audio tensor

Air becomes numbers: 48 000 a second, each rounded to 16 bits, written down as an array you can listen to. Then one window is cut out of it, the transform is asked which frequencies are in that window, and the window hops along to build a frequency-by-time matrix, 513 × 465 — and you can hear what a transpose does to it. It ends on the rank-4 batch a model is handed, three recordings stacked. Sections 00, 02, 04 and 09, and Appendix E.

Straight to one window, the transform, the best rank-k there is or the batch.

Open the audio tensor

🚕 Tucker and CP

One real tensor, factorised two ways: 6,383 New York taxi trips, pickup borough by dropoff borough by hour of day, as a cube of voxels you can turn and click — three quarters of it one Manhattan route. Watch the cube lay itself flat into each unfolding, see what the SVD of one finds, and reassemble a small core plus three factor matrices: 480 numbers down to 102, at 6.7% error, one core entry carrying 99% of the fit. Then build the best rank-1 term there is, see what several of them look like, play alternating least squares one solve at a time from five starts that do not all agree, and spend one parameter budget both ways. Sections 10 and 11, and Appendix C.

Straight to the cube laid flat, the core and its three factors, one rank-1 term, ALS, solve by solve or the same budget spent two ways.

Open Tucker and CP

🧬 DNA to an edit

A gene is a string over a four-letter alphabet, which is already a tensor: 180 bases of a real cas12a gene become a 180 × 4 grid of ones and zeros, one 1 per row. Follow that one stretch through everything a cell does with it. A sliding window cuts 161 views out of it without copying a base. An enzyme reads one strand and the RNA comes out reading like the other, because transcription is a 4 × 4 matrix and two complements undo each other. A codon is three one-hot vectors multiplied together, the genetic code is a 4 × 4 × 4, and translation is one contraction between them — where swapping a codon’s third base is the page’s first edit, and often changes nothing. Sixty residues land on 18 points of a property map; the whole protein, as AlphaFold predicts it, is a (1300, 3) array whose distances are one broadcast; and checking a guide against every window of the sequence is one einsum — 161 windows, one perfect match, the runner-up at 12 of 20. Under every picture is the gene itself, with the stretch that picture is looking at lit. It shows what the arithmetic is; it is not a tool for designing anything. Sections 04 and 06, and Appendix G.

Straight to transcription as a matrix, the genetic code as a 4 × 4 × 4, translation as one contraction, the fold and its grid of distances or the search as one einsum.

Open DNA to an edit

♟️ AlphaTensor: from a rule to a game

Multiplying two 2 × 2 matrices takes eight multiplications, and eight looks like a fact about the problem. It is not. Write the rule down as a list of its eight products, put a 1 at each one, and the rule is a 4 × 4 × 4 cube of zeros and ones that multiplies matrices with one einsum. Split that cube into blocks that each cost one multiplication and you have an algorithm: add Strassen’s seven blocks one at a time and the count of wrong cells goes up, from 8 to 12, before it falls to zero, because the blocks overshoot and cancel. Run the seven on numbers, then on the quarters of a matrix, and one saved multiplication becomes 73.7% of them at 1,024 × 1,024. Then turn it round: start from the cube and subtract blocks until nothing is left. That is the game AlphaTensor plays. With five allowed coefficients a single move has 244,140,625 choices; of the 128,000 different moves left with three, 8 look like progress and Strassen’s is not one of them; and a player who always takes the best-looking move finds eight, never seven. The last picture is the record board, where 3 × 3 is still open between 19 and 23. Under every picture is the cube laid flat, showing what that picture does to it. The page plays the game; it does not run or train a network, and AlphaTensor’s own results are quoted from the paper. Sections 06 and 11, and deep dive 20.

Straight to the rule as a cube, the product as one einsum, Strassen’s seven blocks, the game or why greedy finds eight.

Open AlphaTensor

Tensors for Machine Learning · Built with Quarto

 

Source