FixTheRobot Explore Robotics / LLM / LM1 / LM1-L1

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

LLM · Understanding Large Language Models · LM1-L1 · Beginner

Explore Next-Token Probabilities and Decoding

Ask a language model to finish “the robot picks up the …” twice and you may get two different answers. Ask again with the temperature at zero and you get the same one every time.

You will look inside the simplest possible language model, a table of counts, and implement the two ways of choosing the next word.

Your task

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

    Plain Python with math (and slamkit for small matrix helpers: matmul, transpose, solve, inverse, identity). Images, point clouds and detections arrive as lists inside the dictionary D; an image is a list of rows, each row a list of pixels. There is no NumPy or OpenCV: you write the algorithm yourself, which is the point of the lab. Print with print().

    Hints

    What this lab teaches

    Stage 1 explores a next-word distribution, its entropy and the effect of temperature. Stage 2 computes the distribution from counts. Stage 3 implements greedy decoding and sampling. The “model” is a table of counts on a tiny invented corpus; it is a simulation of the idea, not a neural network, and nothing is trained. Your code is graded on hidden corpora.

    Theory for this lab

    Understanding Large Language Models labs

    1. LM1-L1: Explore Next-Token Probabilities and Decoding: this lab.
    2. LM1-L2: Trace Text to Generated Output

    Educational simplification: words instead of subword tokens, one previous word as the context, a few dozen words of invented text, and pre-drawn random numbers instead of a random generator so that results are reproducible. A real GPT predicts from hundreds or thousands of previous tokens with a neural network. All data in this lab are invented.

    Get the next lab

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