Week 1 — Exercises

Part A — Foundations & calculations

Exercise 1 — Conditional probability from a joint table (calculation)

Given the joint distribution $P(X,Y)$:

$X$ $Y$ $P$
0 0 0.1
0 1 0.2
1 0 0.6
1 1 0.1

Compute the conditional distribution $P(X \mid Y{=}1)$.

Exercise 2 — Build a joint via the chain rule (calculation)

Given the marginal $P(W)$ and the conditional $P(D\mid W)$:

$W$ $P(W)$
sun 0.8
rain 0.2
$P(D\mid W)$ $D=$ wet $D=$ dry
$W=$ sun 0.1 0.9
$W=$ rain 0.7 0.3

Compute the joint table $P(W,D)=P(D\mid W)\,P(W)$.

Exercise 3 — Statistical independence (calculation)

Marginals $P(T)$: hot 0.5, cold 0.5; $P(W)$: sun 0.6, rain 0.4. Joint $P(T,W)$:

$T$ $W$ $P(T,W)$
hot sun 0.4
hot rain 0.1
cold sun 0.2
cold rain 0.3

Are $T$ and $W$ statistically independent? Justify.

Exercise 4 — Chain rule (theory)

  1. Chain Rule: Write $P(W_{1:3})$ for a 3-token sequence as a product of conditional probabilities.
  2. Joint Space Size: How many parameters are needed to store the full, unrepresented joint distribution $P(W_{1:T})$ in a lookup table for a vocabulary $\vert{}V\vert{}$ and length $T$?
  3. The Conditional Bottleneck: Why does the chain rule factorization in (1) fail to solve this exponential memory problem if we try to store the exact conditional probabilities $P(W_t \mid W_{1:t-1})$ in a lookup table? What structural assumption do classical language models use to fix this?

Exercise 5 — The training ladder (conceptual)

Explain what each ladder stage adds, and why only a tool-calling-tuned model can drive an agent loop.

Exercise 6 — Chatbot vs agent, and the three-layers (conceptual)

(a) Classify each as chatbot or agent, and justify:

  • (i) a bot answering FAQs from a fixed text, no actions;
  • (ii) a system that reads your calendar, books a meeting, and emails attendees.

(b) In the three-layer architecture, which layer

  • (i) talks to the messenger,
  • (ii) executes a tool,
  • (iii) calls the LLM?

Part B — Lab: Ollama + the OpenAI client

Install (no root needed). Ollama runs without admin rights — install a user-local binary:

mkdir -p ~/.local
curl -L https://ollama.com/download/ollama-linux-amd64.tgz | tar -xz -C ~/.local
export PATH="$HOME/.local/bin:$PATH"      # add this line to ~/.bashrc

Start the server — each session (lab machines have no auto-start service and no Docker/Podman):

ollama serve &        # local server on 127.0.0.1:11434 — leave it running while you work

Pull a model and test it on the command line:

ollama pull qwen2.5:3b
ollama list                                    # list installed models
ollama run qwen2.5:3b "Say hello in one word." # quick sanity check that Ollama works

Try different models — depending on the machine's free RAM. Smaller = lighter and faster on CPU, but tool calling gets less reliable below ~3B:

free RAM model tool calling
~4 GB llama3.2:1b, qwen2.5:1.5b flaky
~6–8 GB qwen2.5:3b, llama3.2:3b reliable ✅
8+ GB qwen2.5:7b best

Pull a couple and compare speed and answer quality — set MODEL below to whichever you use.

On your own computer you may auto-start Ollama with systemctl --user or Docker/Podman.

In [1]:
# Run me first — defines `client` and `MODEL` used by all lab exercises below.
from openai import OpenAI

client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")  # key is ignored
MODEL = "qwen2.5:3b"   # try "llama3.2:3b", "qwen2.5:1.5b", or "qwen2.5:7b" (RAM permitting)
# MODEL = "qwen2.5:7b" 

Exercise 7 — First API call (lab)

Send a single user message with the Chat Completions API to the model and print its reply.

Exercise 8 — The system prompt (lab)

Send the same user question with the Chat Completions API with two different system prompts and compare the answers. What does the system message control?

Exercise 9 — Statelessness & memory (lab)

Tell the model your name in one request; in a new request ask for it without resending the history. Then repeat with the history. Use the Chat Completions API! Explain what you observe.

Exercise 10 — A structured tool call (preview)

A first look at function calling — the mechanics are Week 2. Here you only advertise a tool and observe the structured request the model emits (you don't invent the schema or run the tool).

Using the tools schema below, ask "What's the weather in Berlin?" and inspect response.choices[0].message.tool_calls — the structured JSON the model emits. Do not execute the tool. Use the Chat Completions API.

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get the current weather for a city.",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    },
}]

Pass tools=tools to client.chat.completions.create(...). (The tool-schema format itself is explained in Week 2 — you're just seeing the output here.)

Part C — Reflection ⚖️

Exercise 11 — Can a language model think critically? (discussion — open question)

Open question. Are language models capable of critical thinking — or do they mainly reproduce majority opinion, including its prejudices? Discuss this in terms of how they generate language: probabilistically, from $P(W_t \mid W_{1:t-1})$.

Work through (a)–(d) and write a ~1 page essay that takes a clear position and states the strongest objection to it.

(a) Start from the maths. The model is fitted by maximum likelihood on a corpus, so $\hat P(W_t \mid W_{1:t-1})$ approximates the distribution of that corpus. If the corpus records many conflicting voices on a contested question, what does the mode of that conditional correspond to — the best-argued position, or the most frequent one? What follows for a minority view that is well argued but rarely written down? (How a system then picks a token from the distribution — greedy vs. sampling, temperature — is Week 2, and W2's Exercise 13 measures it.)

(b) Where could disagreement with the majority come from at all? For each mechanism below, decide whether it produces a genuine evaluation of reasons or only a shift of the distribution:

  1. Conditioning — the prompt or an attached document moves the model into a different region of the distribution.
  2. Preference tuning (SFT/RLHF — the alignment rung of the training ladder) — reshapes the probabilities themselves toward helpful/harmless completions.
  3. Tools & retrieval — evidence from outside the weights (W2, W8).
  4. Decoding knobs — greedy vs. sampling, temperature (W2).

(c) Alignment is not obviously a fix. Preference optimisation rewards answers that raters prefer, and Sharma et al. (2023) find that preference data systematically favours responses matching the user's stated view — sometimes over correct ones (sycophancy). Distinguish two different failures: a model echoing the corpus majority, and a model echoing the person in front of it. Which is more dangerous for an agent that acts (W12), and why?

(d) The counter-position. Bender et al. (2021) argue an LM is a "stochastic parrot" — form without communicative intent. Mahowald et al. (2024) instead separate formal linguistic competence (mastering the rules and statistical regularities of a language) from functional competence (using language rationally in the world: reasoning, world knowledge, situation tracking, social cognition). Sort the ingredients of "critical thinking" — internal consistency, spotting a fallacy, weighing evidence, changing one's mind when the evidence changes — onto that distinction. Then state what would count as evidence that a model did more than repeat patterns: design a concrete test, and say what result would falsify your own position.

References.

  • Bender, E. M., Gebru, T., McMillan-Major, A., & Shmitchell, S. (2021). On the Dangers of Stochastic Parrots: Can Language Models Be Too Big? FAccT '21, 610–623. doi:10.1145/3442188.3445922.
  • Mahowald, K., Ivanova, A. A., Blank, I. A., Kanwisher, N., Tenenbaum, J. B., & Fedorenko, E. (2024). Dissociating Language and Thought in Large Language Models. Trends in Cognitive Sciences 28(6), 517–540. arXiv:2301.06627.
  • Sharma, M., et al. (2023). Towards Understanding Sycophancy in Language Models. arXiv:2310.13548.