You will cut any text into the series' model's tokens, find a token's nearest rows in the model's table by hand, and score a text token by token: each token's surprise in bits, and the text's perplexity.

About 40 minutes. You do it on your own computer. You need your own computer, with uv (free); Windows, Linux or a Mac with Apple silicon, since PyTorch no longer ships for Intel Macs; about 4 GB of free memory; about 2.5 GB of disk, for PyTorch and the series' model, Qwen3.5-0.8B-Base (1.75 GB), which comes from the Hugging Face Hub with no account.

  1. A first runRun it
  2. The piecesYour turn
  3. A token's nearest rowsYour turn
  4. The surprise at each tokenYour turn
  5. Perplexity, two waysYour turn
  6. Two ways to get it wrongRun it
  7. On your own: texts of your ownOn your own
Terminal
curl -LsSf https://astral.sh/uv/install.sh | sh
cd learn-nlp-transformers/labs/nlp-lab-score-text/starter
uv sync

See it on GitHub

When you have run it

After step 5, uv run python score.py prints the series' sentence's perplexity. What is it?

Run on macOS on an M1 Max, uv 0.11.15, Python 3.12, PyTorch 2.15.0, Transformers 5.25.0. Checked on .