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.
| Lab | Title | Livebook | Pairs With | Invariant it teaches |
|---|---|---|---|---|
| LAB 1 | Nx Optimization: Tilting Solar Panels | LAB1_nx_tilt_optimizer.livemd | Ch 17, 18 | defn + autodiff: you supply the forward definition, grad/2 supplies the derivative |
| LAB 2 | Classical ML with Scholar | LAB2_scholar_iris.livemd | Ch 17, 13 | when not to reach for Axon — a tabular model is Scholar.Linear, not a neural net |
| LAB 3 | Axon: Untangling the Two Spirals | LAB3_axon_spiral.livemd | Ch 19 | the loop is a reduction over a stream; run/4 returns an %Axon.ModelState{} |
| LAB 4 | CNN on Fashion-MNIST | LAB4_cnn_fashion_mnist.livemd | Ch 19, 21 | shape arithmetic is the design work — you can read the table fluently |
| LAB 5 | Character-Level LSTM | LAB5_char_lstm.livemd | Ch 19, 20 | batching and dtype discipline: one short batch means a recompile |
| LAB 6 | Bumblebee Semantic Search | LAB6_bumblebee_semantic_search.livemd | Ch 20, 28 | rank 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 serverfrom 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:
| Lab | Wall clock (first run) | Notes |
|---|---|---|
| LAB1 | 2–4 min | dep compile dominates; the rest is instant |
| LAB2 | 3–5 min | |
| LAB3 | 3–6 min | trains on CPU in under a minute once compiled |
| LAB4 | 5–10 min | the longest; convolution is slower on CPU |
| LAB5 | 3–8 min | corpus download at the start |
| LAB6 | 4–8 min | model 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.