# Mac exercise for mission 3.1: Counting tokens with Ollama

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

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

In the mission you used the tokenizer in the browser. Here the model counts on its own: after every request, Ollama reports how many tokens the prompt had.

**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

qwen3:1.7b is 1.4 GB and runs on any Mac with Apple Silicon. It works with 8 GB too.

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

**At the end it says**

```
success
```

### 2. Have a sentence counted

`"raw": true` sends the text without a chat template, `num_predict 1` generates just one token. What gets counted is the prompt. Type your sentence into the field below, and it already appears here in the command. The example sentence is the German one from the measurement: „Wir bieten Ihnen eine kostenlose Rückgabe innerhalb von 30 Tagen.“ (We offer you free returns within 30 days.)

```
curl -s http://localhost:11434/api/generate -d '{"model": "qwen3:1.7b", "prompt": "Wir bieten Ihnen eine kostenlose Rückgabe innerhalb von 30 Tagen.", "raw": true, "stream": false, "options": {"num_predict": 1}}' | python3 -c 'import json, sys; print(json.load(sys.stdin)["prompt_eval_count"], "Tokens")'
```

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

```
16 Tokens
```

The same request with “We offer free returns within 30 days.” gave 10 tokens.

### 3. Let the page check the output

The check needs JavaScript. Without it: compare the number with the tokenizer in the mission.

The page counts your sentence with the same Qwen3 tokenizer in the browser and compares. If both match, you know that Ollama and the browser use the same vocabulary.

### 4. Clean up

Keep the model if you’re still going to do the exercises for 3.2 and 3.3. Otherwise:

```
ollama rm qwen3:1.7b
```

On the DGX Spark, the same works with llama.cpp; see the exercise in [chapter 3](https://llm.yoga/en/03-tokens-3.md).
