# Mac exercise for mission 3.2: Watching the model guess

Part of the course “AI from Zero to Autonomous Agents” (https://llm.yoga/en). Page for humans: https://llm.yoga/en/mac-3-2

About 15 minutes at your computer · Type this address: **llm.yoga/en/mac-3-2**

You ask the model for the five most likely next tokens, convert logprobs into percent and watch what temperature and seed do to the text. Every step is a ready-made command. The prompt is the German „Der Himmel ist“ (the sky is), as in the measurement.

**Before you start**

You need **Ollama** and Python 3 in the terminal. Ollama comes as an app: download it from ollama.com/download and drag it into your Applications folder. On first launch, the app asks permission, if needed, to set up the `ollama` terminal command. It requires macOS 14 or newer. More on this in [chapter 10](https://llm.yoga/en/10-lokale-modelle-4.md). Check:

```
ollama --version
```

Python 3 may need to be installed. On the first `python3` call, macOS may offer to install developer tools; alternatively, Python is available from python.org.

### 1. Load a small model

```
ollama pull qwen3:1.7b
```

### 2. The five most likely next tokens

`raw` turns off the chat template, `num_predict 1` generates exactly one token, `top_logprobs 5` returns the five best candidates. The Python part converts each logprob to percent with e to the power of the logprob.

```
curl -s http://localhost:11434/api/generate -d '{
  "model": "qwen3:1.7b", "prompt": "Der Himmel ist",
  "raw": true, "stream": false,
  "logprobs": true, "top_logprobs": 5,
  "options": { "num_predict": 1, "temperature": 0 } }' \
| python3 -c '
import json, sys, math
d = json.load(sys.stdin)
for x in d["logprobs"][0]["top_logprobs"]:
  print(repr(x["token"]), round(x["logprob"], 3),
        round(math.exp(x["logprob"]) * 100, 1), "%")'
```

**Output (Measured on an M4 Mac (24 GB) on November 24, 2026)**

```
' das' -0.951 38.6 %
' gra' -1.731 17.7 %
' hell' -2.007 13.4 %
' bl' -2.74 6.5 %
' ein' -3.556 2.9 %
```

### 3. Temperature and seed

Now without logprobs: the model writes six tokens, and the Python part only shows the text. Change the numbers after `temperature` (0, 0.7, 1.5) and `seed` (42, 43).

```
curl -s http://localhost:11434/api/generate -d '{"model": "qwen3:1.7b", "prompt": "Der Himmel ist", "raw": true, "stream": false, "options": {"num_predict": 6, "temperature": 0.7, "seed": 42}}' | python3 -c 'import json, sys; print(repr(json.load(sys.stdin)["response"]))'
```

**Outputs (Measured on an M4 Mac (24 GB) on November 24, 2026)**

```
T=0   seed=42: ' das Reich des Herrn,'
T=0   seed=43: ' das Reich des Herrn,'
T=0.7 seed=42: ' hell, das Licht ist hell'
T=0.7 seed=43: ' das Reich des Herrn,'
T=1.5 seed=42: ' die größte Freude,'
T=1.5 seed=43: ' hell, und die Sonne'
```

If you just delete the line with `logprobs` from the command in step 2, you get `KeyError: 'logprobs'`, because the Python part looks for it. That’s why this step has its own command.

### 4. Same seed, same text?

Run the command from step 3 twice with temperature 0.7 and seed 42, and paste both outputs, one per line.

For me, exactly „ hell, das Licht ist hell“ (bright, the light is bright) came out both times. The same seed, the same settings and the same computer give the same text locally.

### 5. Clean up

```
ollama stop qwen3:1.7b
```

Delete it only after the exercises for 3.3 and 9.x: `ollama rm qwen3:1.7b`.

With 8 GB everything works the same way. On the DGX Spark: llama-server with `n_probs`, see [chapter 3](https://llm.yoga/en/03-tokens-3.md).
