Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Part VII — AI Practice Labs

Six guided labs. Each pairs a chapter here with a runnable Livebook in the livebooks/ collection. The examples are all new — a solar-farm tracker, an iris botanist, tangled spirals, wardrobe vision, a tiny text generator, and a support-desk search engine — chosen so every lab teaches a distinct invariant instead of re-walking the chapters.

LabTitleLivebookPairs WithInvariant it teaches
LAB 1Nx Optimization: Tilting Solar PanelsLAB1_nx_tilt_optimizer.livemdCh 17, 18defn + autodiff: you supply the forward definition, grad/2 supplies the derivative
LAB 2Classical ML with ScholarLAB2_scholar_iris.livemdCh 17, 13when not to reach for Axon — a tabular model is Scholar.Linear, not a neural net
LAB 3Axon: Untangling the Two SpiralsLAB3_axon_spiral.livemdCh 19the loop is a reduction over a stream; run/4 returns an %Axon.ModelState{}
LAB 4CNN on Fashion-MNISTLAB4_cnn_fashion_mnist.livemdCh 19, 21shape arithmetic is the design work — you can read the table fluently
LAB 5Character-Level LSTMLAB5_char_lstm.livemdCh 19, 20batching and dtype discipline: one short batch means a recompile
LAB 6Bumblebee Semantic SearchLAB6_bumblebee_semantic_search.livemdCh 20, 28rank fusion beats score fusion; retrieval quality is decided by chunking

Open Livebook from the repository root and each LAB*.livemd runs top to bottom. The runnable files are bundled in this directory’s livebooks/ folder.

Running the Labs

Each lab starts with its own Mix.install/1 cell, so Livebook handles dependency resolution per notebook — you do not need a mix.exs. That cell is also the reason every lab must be run from the top: nothing below it has its dependencies until it evaluates.

Requirements:

  • Elixir 1.20+ on OTP 27+
  • Livebook 0.14+ (livebook server from the repo root, then open a lab)
  • Disk: 1GB for deps and model caches; LAB6 additionally downloads embedding models (~130MB for E5, more if you swap in a larger one)
  • RAM: 4GB minimum. EXLA compiles on first use and wants a core per scheduler; 8GB is comfortable.

Expect roughly:

LabWall clock (first run)Notes
LAB12–4 mindep compile dominates; the rest is instant
LAB23–5 min
LAB33–6 mintrains on CPU in under a minute once compiled
LAB45–10 minthe longest; convolution is slower on CPU
LAB53–8 mincorpus download at the start
LAB64–8 minmodel download dominates

No GPU? Everything runs on Nx.BinaryBackend — drop the {:exla, ...} line from Mix.install and the labs still work, just slower. EXLA on laptop CPU is the default expectation, not a GPU.

Stale pins are the most common failure. If a dep resolves to something that does not exist, or a signature changed, Livebook caches the build: restart the notebook and clear the cache (File.rm_rf!(".livemd-cache") or Livebook’s “Restart and clear cache”). Library versions across these labs match Part IV: nx ~> 0.13, exla ~> 0.13, axon ~> 0.8, bumblebee ~> 0.7, scholar ~> 0.4, kino ~> 0.14.

A Note on Hardware Claims

Every lab prints timings. On a laptop CPU those numbers are honest for CPU and meaningless for GPU — do not quote a CPU figure as an accelerator result. The measurement discipline (pin shapes, warm up, compare backends on equal footing) is the transferable part; the absolute numbers are not. Ch 18 §18.8 explains what makes a backend comparison fair.