Skip to content

Commit 66f7894

Browse files
abossardCopilot
andcommitted
Replace 'Deine erste Vorhersage' with myth-busting quiz
Instead of DSPy-specific Predict demo, start with factual questions where the model gets things WRONG (Australian capital, glass myth, goldfish memory). Shows immediately: LLMs sound confident but aren't always correct. Motivates why evaluation matters. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 34b379e commit 66f7894

1 file changed

Lines changed: 51 additions & 123 deletions

File tree

notebooks/01_evaluation_and_tuning.ipynb

Lines changed: 51 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -165,153 +165,81 @@
165165
},
166166
{
167167
"cell_type": "markdown",
168-
"id": "589032da",
169168
"metadata": {},
170169
"source": [
171-
"## ✨ Deine erste Vorhersage\n",
170+
"## 🧪 Wie gut ist das Modell wirklich?\n",
172171
"\n",
173-
"Eine **Signature** beschreibt was reingeht und was rauskommen soll — wie ein Funktionstyp. Kein Prompt nötig! Der passende Prompt wird automatisch generiert."
172+
"Lass uns das Modell auf **Fragen mit bekannter Antwort** testen — und schauen wo es richtig liegt und wo es **daneben haut**.\n"
174173
]
175174
},
176175
{
177176
"cell_type": "code",
178-
"execution_count": 4,
179-
"id": "756aa0cc",
180177
"metadata": {},
181-
"outputs": [
182-
{
183-
"name": "stdout",
184-
"output_type": "stream",
185-
"text": [
186-
"🎯 Sentiment: positive\n"
187-
]
188-
}
189-
],
190178
"source": [
191-
"from dspy_tasks.data import ClassifySentiment\n",
179+
"import dspy\n",
192180
"from dspy_tasks.config import configure_dspy\n",
193181
"\n",
194-
"# Configure DSPy with chosen model\n",
195182
"configure_dspy(model=model_dropdown.value)\n",
196183
"\n",
197-
"# This is ALL you need — no prompt engineering!\n",
198-
"classifier = dspy.Predict(ClassifySentiment)\n",
184+
"# Fragen mit BEKANNTER richtiger Antwort\n",
185+
"test_questions = [\n",
186+
" (\"Was ist die Hauptstadt von Australien?\", \"Canberra\", \"Viele sagen Sydney...\"),\n",
187+
" (\"Wie viele Planeten hat unser Sonnensystem?\", \"8\", \"Pluto zählt nicht mehr\"),\n",
188+
" (\"Wer hat die Glühbirne erfunden?\", \"Edison hat sie verbessert, nicht erfunden\", \"Übliche Fehlantwort: Edison\"),\n",
189+
" (\"Ist Glas eine Flüssigkeit?\", \"Nein\", \"Weit verbreiteter Mythos\"),\n",
190+
" (\"Können Goldische nur 3 Sekunden erinnern?\", \"Nein, sie erinnern sich monatelang\", \"Klassischer Mythos\"),\n",
191+
" (\"Sieht man die Chinesische Mauer vom Weltraum?\", \"Nein\", \"Häufige Fehlannahme\"),\n",
192+
" (\"Was ist schwerer: 1kg Stahl oder 1kg Federn?\", \"Gleich schwer\", \"Denkfalle!\"),\n",
193+
" (\"Wie viel Prozent des Gehirns nutzen Menschen?\", \"Praktisch 100%\", \"10%-Mythos ist falsch\"),\n",
194+
"]\n",
199195
"\n",
200-
"# Try it\n",
201-
"result = classifier(review=\"This laptop is absolutely fantastic! Best purchase I've made all year.\")\n",
202-
"print(f\"🎯 Sentiment: {result.sentiment}\")"
203-
]
204-
},
205-
{
206-
"cell_type": "code",
207-
"execution_count": 6,
208-
"id": "66a97195",
209-
"metadata": {},
210-
"outputs": [
211-
{
212-
"data": {
213-
"application/vnd.jupyter.widget-view+json": {
214-
"model_id": "297db7290ecb427ea56ffbe2f6f8d418",
215-
"version_major": 2,
216-
"version_minor": 0
217-
},
218-
"text/plain": [
219-
"Textarea(value='The battery life is terrible, but the screen quality is amazing.', description='Review:', layo…"
220-
]
221-
},
222-
"metadata": {},
223-
"output_type": "display_data"
224-
},
225-
{
226-
"data": {
227-
"application/vnd.jupyter.widget-view+json": {
228-
"model_id": "c32046a776e1427a8586cca9792dd6b4",
229-
"version_major": 2,
230-
"version_minor": 0
231-
},
232-
"text/plain": [
233-
"Button(button_style='primary', description='Classify!', icon='play', style=ButtonStyle())"
234-
]
235-
},
236-
"metadata": {},
237-
"output_type": "display_data"
238-
},
239-
{
240-
"data": {
241-
"application/vnd.jupyter.widget-view+json": {
242-
"model_id": "bb5bf39e313b4adc9abc7e8b0a2802f7",
243-
"version_major": 2,
244-
"version_minor": 0
245-
},
246-
"text/plain": [
247-
"Output()"
248-
]
249-
},
250-
"metadata": {},
251-
"output_type": "display_data"
252-
}
196+
"class QA(dspy.Signature):\n",
197+
" \"\"\"Beantworte die Frage kurz und korrekt.\"\"\"\n",
198+
" question = dspy.InputField(desc=\"Eine Wissensfrage\")\n",
199+
" answer = dspy.OutputField(desc=\"Kurze, korrekte Antwort\")\n",
200+
"\n",
201+
"qa = dspy.Predict(QA)\n",
202+
"\n",
203+
"correct = 0\n",
204+
"total = len(test_questions)\n",
205+
"\n",
206+
"for question, expected, note in test_questions:\n",
207+
" result = qa(question=question)\n",
208+
" model_answer = result.answer.strip()\n",
209+
" # Simple check: does the expected answer appear in the model's response?\n",
210+
" is_ok = expected.lower() in model_answer.lower()\n",
211+
" correct += int(is_ok)\n",
212+
" icon = \"\" if is_ok else \"\"\n",
213+
" print(f\"{icon} {question}\")\n",
214+
" print(f\" Modell: {model_answer[:80]}\")\n",
215+
" if not is_ok:\n",
216+
" print(f\" Erwartet: {expected} ({note})\")\n",
217+
" print()\n",
218+
"\n",
219+
"accuracy = correct / total\n",
220+
"print(\"=\" * 50)\n",
221+
"print(f\"Ergebnis: {correct}/{total} richtig = {accuracy:.0%}\")\n",
222+
"if accuracy < 1.0:\n",
223+
" print(f\"\\n👆 {total - correct} Fehler! Das LLM ist NICHT perfekt.\")\n",
224+
" print(\"Und das waren noch einfache Fakten-Fragen...\")\n"
253225
],
254-
"source": [
255-
"review_input = widgets.Textarea(value=\"The battery life is terrible, but the screen quality is amazing.\",\n",
256-
" description=\"Review:\", layout=widgets.Layout(width=\"600px\", height=\"80px\"))\n",
257-
"run_btn = widgets.Button(description=\"Classify!\", button_style=\"primary\", icon=\"play\")\n",
258-
"output = widgets.Output()\n",
259-
"\n",
260-
"def on_click(b):\n",
261-
" with output:\n",
262-
" output.clear_output()\n",
263-
" result = classifier(review=review_input.value)\n",
264-
" display_score(\"Prediction\", 1.0 if result.sentiment else 0.0)\n",
265-
" print(f\"→ {result.sentiment}\")\n",
266-
"\n",
267-
"run_btn.on_click(on_click)\n",
268-
"display(review_input, run_btn, output)"
269-
]
270-
},
271-
{
272-
"cell_type": "markdown",
273-
"id": "2cc4afb0",
274-
"metadata": {},
275-
"source": [
276-
"## 🗺️ Was dich erwartet\n",
277-
"\n",
278-
"Du wirst durch 8 Notebooks geführt — von den Grundlagen bis zur automatischen Optimierung. Jedes Notebook baut auf dem vorherigen auf und hat interaktive Aufgaben.\n",
279-
"\n",
280-
"Los geht's!"
281-
]
282-
},
283-
{
284-
"cell_type": "code",
285-
"execution_count": 7,
286-
"id": "a0eedf86",
287-
"metadata": {},
288226
"outputs": [],
289-
"source": [
290-
"# Die Aufgaben entdeckst du Schritt für Schritt in den folgenden Notebooks."
291-
]
227+
"execution_count": null
292228
},
293229
{
294230
"cell_type": "markdown",
295-
"id": "d2b9afcc",
296231
"metadata": {},
297232
"source": [
298-
"## ⏭️ Weiter geht's!\n",
299-
"\n",
300-
"Du kannst ein Modell aufrufen und bekommst ein Ergebnis. **Aber woher weisst du, ob es GUT ist?**\n",
233+
"## 💡 Das Problem\n",
301234
"\n",
302-
"Das klären wir im nächsten Notebook: Wie man **Accuracy misst**, wo LLMs versagen, und wie du **selbst versuchst den Prompt zu verbessern**.\n",
235+
"LLMs klingen immer selbstsicher — auch wenn sie **falsch liegen**. Ohne systematische Messung weisst du nicht:\n",
236+
"- Wie oft liegt das Modell richtig?\n",
237+
"- Wird es bei bestimmten Fragen schlechter?\n",
238+
"- Hilft eine andere Formulierung?\n",
303239
"\n",
304-
"👉 **[Weiter zu Notebook: Evaluation →](01_evaluation_and_tuning.ipynb)**\n"
240+
"Genau dafür brauchst du **Evaluation** — und die kommt jetzt.\n"
305241
]
306242
},
307-
{
308-
"cell_type": "code",
309-
"execution_count": null,
310-
"id": "38a40975",
311-
"metadata": {},
312-
"outputs": [],
313-
"source": []
314-
},
315243
{
316244
"cell_type": "markdown",
317245
"id": "cb49eaa5",
@@ -636,4 +564,4 @@
636564
},
637565
"nbformat": 4,
638566
"nbformat_minor": 5
639-
}
567+
}

0 commit comments

Comments
 (0)