{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Bab 11 — Generative AI Playground\n",
    "Notebook pendamping untuk memahami tokenisasi, embeddings, attention, decoding, mini RAG, dan hallucination check. Jalankan dari folder `code/` atau unggah bersama `generative_ai_playground.py` ke Colab/Kaggle."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from generative_ai_playground import *\n",
    "print('Notebook siap')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": ["## 1. Tokenisasi sederhana"]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": ["tokenize('Beras premium 5 kg untuk UMKM Bandung!')"]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": ["## 2. Retrieval berbasis cosine similarity"]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": ["retrieve('Apa syarat pinjaman koperasi?', DOCS, top_k=4)"]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": ["## 3. Self-attention mini"]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": ["attention_demo()"]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": ["## 4. Decoding bigram dan temperature"]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": ["generate_bigram('guru', temperature=0.4, top_k=3)"]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": ["generate_bigram('guru', temperature=1.4, top_k=5)"]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": ["## 5. Mini RAG dan cek klaim"]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": ["mini_rag_answer('Bolehkah memasukkan NIK ke AI publik?')"]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": ["unsupported_claims('Anggota wajib punya saldo sepuluh juta dan surat dokter.', [d['text'] for d in DOCS])"]
  }
 ],
 "metadata": {
  "kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"},
  "language_info": {"name": "python", "version": "3"}
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
