FixTheRobot Explore Robotics / Robot Learning / M2 / M2-L2

This lab works on phones, but writing code is much easier on a laptop.

Robot Learning · Supervised Learning for Robots · M2-L2 · Intermediate

Train a Tiny Neural Network

Experiment log · Scout at Meridian General Hospital

Experiment log, Meridian General Hospital, 14:05. The linear steering model works in the straight ward corridor and wanders in the curved wing: the true command saturates near the centre line and eases off towards the walls, and no straight line through the logs follows that. The team wants the smallest network that does.

You will write the two functions every network library hides, the forward pass and the backward pass, and check the second against finite differences, the debugging tool people actually use. Then you will train a network in the browser on the curved-corridor logs and choose its size, learning rate and training length yourself.

Your task

    Simulation
    solution.pyLoading Python…
    Ctrl+Enter runs
    What Python can I use?

    Plain Python with math and heapq. Your code runs in a background worker: an endless loop is stopped after a few seconds and the page stays usable. It runs in your browser and is never sent anywhere.

    Hints

    What this lab teaches

    Stage 1 is the forward pass of a network with one tanh hidden layer and a linear output, graded on hidden weights and inputs, and the feedback names the usual slips (no nonlinearity, a missing bias, a tanh on the output). Stage 2 is the backward pass for a single sample: the gradient of the squared error with respect to all four parameter blocks. It is graded against the exact analytic gradient and against central finite differences of the loss, and the message says which block is wrong, because an error in the middle of the chain leaves the layers after it correct and the ones before it wrong.

    Stage 3 has no code. The simulator trains a one-input network by full-batch gradient descent, and you choose the number of hidden units, the learning rate and the number of epochs, watching the fitted curve and the training and validation loss. It teaches the three things that must be right together: capacity, a stable step size and enough training time. Two questions ask why one unit cannot fit the curve and why a large learning rate diverges.

    Theory for this lab

    Supervised Learning for Robots labs

    1. M2-L1: Fit Steering with Gradient Descent
    2. M2-L2: Train a Tiny Neural Network: this lab.
    3. M2-L3: Catch the Overfit Model

    Educational simplification: the networks are tiny (at most five hidden units in the code stages and twelve in the experiment), the experiment has one input and a made-up smooth steering curve with Gaussian noise, and training is full-batch gradient descent from a seeded random start with no minibatches, momentum or weight decay. Real steering networks have many inputs and are trained with minibatches and adaptive optimisers; the forward and backward passes are the same idea at larger size (lesson M2-T4).

    Get the next lab

    Get notified when new robotics labs are released. One email per new lab, nothing else.