Notebooks

One notebook per section, plus take-home deep dives, each runnable cold in Colab

Every section of the workshop has a notebook. Additional notebooks offer take-home deep dives. They are English-primary, and every heading carries a one-line Spanish summary — cada encabezado lleva un resumen en español.

How they are built

Notebooks 01–11 separate the live session from later study:

  1. Header: Practise today and Explore later, with the same outcomes as the slides and handbook.
  2. Run the Setup cell first, then work straight down. Each notebook opens with a short route to follow: a quick recall, a worked example, then your own attempt, feedback, and a checkpoint. Try the exercise yourself before opening the folded solution.
  3. Core complete: the route above ends here. Keep your explanation — that is what the session needs — and follow the facilitator’s quiz and break schedule.
  4. Explore later: optional material you come back to afterward — more reference, exercises, and explorers.

Notebook 00 keeps the entry check and pre-work setup; 12 starts with the exit check. The deep dives are listed under Going further below. Solutions remain folded: open them after an attempt. Each notebook loads its own data and runs independently.

The notebooks are committed with no outputs and no execution counts. Every number you see is one you produced. The prose quotes the expected results, so you can tell whether yours are right. If yours differ, that is worth investigating rather than dismissing.

The notebooks

# Open Notebook Covers
00 Open In Colab 00-setup-and-data.ipynb Setup and welcome — Load every dataset and confirm your runtime works before the workshop starts.
01 Open In Colab 01-what-a-tensor-is.ipynb What a tensor is — Learn to read a tensor’s structure and track what its axes mean as you fix, rearrange, or contract them.
02 Open In Colab 02-thinking-in-n-dimensions.ipynb Thinking in N dimensions — Learn to read real tensors by asking what every axis counts and why a batch axis is not the same thing as a time axis.
03 Open In Colab 03-indexing-and-broadcasting.ipynb Indexing and broadcasting real data — Select named measurements from real tumour-sample data, compare meaningful subsets, then standardize real image data safely.
04 Open In Colab 04-reshape-and-transpose.ipynb Reshape and transpose real images — Use real images to move between HWC↔︎CHW and NHWC↔︎NCHW, then show why matching shapes do not guarantee matching axis semantics.
05 Open In Colab 05-video-pipeline-design.ipynb Video pipeline design — Process one pinned real video end to end, then use what its axes actually mean to design two downstream video pipelines.
06 Open In Colab 06-contraction-with-einsum.ipynb Contraction with einsum — Use one index rule on real data, then change the inputs interactively to test which index disappears.
07 Open In Colab 07-inverses-and-pseudoinverse.ipynb Inverses and the pseudoinverse — Use the pseudoinverse on real singular, tall, and wide systems, then inspect the geometry interactively.
08 Open In Colab 08-recursion-with-matrices.ipynb Recursion with matrices and vectors — Treat recursion as repeated state updates, connect repeated multiplication with dominant eigen-directions, and test recursive forecasting on real airline-passenger data.
09 Open In Colab 09-matrix-factorizations.ipynb Matrix factorizations — Put LU, QR, Cholesky, eigendecomposition, SVD and NMF side by side on real data and see which question each one answers, and what each one costs.
10 Open In Colab 10-tucker-decomposition.ipynb Tucker decomposition on real data — Build a real tensor from New York taxi trips, compress each mode with HOSVD, and explore the trade-off between size, reconstruction error, and interpretable structure.
11 Open In Colab 11-tensor-factorizations.ipynb Tensor factorizations — Compare CP, Tucker/HOSVD, Tensor Train and t-SVD, understand the structure each one preserves, and measure what each representation costs.
12 Open In Colab 12-wrap-up-and-take-homes.ipynb Wrap-up and take-homes — Wrap up the workshop around one connecting idea, then choose among five extensions: PCA, attention, CP, Cholesky, and audio.

Going further

These are not sections. They are deep dives, handed out as take-home material. They have no slides, no Kahoot, and no minutes on the workshop clock: the 210-minute agenda is exactly what it was without them. Section 11’s live core compares CP and Tucker using library calls; its four-model overview is extension material. Notebooks 14 and 15 build on that comparison by fitting CP by hand and then changing what “fit” means.

# Open Deep dive
13 Open In Colab 13-convolution-and-deconvolution.ipynb — Convolution and deconvolution — Treat convolution as a structured linear operator, separate it from correlation, understand transposed convolution, and partially recover a real blurred image.
14 Open In Colab 14-cp-factorization.ipynb — CP factorization and the rank-1 view — Read a CP component as one vector per axis, fit it by alternating least squares, constrain it to be non-negative, and watch real neural recordings sort themselves by a label the method never saw.
15 Open In Colab 15-generalized-cp.ipynb — Generalized CP for counts and binary data — Squared error is a modelling assumption, not a definition of fit. Swap it for a Poisson or Bernoulli loss, decompose a real tensor of crime counts — including one component that turns out to be an artifact of the file — then hand the same objective to PyTorch and watch what momentum does to it.
16 Open In Colab 16-pca-from-tensors.ipynb — PCA from a tensors perspective — Connect covariance, correlation, eigendecomposition and SVD on real satellite patches; evaluate classification and clustering, then fit multilinear PCA and recover a synthetic tensor signal.
17 Open In Colab 17-multi-head-attention.ipynb — 4D multi-head attention: reshape Q, K and V — Split projected features into heads, verify strides and token identity, compute scaled dot-product attention, and compare NumPy with PyTorch.
18 Open In Colab 18-feature-compression.ipynb — Latent feature compression with SVD — Compress an HWC image with truncated SVD, compare ranks and energy retention, test reconstruction against PyTorch, and distinguish matrix rank from CP rank.
19 Open In Colab 19-cp-or-tucker-in-practice.ipynb — CP or Tucker in practice — Take CP and Tucker to a real knowledge graph, a trained ResNet-18 kernel and a photograph: see which core can express an asymmetric relation, which stores a kernel in fewer numbers and at what hidden price, how to choose the rank, and why the model that compresses best does not predict best.

Deep dive 19 works through the ML blog post CP or Tucker in practice.

The browser widgets beside the sections have a page of their own: Interactive gives each one a card, with the sections it belongs to and the scenes worth opening directly.

Running them somewhere other than Colab

The notebooks only need the scientific Python stack. Locally:

git clone https://github.com/project-delphi/tensors-workshop.git
cd tensors-workshop
uv run --group notebooks jupyter lab

The notebooks group is declared in pyproject.toml, and it is read off the notebooks’ own imports rather than written down beside them. matplotlib and ipywidgets are in it because the notebooks use plots and interactive widgets. Both ship with Colab, so a missing one only shows up when you run locally.

scikit-learn and scikit-image ship the tumour data, the handwritten digits and the photographs. Some notebooks use only bundled data; others download data or install packages. The generated table below lists each notebook’s network requirements.

What each notebook needs

Colab already has every one of these installed.
Notebook Beyond NumPy Network
00 matplotlib, ipywidgets, pandas, scikit-learn, scikit-image, scipy, pillow, imageio† yes — California housing, airline passengers, NYC taxi trips, the storm clip (only a 1 KB probe)
01 matplotlib, ipywidgets, scikit-learn, scikit-image, pillow no
02 matplotlib, ipywidgets, scikit-learn, scikit-image, pillow, imageio† yes — the storm clip
03 matplotlib, ipywidgets, pandas, scikit-learn, pillow no
04 matplotlib, ipywidgets, scikit-image, pillow no
05 matplotlib, ipywidgets, pillow, imageio† yes — the storm clip
06 matplotlib, ipywidgets, scikit-learn, scikit-image, pillow no
07 matplotlib, ipywidgets, pandas, scikit-learn, pillow yes — California housing
08 matplotlib, ipywidgets, pandas, pillow yes — airline passengers
09 matplotlib, ipywidgets, pandas, scikit-learn, scikit-image, scipy, pillow yes — airline passengers
10 matplotlib, ipywidgets, pandas, pillow yes — NYC taxi trips
11 matplotlib, ipywidgets, pandas, pillow, tensorly†, imageio† yes — NYC taxi trips, the storm clip
12 matplotlib, ipywidgets, pandas, scikit-learn, scipy, pillow yes — a voice recording (for take-home E)
13 matplotlib, ipywidgets, scikit-image, scipy, pillow no
14 matplotlib, ipywidgets, scipy, pillow, tensorly† yes — the monkey BMI recordings (5 MB, once)
15 matplotlib, ipywidgets, pandas, scipy, pillow, pyttb†, torch† yes — Chicago crime reports (3 MB, once)
16 matplotlib, ipywidgets, pandas, scikit-learn, pillow yes — UCI Landsat satellite patches (101 KB archive, cached)
17 matplotlib, ipywidgets, torch no
18 matplotlib, ipywidgets, torch no
19 matplotlib, ipywidgets, pandas, scikit-image, scipy, tensorly†, torch yes — the FB15k-237 knowledge graph (21 MB, once), a ResNet-18 kernel and cached fits

† Installed by the notebook itself with %pip install -q, which is why neither is in the command above.