Machine Learning Fundamentals · free preview

Vectorization and Inference

A training loop written with whole-array operations runs orders of magnitude faster than the same loop over indices, and once parameters are fixed the model scores new examples in one pass.

1. The cost of the loop

The cost of the loop

2. What a batched iteration looks like

What a batched iteration looks like

3. After training

After training

4. Why the library call wins

Two implementations add two vectors of length 10,000. One loops over the indices in Python and one calls the array library's addition operator. Both perform the same 10,000 additions. Which statement explains the speed gap?

5. Gradients needed at serving time

A fitted linear model scores a single new example with its recorded parameters w^\hat{\mathbf{w}} and b^\hat{b}. The forward pass is one dot product plus one addition. During this phase, gradients are ____.

Practice this interactively

Free account · instant grading · spaced review that schedules itself.

Start this course for free