fassabilf commited on
Commit
b205ee8
·
verified ·
1 Parent(s): 5e14285

Add executed notebook with outputs (all 33 cells run)

Browse files
Files changed (1) hide show
  1. clip_tutorial.ipynb +900 -94
clip_tutorial.ipynb CHANGED
@@ -65,11 +65,21 @@
65
  },
66
  {
67
  "cell_type": "code",
68
- "execution_count": null,
69
  "id": "25a6d7c7",
70
- "metadata": {},
 
 
 
 
 
 
 
71
  "outputs": [],
72
  "source": [
 
 
 
73
  "# ── Cell 1.1: Visualisasi konsep similarity matrix ──────────────────────────\n",
74
  "import numpy as np\n",
75
  "import matplotlib.pyplot as plt\n",
@@ -127,10 +137,40 @@
127
  },
128
  {
129
  "cell_type": "code",
130
- "execution_count": null,
131
  "id": "1e24cd2b",
132
- "metadata": {},
133
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  "source": [
135
  "# ── Cell 2.1: Setup dan download CIFAR-10 ───────────────────────────────────\n",
136
  "import torch\n",
@@ -151,7 +191,7 @@
151
  " transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))\n",
152
  "])\n",
153
  "\n",
154
- "full_train = datasets.CIFAR10(root='./data', train=True, download=True, transform=transform)\n",
155
  "\n",
156
  "# Ambil 100 images per class = 1000 total\n",
157
  "indices_per_class = {c: [] for c in range(10)}\n",
@@ -170,9 +210,16 @@
170
  },
171
  {
172
  "cell_type": "code",
173
- "execution_count": null,
174
  "id": "48df6b98",
175
- "metadata": {},
 
 
 
 
 
 
 
176
  "outputs": [],
177
  "source": [
178
  "# ── Cell 2.2: Tiny Image Encoder ────────────────────────────────────────────\n",
@@ -222,10 +269,26 @@
222
  },
223
  {
224
  "cell_type": "code",
225
- "execution_count": null,
226
  "id": "0bd8a6ea",
227
- "metadata": {},
228
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
  "source": [
230
  "# ── Cell 2.4: Simple Tokenizer ───────────────────────────────────────────────\n",
231
  "templates = [f\"a photo of a {c}\" for c in CIFAR10_CLASSES]\n",
@@ -252,9 +315,16 @@
252
  },
253
  {
254
  "cell_type": "code",
255
- "execution_count": null,
256
  "id": "6d6dce03",
257
- "metadata": {},
 
 
 
 
 
 
 
258
  "outputs": [],
259
  "source": [
260
  "# ── Cell 2.5: InfoNCE Loss ───────────────────────────────────────────────────\n",
@@ -279,10 +349,25 @@
279
  },
280
  {
281
  "cell_type": "code",
282
- "execution_count": null,
283
  "id": "45e059f3",
284
- "metadata": {},
285
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286
  "source": [
287
  "# ── Cell 2.6: TinyCLIP model ────────────────────────────────────────────────\n",
288
  "class TinyCLIP(nn.Module):\n",
@@ -304,10 +389,58 @@
304
  },
305
  {
306
  "cell_type": "code",
307
- "execution_count": null,
308
  "id": "f360ddba",
309
- "metadata": {},
310
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
  "source": [
312
  "# ── Cell 2.7: Training loop ──────────────────────────────────────────────────\n",
313
  "optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)\n",
@@ -348,9 +481,16 @@
348
  },
349
  {
350
  "cell_type": "code",
351
- "execution_count": null,
352
  "id": "cb49c0e2",
353
- "metadata": {},
 
 
 
 
 
 
 
354
  "outputs": [],
355
  "source": [
356
  "# ── Cell 2.8: Plot loss curve ────────────────────────────────────────────────\n",
@@ -368,9 +508,16 @@
368
  },
369
  {
370
  "cell_type": "code",
371
- "execution_count": null,
372
  "id": "7e920a81",
373
- "metadata": {},
 
 
 
 
 
 
 
374
  "outputs": [],
375
  "source": [
376
  "# ── Cell 2.9: Visualisasi embedding space (t-SNE) ───────────────────────────\n",
@@ -431,10 +578,273 @@
431
  },
432
  {
433
  "cell_type": "code",
434
- "execution_count": null,
435
  "id": "1cde344f",
436
- "metadata": {},
437
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
438
  "source": [
439
  "# ── Cell 3.1: Install dan load CLIP ─────────────────────────────────────────\n",
440
  "# !pip install git+https://github.com/openai/CLIP.git # jalankan sekali jika belum\n",
@@ -455,10 +865,32 @@
455
  },
456
  {
457
  "cell_type": "code",
458
- "execution_count": null,
459
  "id": "51eb6f2e",
460
- "metadata": {},
461
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
462
  "source": [
463
  "# ── Cell 3.2: Load STL-10 test images ───────────────────────────────────────\n",
464
  "from torchvision import datasets\n",
@@ -472,7 +904,7 @@
472
  " (0.26862954, 0.26130258, 0.27577711))\n",
473
  "])\n",
474
  "\n",
475
- "stl10_test = datasets.STL10(root='./data', split='test', download=True,\n",
476
  " transform=clip_preprocess)\n",
477
  "\n",
478
  "STL10_CLASSES = stl10_test.classes\n",
@@ -505,10 +937,33 @@
505
  },
506
  {
507
  "cell_type": "code",
508
- "execution_count": null,
509
  "id": "0c99135b",
510
- "metadata": {},
511
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
512
  "source": [
513
  "# ── Cell 3.3: Extract CLIP image embeddings ──────────────────────────────────\n",
514
  "from torch.utils.data import DataLoader, TensorDataset\n",
@@ -536,10 +991,25 @@
536
  },
537
  {
538
  "cell_type": "code",
539
- "execution_count": null,
540
  "id": "61608dde",
541
- "metadata": {},
542
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
543
  "source": [
544
  "# ── Cell 3.4: Extract text embeddings untuk 10 kelas ────────────────────────\n",
545
  "def get_text_embeddings(class_names, template=\"a photo of a {}\"):\n",
@@ -558,9 +1028,16 @@
558
  },
559
  {
560
  "cell_type": "code",
561
- "execution_count": null,
562
  "id": "5a113a9e",
563
- "metadata": {},
 
 
 
 
 
 
 
564
  "outputs": [],
565
  "source": [
566
  "# ── Cell 3.5: Visualisasi t-SNE ─────────────────────────────────────────────\n",
@@ -612,10 +1089,25 @@
612
  },
613
  {
614
  "cell_type": "code",
615
- "execution_count": null,
616
  "id": "6d54f9b1",
617
- "metadata": {},
618
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
619
  "source": [
620
  "# ── Cell 4.1: Zero-shot prediction ──────────────────────────────────────────\n",
621
  "# zs_embeddings dan text_embeddings sudah dihitung di Section 3\n",
@@ -630,10 +1122,31 @@
630
  },
631
  {
632
  "cell_type": "code",
633
- "execution_count": null,
634
  "id": "bfb07706",
635
- "metadata": {},
636
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
637
  "source": [
638
  "# ── Cell 4.2: Pengaruh prompt engineering ────────────────────────────────────\n",
639
  "templates_to_compare = [\n",
@@ -655,9 +1168,16 @@
655
  },
656
  {
657
  "cell_type": "code",
658
- "execution_count": null,
659
  "id": "aa9db826",
660
- "metadata": {},
 
 
 
 
 
 
 
661
  "outputs": [],
662
  "source": [
663
  "# ── Cell 4.3: Confusion matrix ───────────────────────────────────────────────\n",
@@ -676,10 +1196,36 @@
676
  },
677
  {
678
  "cell_type": "code",
679
- "execution_count": null,
680
  "id": "eb5c282d",
681
- "metadata": {},
682
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
683
  "source": [
684
  "# ── Cell 4.4: Per-class accuracy ─────────────────────────────────────────────\n",
685
  "per_class_acc = {}\n",
@@ -716,13 +1262,35 @@
716
  },
717
  {
718
  "cell_type": "code",
719
- "execution_count": null,
720
  "id": "c57f46c5",
721
- "metadata": {},
722
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
723
  "source": [
724
  "# ── Cell 5.1: Extract train embeddings untuk linear probing ─────────────────\n",
725
- "stl10_train = datasets.STL10(root='./data', split='train', download=True,\n",
726
  " transform=clip_preprocess)\n",
727
  "\n",
728
  "# Ambil 100/class = 1000 images untuk training\n",
@@ -746,10 +1314,25 @@
746
  },
747
  {
748
  "cell_type": "code",
749
- "execution_count": null,
750
  "id": "1dc5eed7",
751
- "metadata": {},
752
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
753
  "source": [
754
  "# ── Cell 5.2: Train classifier ───────────────────────────────────────────────\n",
755
  "from sklearn.linear_model import LogisticRegression\n",
@@ -764,10 +1347,32 @@
764
  },
765
  {
766
  "cell_type": "code",
767
- "execution_count": null,
768
  "id": "9832535f",
769
- "metadata": {},
770
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
771
  "source": [
772
  "# ── Cell 5.3: Perbandingan zero-shot vs linear probing ───────────────────────\n",
773
  "print(\"\\n\" + \"=\"*50)\n",
@@ -781,9 +1386,16 @@
781
  },
782
  {
783
  "cell_type": "code",
784
- "execution_count": null,
785
  "id": "69fafdc6",
786
- "metadata": {},
 
 
 
 
 
 
 
787
  "outputs": [],
788
  "source": [
789
  "# ── Cell 5.4: Bar chart per-class comparison ─────────────────────────────────\n",
@@ -832,16 +1444,46 @@
832
  },
833
  {
834
  "cell_type": "code",
835
- "execution_count": null,
836
  "id": "4eac3bd2",
837
- "metadata": {},
838
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
839
  "source": [
840
  "# ── Cell 6.1: Load Flickr8k test data ────────────────────────────────────────\n",
841
  "import pandas as pd\n",
842
  "from PIL import Image as PILImage\n",
843
  "\n",
844
- "DATASET_ROOT = '/kaggle/input/clip-pelatnas-p2'\n",
845
  "candidates_df = pd.read_csv(f'{DATASET_ROOT}/test/retrieval/candidates.csv')\n",
846
  "print(f\"Retrieval test: {len(candidates_df)} queries\")\n",
847
  "print(candidates_df.head(2))\n"
@@ -849,9 +1491,16 @@
849
  },
850
  {
851
  "cell_type": "code",
852
- "execution_count": null,
853
  "id": "876b6c60",
854
- "metadata": {},
 
 
 
 
 
 
 
855
  "outputs": [],
856
  "source": [
857
  "# ── Cell 6.2: CLIP retrieval pipeline ────────────────────────────────────────\n",
@@ -877,10 +1526,26 @@
877
  },
878
  {
879
  "cell_type": "code",
880
- "execution_count": null,
881
  "id": "70ca735c",
882
- "metadata": {},
883
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
884
  "source": [
885
  "# ── Cell 6.3: Batch evaluation ────────────────────────────────────────────────\n",
886
  "base_path = f'{DATASET_ROOT}/test/retrieval/queries/'\n",
@@ -903,9 +1568,16 @@
903
  },
904
  {
905
  "cell_type": "code",
906
- "execution_count": null,
907
  "id": "0c01f0d0",
908
- "metadata": {},
 
 
 
 
 
 
 
909
  "outputs": [],
910
  "source": [
911
  "# ── Cell 6.4: Qualitative examples ───────────────────────────────────────────\n",
@@ -966,10 +1638,36 @@
966
  },
967
  {
968
  "cell_type": "code",
969
- "execution_count": null,
970
  "id": "bd004ef7",
971
- "metadata": {},
972
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
973
  "source": [
974
  "# ── Cell 7.1: Load ScienceQA test data ──────────────────────────────────────\n",
975
  "mcqa_df = pd.read_csv(f'{DATASET_ROOT}/test/mcqa/test.csv')\n",
@@ -979,9 +1677,16 @@
979
  },
980
  {
981
  "cell_type": "code",
982
- "execution_count": null,
983
  "id": "3fedf9ce",
984
- "metadata": {},
 
 
 
 
 
 
 
985
  "outputs": [],
986
  "source": [
987
  "# ── Cell 7.2: CLIP MCQA pipeline ─────────────────────────────────────────────\n",
@@ -1010,10 +1715,26 @@
1010
  },
1011
  {
1012
  "cell_type": "code",
1013
- "execution_count": null,
1014
  "id": "80755731",
1015
- "metadata": {},
1016
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1017
  "source": [
1018
  "# ── Cell 7.3: Batch evaluation ────────────────────────────────────────────────\n",
1019
  "base_path_mcqa = f'{DATASET_ROOT}/test/mcqa/images/'\n",
@@ -1038,10 +1759,28 @@
1038
  },
1039
  {
1040
  "cell_type": "code",
1041
- "execution_count": null,
1042
  "id": "0b34a2f3",
1043
- "metadata": {},
1044
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1045
  "source": [
1046
  "# ── Cell 7.4: Analysis per subject ───────────────────────────────────────────\n",
1047
  "mcqa_df_copy = mcqa_df.copy()\n",
@@ -1086,9 +1825,16 @@
1086
  },
1087
  {
1088
  "cell_type": "code",
1089
- "execution_count": null,
1090
  "id": "98109b5f",
1091
- "metadata": {},
 
 
 
 
 
 
 
1092
  "outputs": [],
1093
  "source": [
1094
  "# ── Cell 8.1: Compile semua prediksi ─────────────────────────────────────────\n",
@@ -1119,10 +1865,42 @@
1119
  },
1120
  {
1121
  "cell_type": "code",
1122
- "execution_count": null,
1123
  "id": "0675c9b8",
1124
- "metadata": {},
1125
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1126
  "source": [
1127
  "# ── Cell 8.2: Generate submission ────────────────────────────────────────────\n",
1128
  "submission = sample_sub.copy()\n",
@@ -1143,10 +1921,30 @@
1143
  },
1144
  {
1145
  "cell_type": "code",
1146
- "execution_count": null,
1147
  "id": "9fcd617f",
1148
- "metadata": {},
1149
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1150
  "source": [
1151
  "# ── Cell 8.3: Sanity check ────────────────────────────────────────────────────\n",
1152
  "print(\"Distribusi prediksi per task:\\n\")\n",
@@ -1161,13 +1959,21 @@
1161
  ],
1162
  "metadata": {
1163
  "kernelspec": {
1164
- "display_name": "Python 3",
1165
  "language": "python",
1166
- "name": "python3"
1167
  },
1168
  "language_info": {
 
 
 
 
 
 
1169
  "name": "python",
1170
- "version": "3.10.0"
 
 
1171
  }
1172
  },
1173
  "nbformat": 4,
 
65
  },
66
  {
67
  "cell_type": "code",
68
+ "execution_count": 1,
69
  "id": "25a6d7c7",
70
+ "metadata": {
71
+ "execution": {
72
+ "iopub.execute_input": "2026-05-30T01:07:45.417657Z",
73
+ "iopub.status.busy": "2026-05-30T01:07:45.417118Z",
74
+ "iopub.status.idle": "2026-05-30T01:07:46.121194Z",
75
+ "shell.execute_reply": "2026-05-30T01:07:46.120053Z"
76
+ }
77
+ },
78
  "outputs": [],
79
  "source": [
80
+ "import matplotlib\n",
81
+ "matplotlib.use(\"Agg\")\n",
82
+ "\n",
83
  "# ── Cell 1.1: Visualisasi konsep similarity matrix ──────────────────────────\n",
84
  "import numpy as np\n",
85
  "import matplotlib.pyplot as plt\n",
 
137
  },
138
  {
139
  "cell_type": "code",
140
+ "execution_count": 2,
141
  "id": "1e24cd2b",
142
+ "metadata": {
143
+ "execution": {
144
+ "iopub.execute_input": "2026-05-30T01:07:46.125861Z",
145
+ "iopub.status.busy": "2026-05-30T01:07:46.125608Z",
146
+ "iopub.status.idle": "2026-05-30T01:07:49.587548Z",
147
+ "shell.execute_reply": "2026-05-30T01:07:49.586502Z"
148
+ }
149
+ },
150
+ "outputs": [
151
+ {
152
+ "name": "stdout",
153
+ "output_type": "stream",
154
+ "text": [
155
+ "Using device: cuda\n"
156
+ ]
157
+ },
158
+ {
159
+ "name": "stderr",
160
+ "output_type": "stream",
161
+ "text": [
162
+ "/venv/main/lib/python3.12/site-packages/torchvision/datasets/cifar.py:83: VisibleDeprecationWarning: dtype(): align should be passed as Python or NumPy boolean but got `align=0`. Did you mean to pass a tuple to create a subarray type? (Deprecated NumPy 2.4)\n",
163
+ " entry = pickle.load(f, encoding=\"latin1\")\n"
164
+ ]
165
+ },
166
+ {
167
+ "name": "stdout",
168
+ "output_type": "stream",
169
+ "text": [
170
+ "Toy dataset size: 1000 images\n"
171
+ ]
172
+ }
173
+ ],
174
  "source": [
175
  "# ── Cell 2.1: Setup dan download CIFAR-10 ───────────────────────────────────\n",
176
  "import torch\n",
 
191
  " transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))\n",
192
  "])\n",
193
  "\n",
194
+ "full_train = datasets.CIFAR10(root='/workspace/data', train=True, download=True, transform=transform)\n",
195
  "\n",
196
  "# Ambil 100 images per class = 1000 total\n",
197
  "indices_per_class = {c: [] for c in range(10)}\n",
 
210
  },
211
  {
212
  "cell_type": "code",
213
+ "execution_count": 3,
214
  "id": "48df6b98",
215
+ "metadata": {
216
+ "execution": {
217
+ "iopub.execute_input": "2026-05-30T01:07:49.592486Z",
218
+ "iopub.status.busy": "2026-05-30T01:07:49.592039Z",
219
+ "iopub.status.idle": "2026-05-30T01:07:49.600668Z",
220
+ "shell.execute_reply": "2026-05-30T01:07:49.599519Z"
221
+ }
222
+ },
223
  "outputs": [],
224
  "source": [
225
  "# ── Cell 2.2: Tiny Image Encoder ────────────────────────────────────────────\n",
 
269
  },
270
  {
271
  "cell_type": "code",
272
+ "execution_count": 4,
273
  "id": "0bd8a6ea",
274
+ "metadata": {
275
+ "execution": {
276
+ "iopub.execute_input": "2026-05-30T01:07:49.605442Z",
277
+ "iopub.status.busy": "2026-05-30T01:07:49.605177Z",
278
+ "iopub.status.idle": "2026-05-30T01:07:49.730158Z",
279
+ "shell.execute_reply": "2026-05-30T01:07:49.729076Z"
280
+ }
281
+ },
282
+ "outputs": [
283
+ {
284
+ "name": "stdout",
285
+ "output_type": "stream",
286
+ "text": [
287
+ "Vocabulary: {'a': 1, 'airplane': 2, 'automobile': 3, 'bird': 4, 'cat': 5, 'deer': 6, 'dog': 7, 'frog': 8, 'horse': 9, 'of': 10, 'photo': 11, 'ship': 12, 'truck': 13, '<pad>': 0}\n",
288
+ "Template tokens shape: torch.Size([10, 8])\n"
289
+ ]
290
+ }
291
+ ],
292
  "source": [
293
  "# ── Cell 2.4: Simple Tokenizer ───────────────────────────────────────────────\n",
294
  "templates = [f\"a photo of a {c}\" for c in CIFAR10_CLASSES]\n",
 
315
  },
316
  {
317
  "cell_type": "code",
318
+ "execution_count": 5,
319
  "id": "6d6dce03",
320
+ "metadata": {
321
+ "execution": {
322
+ "iopub.execute_input": "2026-05-30T01:07:49.733518Z",
323
+ "iopub.status.busy": "2026-05-30T01:07:49.733317Z",
324
+ "iopub.status.idle": "2026-05-30T01:07:49.738357Z",
325
+ "shell.execute_reply": "2026-05-30T01:07:49.736505Z"
326
+ }
327
+ },
328
  "outputs": [],
329
  "source": [
330
  "# ── Cell 2.5: InfoNCE Loss ───────────────────────────────────────────────────\n",
 
349
  },
350
  {
351
  "cell_type": "code",
352
+ "execution_count": 6,
353
  "id": "45e059f3",
354
+ "metadata": {
355
+ "execution": {
356
+ "iopub.execute_input": "2026-05-30T01:07:49.742790Z",
357
+ "iopub.status.busy": "2026-05-30T01:07:49.742553Z",
358
+ "iopub.status.idle": "2026-05-30T01:07:49.750386Z",
359
+ "shell.execute_reply": "2026-05-30T01:07:49.749325Z"
360
+ }
361
+ },
362
+ "outputs": [
363
+ {
364
+ "name": "stdout",
365
+ "output_type": "stream",
366
+ "text": [
367
+ "TinyCLIP parameters: 36,992\n"
368
+ ]
369
+ }
370
+ ],
371
  "source": [
372
  "# ── Cell 2.6: TinyCLIP model ────────────────────────────────────────────────\n",
373
  "class TinyCLIP(nn.Module):\n",
 
389
  },
390
  {
391
  "cell_type": "code",
392
+ "execution_count": 7,
393
  "id": "f360ddba",
394
+ "metadata": {
395
+ "execution": {
396
+ "iopub.execute_input": "2026-05-30T01:07:49.754647Z",
397
+ "iopub.status.busy": "2026-05-30T01:07:49.754364Z",
398
+ "iopub.status.idle": "2026-05-30T01:07:51.795842Z",
399
+ "shell.execute_reply": "2026-05-30T01:07:51.793975Z"
400
+ }
401
+ },
402
+ "outputs": [
403
+ {
404
+ "name": "stdout",
405
+ "output_type": "stream",
406
+ "text": [
407
+ "Epoch 1/10 | Loss: 4.0007\n",
408
+ "Epoch 2/10 | Loss: 3.8239\n"
409
+ ]
410
+ },
411
+ {
412
+ "name": "stdout",
413
+ "output_type": "stream",
414
+ "text": [
415
+ "Epoch 3/10 | Loss: 3.7374\n",
416
+ "Epoch 4/10 | Loss: 3.6494\n"
417
+ ]
418
+ },
419
+ {
420
+ "name": "stdout",
421
+ "output_type": "stream",
422
+ "text": [
423
+ "Epoch 5/10 | Loss: 3.5925\n",
424
+ "Epoch 6/10 | Loss: 3.5350\n"
425
+ ]
426
+ },
427
+ {
428
+ "name": "stdout",
429
+ "output_type": "stream",
430
+ "text": [
431
+ "Epoch 7/10 | Loss: 3.4929\n",
432
+ "Epoch 8/10 | Loss: 3.4293\n"
433
+ ]
434
+ },
435
+ {
436
+ "name": "stdout",
437
+ "output_type": "stream",
438
+ "text": [
439
+ "Epoch 9/10 | Loss: 3.3991\n",
440
+ "Epoch 10/10 | Loss: 3.3990\n"
441
+ ]
442
+ }
443
+ ],
444
  "source": [
445
  "# ── Cell 2.7: Training loop ──────────────────────────────────────────────────\n",
446
  "optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)\n",
 
481
  },
482
  {
483
  "cell_type": "code",
484
+ "execution_count": 8,
485
  "id": "cb49c0e2",
486
+ "metadata": {
487
+ "execution": {
488
+ "iopub.execute_input": "2026-05-30T01:07:51.800144Z",
489
+ "iopub.status.busy": "2026-05-30T01:07:51.799672Z",
490
+ "iopub.status.idle": "2026-05-30T01:07:51.853728Z",
491
+ "shell.execute_reply": "2026-05-30T01:07:51.852713Z"
492
+ }
493
+ },
494
  "outputs": [],
495
  "source": [
496
  "# ── Cell 2.8: Plot loss curve ────────────────────────────────────────────────\n",
 
508
  },
509
  {
510
  "cell_type": "code",
511
+ "execution_count": 9,
512
  "id": "7e920a81",
513
+ "metadata": {
514
+ "execution": {
515
+ "iopub.execute_input": "2026-05-30T01:07:51.858456Z",
516
+ "iopub.status.busy": "2026-05-30T01:07:51.858122Z",
517
+ "iopub.status.idle": "2026-05-30T01:07:55.968437Z",
518
+ "shell.execute_reply": "2026-05-30T01:07:55.967679Z"
519
+ }
520
+ },
521
  "outputs": [],
522
  "source": [
523
  "# ── Cell 2.9: Visualisasi embedding space (t-SNE) ───────────────────────────\n",
 
578
  },
579
  {
580
  "cell_type": "code",
581
+ "execution_count": 10,
582
  "id": "1cde344f",
583
+ "metadata": {
584
+ "execution": {
585
+ "iopub.execute_input": "2026-05-30T01:07:55.972774Z",
586
+ "iopub.status.busy": "2026-05-30T01:07:55.972129Z",
587
+ "iopub.status.idle": "2026-05-30T01:08:02.791603Z",
588
+ "shell.execute_reply": "2026-05-30T01:08:02.790296Z"
589
+ }
590
+ },
591
+ "outputs": [
592
+ {
593
+ "name": "stderr",
594
+ "output_type": "stream",
595
+ "text": [
596
+ "\r",
597
+ " 0%| | 0.00/338M [00:00<?, ?iB/s]"
598
+ ]
599
+ },
600
+ {
601
+ "name": "stderr",
602
+ "output_type": "stream",
603
+ "text": [
604
+ "\r",
605
+ " 0%| | 240k/338M [00:00<02:26, 2.42MiB/s]"
606
+ ]
607
+ },
608
+ {
609
+ "name": "stderr",
610
+ "output_type": "stream",
611
+ "text": [
612
+ "\r",
613
+ " 1%|▎ | 2.69M/338M [00:00<00:21, 16.0MiB/s]"
614
+ ]
615
+ },
616
+ {
617
+ "name": "stderr",
618
+ "output_type": "stream",
619
+ "text": [
620
+ "\r",
621
+ " 4%|█▋ | 14.9M/338M [00:00<00:05, 67.0MiB/s]"
622
+ ]
623
+ },
624
+ {
625
+ "name": "stderr",
626
+ "output_type": "stream",
627
+ "text": [
628
+ "\r",
629
+ " 8%|███ | 27.7M/338M [00:00<00:03, 93.1MiB/s]"
630
+ ]
631
+ },
632
+ {
633
+ "name": "stderr",
634
+ "output_type": "stream",
635
+ "text": [
636
+ "\r",
637
+ " 12%|████▋ | 41.0M/338M [00:00<00:02, 110MiB/s]"
638
+ ]
639
+ },
640
+ {
641
+ "name": "stderr",
642
+ "output_type": "stream",
643
+ "text": [
644
+ "\r",
645
+ " 16%|██████▏ | 54.0M/338M [00:00<00:02, 119MiB/s]"
646
+ ]
647
+ },
648
+ {
649
+ "name": "stderr",
650
+ "output_type": "stream",
651
+ "text": [
652
+ "\r",
653
+ " 20%|███████▋ | 66.2M/338M [00:00<00:02, 122MiB/s]"
654
+ ]
655
+ },
656
+ {
657
+ "name": "stderr",
658
+ "output_type": "stream",
659
+ "text": [
660
+ "\r",
661
+ " 23%|█████████▏ | 79.3M/338M [00:00<00:02, 127MiB/s]"
662
+ ]
663
+ },
664
+ {
665
+ "name": "stderr",
666
+ "output_type": "stream",
667
+ "text": [
668
+ "\r",
669
+ " 27%|██████████▋ | 92.5M/338M [00:00<00:01, 130MiB/s]"
670
+ ]
671
+ },
672
+ {
673
+ "name": "stderr",
674
+ "output_type": "stream",
675
+ "text": [
676
+ "\r",
677
+ " 31%|████████████▌ | 106M/338M [00:01<00:01, 133MiB/s]"
678
+ ]
679
+ },
680
+ {
681
+ "name": "stderr",
682
+ "output_type": "stream",
683
+ "text": [
684
+ "\r",
685
+ " 35%|██████████████ | 119M/338M [00:01<00:01, 134MiB/s]"
686
+ ]
687
+ },
688
+ {
689
+ "name": "stderr",
690
+ "output_type": "stream",
691
+ "text": [
692
+ "\r",
693
+ " 39%|███████████████▌ | 132M/338M [00:01<00:01, 134MiB/s]"
694
+ ]
695
+ },
696
+ {
697
+ "name": "stderr",
698
+ "output_type": "stream",
699
+ "text": [
700
+ "\r",
701
+ " 43%|█████████████████▏ | 145M/338M [00:01<00:01, 136MiB/s]"
702
+ ]
703
+ },
704
+ {
705
+ "name": "stderr",
706
+ "output_type": "stream",
707
+ "text": [
708
+ "\r",
709
+ " 47%|██████████████████▊ | 158M/338M [00:01<00:01, 137MiB/s]"
710
+ ]
711
+ },
712
+ {
713
+ "name": "stderr",
714
+ "output_type": "stream",
715
+ "text": [
716
+ "\r",
717
+ " 51%|████████████████████▎ | 171M/338M [00:01<00:01, 137MiB/s]"
718
+ ]
719
+ },
720
+ {
721
+ "name": "stderr",
722
+ "output_type": "stream",
723
+ "text": [
724
+ "\r",
725
+ " 55%|█████████████████████▊ | 184M/338M [00:01<00:01, 130MiB/s]"
726
+ ]
727
+ },
728
+ {
729
+ "name": "stderr",
730
+ "output_type": "stream",
731
+ "text": [
732
+ "\r",
733
+ " 58%|███████████████████████▎ | 197M/338M [00:01<00:01, 103MiB/s]"
734
+ ]
735
+ },
736
+ {
737
+ "name": "stderr",
738
+ "output_type": "stream",
739
+ "text": [
740
+ "\r",
741
+ " 62%|████████████████████████▌ | 208M/338M [00:01<00:01, 104MiB/s]"
742
+ ]
743
+ },
744
+ {
745
+ "name": "stderr",
746
+ "output_type": "stream",
747
+ "text": [
748
+ "\r",
749
+ " 65%|█████████████████████████▉ | 219M/338M [00:02<00:01, 107MiB/s]"
750
+ ]
751
+ },
752
+ {
753
+ "name": "stderr",
754
+ "output_type": "stream",
755
+ "text": [
756
+ "\r",
757
+ " 69%|███████████████████████████▍ | 232M/338M [00:02<00:00, 115MiB/s]"
758
+ ]
759
+ },
760
+ {
761
+ "name": "stderr",
762
+ "output_type": "stream",
763
+ "text": [
764
+ "\r",
765
+ " 72%|████████████████████████████▉ | 244M/338M [00:02<00:00, 119MiB/s]"
766
+ ]
767
+ },
768
+ {
769
+ "name": "stderr",
770
+ "output_type": "stream",
771
+ "text": [
772
+ "\r",
773
+ " 76%|██████████████████████████████▎ | 256M/338M [00:02<00:00, 120MiB/s]"
774
+ ]
775
+ },
776
+ {
777
+ "name": "stderr",
778
+ "output_type": "stream",
779
+ "text": [
780
+ "\r",
781
+ " 79%|██████████████████████████████▉ | 268M/338M [00:02<00:00, 90.1MiB/s]"
782
+ ]
783
+ },
784
+ {
785
+ "name": "stderr",
786
+ "output_type": "stream",
787
+ "text": [
788
+ "\r",
789
+ " 83%|████████████████████████████████▎ | 280M/338M [00:02<00:00, 98.8MiB/s]"
790
+ ]
791
+ },
792
+ {
793
+ "name": "stderr",
794
+ "output_type": "stream",
795
+ "text": [
796
+ "\r",
797
+ " 87%|██████████████████████████████████▋ | 293M/338M [00:02<00:00, 108MiB/s]"
798
+ ]
799
+ },
800
+ {
801
+ "name": "stderr",
802
+ "output_type": "stream",
803
+ "text": [
804
+ "\r",
805
+ " 90%|████████████████████████████████████ | 305M/338M [00:02<00:00, 112MiB/s]"
806
+ ]
807
+ },
808
+ {
809
+ "name": "stderr",
810
+ "output_type": "stream",
811
+ "text": [
812
+ "\r",
813
+ " 94%|█████████████████████████████████████▋ | 318M/338M [00:02<00:00, 119MiB/s]"
814
+ ]
815
+ },
816
+ {
817
+ "name": "stderr",
818
+ "output_type": "stream",
819
+ "text": [
820
+ "\r",
821
+ " 98%|███████████████████████████████████████▏| 331M/338M [00:03<00:00, 123MiB/s]"
822
+ ]
823
+ },
824
+ {
825
+ "name": "stderr",
826
+ "output_type": "stream",
827
+ "text": [
828
+ "\r",
829
+ "100%|████████████████████████████████████████| 338M/338M [00:03<00:00, 114MiB/s]"
830
+ ]
831
+ },
832
+ {
833
+ "name": "stderr",
834
+ "output_type": "stream",
835
+ "text": [
836
+ "\n"
837
+ ]
838
+ },
839
+ {
840
+ "name": "stdout",
841
+ "output_type": "stream",
842
+ "text": [
843
+ "Model loaded. Input resolution: 224\n",
844
+ "Embedding dimension: 512\n"
845
+ ]
846
+ }
847
+ ],
848
  "source": [
849
  "# ── Cell 3.1: Install dan load CLIP ─────────────────────────────────────────\n",
850
  "# !pip install git+https://github.com/openai/CLIP.git # jalankan sekali jika belum\n",
 
865
  },
866
  {
867
  "cell_type": "code",
868
+ "execution_count": 11,
869
  "id": "51eb6f2e",
870
+ "metadata": {
871
+ "execution": {
872
+ "iopub.execute_input": "2026-05-30T01:08:02.795735Z",
873
+ "iopub.status.busy": "2026-05-30T01:08:02.795482Z",
874
+ "iopub.status.idle": "2026-05-30T01:08:07.727582Z",
875
+ "shell.execute_reply": "2026-05-30T01:08:07.726747Z"
876
+ }
877
+ },
878
+ "outputs": [
879
+ {
880
+ "name": "stdout",
881
+ "output_type": "stream",
882
+ "text": [
883
+ "STL-10 classes: ['airplane', 'bird', 'car', 'cat', 'deer', 'dog', 'horse', 'monkey', 'ship', 'truck']\n"
884
+ ]
885
+ },
886
+ {
887
+ "name": "stdout",
888
+ "output_type": "stream",
889
+ "text": [
890
+ "ZS set: 200 | LP test set: 200\n"
891
+ ]
892
+ }
893
+ ],
894
  "source": [
895
  "# ── Cell 3.2: Load STL-10 test images ───────────────────────────────────────\n",
896
  "from torchvision import datasets\n",
 
904
  " (0.26862954, 0.26130258, 0.27577711))\n",
905
  "])\n",
906
  "\n",
907
+ "stl10_test = datasets.STL10(root='/workspace/raw_data', split='test', download=True,\n",
908
  " transform=clip_preprocess)\n",
909
  "\n",
910
  "STL10_CLASSES = stl10_test.classes\n",
 
937
  },
938
  {
939
  "cell_type": "code",
940
+ "execution_count": 12,
941
  "id": "0c99135b",
942
+ "metadata": {
943
+ "execution": {
944
+ "iopub.execute_input": "2026-05-30T01:08:07.729568Z",
945
+ "iopub.status.busy": "2026-05-30T01:08:07.729354Z",
946
+ "iopub.status.idle": "2026-05-30T01:08:08.214303Z",
947
+ "shell.execute_reply": "2026-05-30T01:08:08.213291Z"
948
+ }
949
+ },
950
+ "outputs": [
951
+ {
952
+ "name": "stdout",
953
+ "output_type": "stream",
954
+ "text": [
955
+ "Extracting embeddings...\n"
956
+ ]
957
+ },
958
+ {
959
+ "name": "stdout",
960
+ "output_type": "stream",
961
+ "text": [
962
+ "Zero-shot embeddings: (200, 512)\n",
963
+ "Linear probing test embeddings: (200, 512)\n"
964
+ ]
965
+ }
966
+ ],
967
  "source": [
968
  "# ── Cell 3.3: Extract CLIP image embeddings ──────────────────────────────────\n",
969
  "from torch.utils.data import DataLoader, TensorDataset\n",
 
991
  },
992
  {
993
  "cell_type": "code",
994
+ "execution_count": 13,
995
  "id": "61608dde",
996
+ "metadata": {
997
+ "execution": {
998
+ "iopub.execute_input": "2026-05-30T01:08:08.218031Z",
999
+ "iopub.status.busy": "2026-05-30T01:08:08.217685Z",
1000
+ "iopub.status.idle": "2026-05-30T01:08:08.258211Z",
1001
+ "shell.execute_reply": "2026-05-30T01:08:08.257368Z"
1002
+ }
1003
+ },
1004
+ "outputs": [
1005
+ {
1006
+ "name": "stdout",
1007
+ "output_type": "stream",
1008
+ "text": [
1009
+ "Text embeddings: (10, 512)\n"
1010
+ ]
1011
+ }
1012
+ ],
1013
  "source": [
1014
  "# ── Cell 3.4: Extract text embeddings untuk 10 kelas ────────────────────────\n",
1015
  "def get_text_embeddings(class_names, template=\"a photo of a {}\"):\n",
 
1028
  },
1029
  {
1030
  "cell_type": "code",
1031
+ "execution_count": 14,
1032
  "id": "5a113a9e",
1033
+ "metadata": {
1034
+ "execution": {
1035
+ "iopub.execute_input": "2026-05-30T01:08:08.261919Z",
1036
+ "iopub.status.busy": "2026-05-30T01:08:08.261731Z",
1037
+ "iopub.status.idle": "2026-05-30T01:08:08.864075Z",
1038
+ "shell.execute_reply": "2026-05-30T01:08:08.863083Z"
1039
+ }
1040
+ },
1041
  "outputs": [],
1042
  "source": [
1043
  "# ── Cell 3.5: Visualisasi t-SNE ─────────────────────────────────────────────\n",
 
1089
  },
1090
  {
1091
  "cell_type": "code",
1092
+ "execution_count": 15,
1093
  "id": "6d54f9b1",
1094
+ "metadata": {
1095
+ "execution": {
1096
+ "iopub.execute_input": "2026-05-30T01:08:08.868302Z",
1097
+ "iopub.status.busy": "2026-05-30T01:08:08.867825Z",
1098
+ "iopub.status.idle": "2026-05-30T01:08:08.882139Z",
1099
+ "shell.execute_reply": "2026-05-30T01:08:08.880819Z"
1100
+ }
1101
+ },
1102
+ "outputs": [
1103
+ {
1104
+ "name": "stdout",
1105
+ "output_type": "stream",
1106
+ "text": [
1107
+ "Zero-shot accuracy: 0.9700 (97.0%)\n"
1108
+ ]
1109
+ }
1110
+ ],
1111
  "source": [
1112
  "# ── Cell 4.1: Zero-shot prediction ──────────────────────────────────────────\n",
1113
  "# zs_embeddings dan text_embeddings sudah dihitung di Section 3\n",
 
1122
  },
1123
  {
1124
  "cell_type": "code",
1125
+ "execution_count": 16,
1126
  "id": "bfb07706",
1127
+ "metadata": {
1128
+ "execution": {
1129
+ "iopub.execute_input": "2026-05-30T01:08:08.886646Z",
1130
+ "iopub.status.busy": "2026-05-30T01:08:08.886415Z",
1131
+ "iopub.status.idle": "2026-05-30T01:08:08.943583Z",
1132
+ "shell.execute_reply": "2026-05-30T01:08:08.942419Z"
1133
+ }
1134
+ },
1135
+ "outputs": [
1136
+ {
1137
+ "name": "stdout",
1138
+ "output_type": "stream",
1139
+ "text": [
1140
+ "\n",
1141
+ "Prompt engineering comparison:\n",
1142
+ "--------------------------------------------------\n",
1143
+ " {} → 97.0%\n",
1144
+ " a photo of a {} → 97.0%\n",
1145
+ " a photo of a {}, high quality → 96.5%\n",
1146
+ " a {} in the wild → 96.0%\n"
1147
+ ]
1148
+ }
1149
+ ],
1150
  "source": [
1151
  "# ── Cell 4.2: Pengaruh prompt engineering ────────────────────────────────────\n",
1152
  "templates_to_compare = [\n",
 
1168
  },
1169
  {
1170
  "cell_type": "code",
1171
+ "execution_count": 17,
1172
  "id": "aa9db826",
1173
+ "metadata": {
1174
+ "execution": {
1175
+ "iopub.execute_input": "2026-05-30T01:08:08.947319Z",
1176
+ "iopub.status.busy": "2026-05-30T01:08:08.947076Z",
1177
+ "iopub.status.idle": "2026-05-30T01:08:09.015923Z",
1178
+ "shell.execute_reply": "2026-05-30T01:08:09.014911Z"
1179
+ }
1180
+ },
1181
  "outputs": [],
1182
  "source": [
1183
  "# ── Cell 4.3: Confusion matrix ───────────────────────────────────────────────\n",
 
1196
  },
1197
  {
1198
  "cell_type": "code",
1199
+ "execution_count": 18,
1200
  "id": "eb5c282d",
1201
+ "metadata": {
1202
+ "execution": {
1203
+ "iopub.execute_input": "2026-05-30T01:08:09.020221Z",
1204
+ "iopub.status.busy": "2026-05-30T01:08:09.019982Z",
1205
+ "iopub.status.idle": "2026-05-30T01:08:09.025774Z",
1206
+ "shell.execute_reply": "2026-05-30T01:08:09.024616Z"
1207
+ }
1208
+ },
1209
+ "outputs": [
1210
+ {
1211
+ "name": "stdout",
1212
+ "output_type": "stream",
1213
+ "text": [
1214
+ "\n",
1215
+ "Per-class accuracy:\n",
1216
+ " bird 100.0% ████████████████████\n",
1217
+ " dog 100.0% ████████████████████\n",
1218
+ " horse 100.0% ████████████████████\n",
1219
+ " monkey 100.0% ████████████████████\n",
1220
+ " ship 100.0% ████████████████████\n",
1221
+ " airplane 95.0% ███████████████████\n",
1222
+ " car 95.0% ███████████████████\n",
1223
+ " cat 95.0% ███████████████████\n",
1224
+ " deer 95.0% ███████████████████\n",
1225
+ " truck 90.0% ██████████████████\n"
1226
+ ]
1227
+ }
1228
+ ],
1229
  "source": [
1230
  "# ── Cell 4.4: Per-class accuracy ─────────────────────────────────────────────\n",
1231
  "per_class_acc = {}\n",
 
1262
  },
1263
  {
1264
  "cell_type": "code",
1265
+ "execution_count": 19,
1266
  "id": "c57f46c5",
1267
+ "metadata": {
1268
+ "execution": {
1269
+ "iopub.execute_input": "2026-05-30T01:08:09.029486Z",
1270
+ "iopub.status.busy": "2026-05-30T01:08:09.029279Z",
1271
+ "iopub.status.idle": "2026-05-30T01:08:15.811089Z",
1272
+ "shell.execute_reply": "2026-05-30T01:08:15.810407Z"
1273
+ }
1274
+ },
1275
+ "outputs": [
1276
+ {
1277
+ "name": "stdout",
1278
+ "output_type": "stream",
1279
+ "text": [
1280
+ "Extracting train embeddings...\n"
1281
+ ]
1282
+ },
1283
+ {
1284
+ "name": "stdout",
1285
+ "output_type": "stream",
1286
+ "text": [
1287
+ "Train embeddings: (1000, 512)\n"
1288
+ ]
1289
+ }
1290
+ ],
1291
  "source": [
1292
  "# ── Cell 5.1: Extract train embeddings untuk linear probing ─────────────────\n",
1293
+ "stl10_train = datasets.STL10(root='/workspace/raw_data', split='train', download=True,\n",
1294
  " transform=clip_preprocess)\n",
1295
  "\n",
1296
  "# Ambil 100/class = 1000 images untuk training\n",
 
1314
  },
1315
  {
1316
  "cell_type": "code",
1317
+ "execution_count": 20,
1318
  "id": "1dc5eed7",
1319
+ "metadata": {
1320
+ "execution": {
1321
+ "iopub.execute_input": "2026-05-30T01:08:15.815676Z",
1322
+ "iopub.status.busy": "2026-05-30T01:08:15.815477Z",
1323
+ "iopub.status.idle": "2026-05-30T01:08:17.308346Z",
1324
+ "shell.execute_reply": "2026-05-30T01:08:17.307666Z"
1325
+ }
1326
+ },
1327
+ "outputs": [
1328
+ {
1329
+ "name": "stdout",
1330
+ "output_type": "stream",
1331
+ "text": [
1332
+ "Linear probing accuracy: 0.9700 (97.0%)\n"
1333
+ ]
1334
+ }
1335
+ ],
1336
  "source": [
1337
  "# ── Cell 5.2: Train classifier ───────────────────────────────────────────────\n",
1338
  "from sklearn.linear_model import LogisticRegression\n",
 
1347
  },
1348
  {
1349
  "cell_type": "code",
1350
+ "execution_count": 21,
1351
  "id": "9832535f",
1352
+ "metadata": {
1353
+ "execution": {
1354
+ "iopub.execute_input": "2026-05-30T01:08:17.320194Z",
1355
+ "iopub.status.busy": "2026-05-30T01:08:17.319219Z",
1356
+ "iopub.status.idle": "2026-05-30T01:08:17.326850Z",
1357
+ "shell.execute_reply": "2026-05-30T01:08:17.325630Z"
1358
+ }
1359
+ },
1360
+ "outputs": [
1361
+ {
1362
+ "name": "stdout",
1363
+ "output_type": "stream",
1364
+ "text": [
1365
+ "\n",
1366
+ "==================================================\n",
1367
+ " Perbandingan: Zero-Shot vs Linear Probing\n",
1368
+ "==================================================\n",
1369
+ " Zero-shot (0 training images) : 97.0%\n",
1370
+ " Linear probe (1.000 labeled imgs) : 97.0%\n",
1371
+ " Gap: +0.0%\n",
1372
+ "==================================================\n"
1373
+ ]
1374
+ }
1375
+ ],
1376
  "source": [
1377
  "# ── Cell 5.3: Perbandingan zero-shot vs linear probing ───────────────────────\n",
1378
  "print(\"\\n\" + \"=\"*50)\n",
 
1386
  },
1387
  {
1388
  "cell_type": "code",
1389
+ "execution_count": 22,
1390
  "id": "69fafdc6",
1391
+ "metadata": {
1392
+ "execution": {
1393
+ "iopub.execute_input": "2026-05-30T01:08:17.329019Z",
1394
+ "iopub.status.busy": "2026-05-30T01:08:17.328815Z",
1395
+ "iopub.status.idle": "2026-05-30T01:08:17.437675Z",
1396
+ "shell.execute_reply": "2026-05-30T01:08:17.436433Z"
1397
+ }
1398
+ },
1399
  "outputs": [],
1400
  "source": [
1401
  "# ── Cell 5.4: Bar chart per-class comparison ─────────────────────────────────\n",
 
1444
  },
1445
  {
1446
  "cell_type": "code",
1447
+ "execution_count": 23,
1448
  "id": "4eac3bd2",
1449
+ "metadata": {
1450
+ "execution": {
1451
+ "iopub.execute_input": "2026-05-30T01:08:17.440562Z",
1452
+ "iopub.status.busy": "2026-05-30T01:08:17.440322Z",
1453
+ "iopub.status.idle": "2026-05-30T01:08:17.451847Z",
1454
+ "shell.execute_reply": "2026-05-30T01:08:17.450432Z"
1455
+ }
1456
+ },
1457
+ "outputs": [
1458
+ {
1459
+ "name": "stdout",
1460
+ "output_type": "stream",
1461
+ "text": [
1462
+ "Retrieval test: 200 queries\n",
1463
+ " id image_path caption_0 \\\n",
1464
+ "0 ret_0001 ret_0001.jpg A couple of people sit outdoors at a table wit... \n",
1465
+ "1 ret_0002 ret_0002.jpg A brown and white dog stands outside while it ... \n",
1466
+ "\n",
1467
+ " caption_1 \\\n",
1468
+ "0 A couple in an embrace looking at each other . \n",
1469
+ "1 A girl with dark brown hair and eyes in a blue... \n",
1470
+ "\n",
1471
+ " caption_2 \\\n",
1472
+ "0 A girl 's hands , another person 's feet , and... \n",
1473
+ "1 A brown and white greyhound wearing a red numb... \n",
1474
+ "\n",
1475
+ " caption_3 correct_idx \n",
1476
+ "0 A long haired drummer plays music outdoors . 0 \n",
1477
+ "1 a boy on skateboard is making a jump from a bl... 1 \n"
1478
+ ]
1479
+ }
1480
+ ],
1481
  "source": [
1482
  "# ── Cell 6.1: Load Flickr8k test data ────────────────────────────────────────\n",
1483
  "import pandas as pd\n",
1484
  "from PIL import Image as PILImage\n",
1485
  "\n",
1486
+ "DATASET_ROOT = '/workspace/output/clip-pelatnas-p2'\n",
1487
  "candidates_df = pd.read_csv(f'{DATASET_ROOT}/test/retrieval/candidates.csv')\n",
1488
  "print(f\"Retrieval test: {len(candidates_df)} queries\")\n",
1489
  "print(candidates_df.head(2))\n"
 
1491
  },
1492
  {
1493
  "cell_type": "code",
1494
+ "execution_count": 24,
1495
  "id": "876b6c60",
1496
+ "metadata": {
1497
+ "execution": {
1498
+ "iopub.execute_input": "2026-05-30T01:08:17.454380Z",
1499
+ "iopub.status.busy": "2026-05-30T01:08:17.454178Z",
1500
+ "iopub.status.idle": "2026-05-30T01:08:17.459992Z",
1501
+ "shell.execute_reply": "2026-05-30T01:08:17.458850Z"
1502
+ }
1503
+ },
1504
  "outputs": [],
1505
  "source": [
1506
  "# ── Cell 6.2: CLIP retrieval pipeline ────────────────────────────────────────\n",
 
1526
  },
1527
  {
1528
  "cell_type": "code",
1529
+ "execution_count": 25,
1530
  "id": "70ca735c",
1531
+ "metadata": {
1532
+ "execution": {
1533
+ "iopub.execute_input": "2026-05-30T01:08:17.462830Z",
1534
+ "iopub.status.busy": "2026-05-30T01:08:17.462361Z",
1535
+ "iopub.status.idle": "2026-05-30T01:08:21.346917Z",
1536
+ "shell.execute_reply": "2026-05-30T01:08:21.345877Z"
1537
+ }
1538
+ },
1539
+ "outputs": [
1540
+ {
1541
+ "name": "stdout",
1542
+ "output_type": "stream",
1543
+ "text": [
1544
+ "Retrieval accuracy (4-way): 0.9400 (94.0%)\n",
1545
+ "Random baseline: 25.0%\n"
1546
+ ]
1547
+ }
1548
+ ],
1549
  "source": [
1550
  "# ── Cell 6.3: Batch evaluation ────────────────────────────────────────────────\n",
1551
  "base_path = f'{DATASET_ROOT}/test/retrieval/queries/'\n",
 
1568
  },
1569
  {
1570
  "cell_type": "code",
1571
+ "execution_count": 26,
1572
  "id": "0c01f0d0",
1573
+ "metadata": {
1574
+ "execution": {
1575
+ "iopub.execute_input": "2026-05-30T01:08:21.351698Z",
1576
+ "iopub.status.busy": "2026-05-30T01:08:21.351462Z",
1577
+ "iopub.status.idle": "2026-05-30T01:08:21.553840Z",
1578
+ "shell.execute_reply": "2026-05-30T01:08:21.552682Z"
1579
+ }
1580
+ },
1581
  "outputs": [],
1582
  "source": [
1583
  "# ── Cell 6.4: Qualitative examples ───────────────────────────────────────────\n",
 
1638
  },
1639
  {
1640
  "cell_type": "code",
1641
+ "execution_count": 27,
1642
  "id": "bd004ef7",
1643
+ "metadata": {
1644
+ "execution": {
1645
+ "iopub.execute_input": "2026-05-30T01:08:21.558193Z",
1646
+ "iopub.status.busy": "2026-05-30T01:08:21.557954Z",
1647
+ "iopub.status.idle": "2026-05-30T01:08:21.567638Z",
1648
+ "shell.execute_reply": "2026-05-30T01:08:21.566348Z"
1649
+ }
1650
+ },
1651
+ "outputs": [
1652
+ {
1653
+ "name": "stdout",
1654
+ "output_type": "stream",
1655
+ "text": [
1656
+ "MCQA test: 200 questions\n",
1657
+ " id image_path \\\n",
1658
+ "0 mcqa_0001 mcqa_0001.png \n",
1659
+ "1 mcqa_0002 mcqa_0002.png \n",
1660
+ "\n",
1661
+ " question choice_A choice_B \\\n",
1662
+ "0 Which continent is highlighted? Africa North America \n",
1663
+ "1 Which property do these four objects have in c... fragile stretchy \n",
1664
+ "\n",
1665
+ " choice_C choice_D choice_E num_choices subject grade \n",
1666
+ "0 Europe Asia NaN 4 social science grade7 \n",
1667
+ "1 sour NaN NaN 3 natural science grade5 \n"
1668
+ ]
1669
+ }
1670
+ ],
1671
  "source": [
1672
  "# ── Cell 7.1: Load ScienceQA test data ──────────────────────────────────────\n",
1673
  "mcqa_df = pd.read_csv(f'{DATASET_ROOT}/test/mcqa/test.csv')\n",
 
1677
  },
1678
  {
1679
  "cell_type": "code",
1680
+ "execution_count": 28,
1681
  "id": "3fedf9ce",
1682
+ "metadata": {
1683
+ "execution": {
1684
+ "iopub.execute_input": "2026-05-30T01:08:21.571029Z",
1685
+ "iopub.status.busy": "2026-05-30T01:08:21.570792Z",
1686
+ "iopub.status.idle": "2026-05-30T01:08:21.577861Z",
1687
+ "shell.execute_reply": "2026-05-30T01:08:21.576438Z"
1688
+ }
1689
+ },
1690
  "outputs": [],
1691
  "source": [
1692
  "# ── Cell 7.2: CLIP MCQA pipeline ─────────────────────────────────────────────\n",
 
1715
  },
1716
  {
1717
  "cell_type": "code",
1718
+ "execution_count": 29,
1719
  "id": "80755731",
1720
+ "metadata": {
1721
+ "execution": {
1722
+ "iopub.execute_input": "2026-05-30T01:08:21.580942Z",
1723
+ "iopub.status.busy": "2026-05-30T01:08:21.580701Z",
1724
+ "iopub.status.idle": "2026-05-30T01:08:25.613344Z",
1725
+ "shell.execute_reply": "2026-05-30T01:08:25.612552Z"
1726
+ }
1727
+ },
1728
+ "outputs": [
1729
+ {
1730
+ "name": "stdout",
1731
+ "output_type": "stream",
1732
+ "text": [
1733
+ "MCQA predictions done (answer column not available in test set)\n",
1734
+ "Random baseline (~3.5 choices avg): ~28.6%\n"
1735
+ ]
1736
+ }
1737
+ ],
1738
  "source": [
1739
  "# ── Cell 7.3: Batch evaluation ────────────────────────────────────────────────\n",
1740
  "base_path_mcqa = f'{DATASET_ROOT}/test/mcqa/images/'\n",
 
1759
  },
1760
  {
1761
  "cell_type": "code",
1762
+ "execution_count": 30,
1763
  "id": "0b34a2f3",
1764
+ "metadata": {
1765
+ "execution": {
1766
+ "iopub.execute_input": "2026-05-30T01:08:25.615571Z",
1767
+ "iopub.status.busy": "2026-05-30T01:08:25.615332Z",
1768
+ "iopub.status.idle": "2026-05-30T01:08:25.623214Z",
1769
+ "shell.execute_reply": "2026-05-30T01:08:25.622425Z"
1770
+ }
1771
+ },
1772
+ "outputs": [
1773
+ {
1774
+ "name": "stdout",
1775
+ "output_type": "stream",
1776
+ "text": [
1777
+ "Question count per subject:\n",
1778
+ " language science 44 questions\n",
1779
+ " natural science 82 questions\n",
1780
+ " social science 74 questions\n"
1781
+ ]
1782
+ }
1783
+ ],
1784
  "source": [
1785
  "# ── Cell 7.4: Analysis per subject ───────────────────────────────────────────\n",
1786
  "mcqa_df_copy = mcqa_df.copy()\n",
 
1825
  },
1826
  {
1827
  "cell_type": "code",
1828
+ "execution_count": 31,
1829
  "id": "98109b5f",
1830
+ "metadata": {
1831
+ "execution": {
1832
+ "iopub.execute_input": "2026-05-30T01:08:25.625351Z",
1833
+ "iopub.status.busy": "2026-05-30T01:08:25.625185Z",
1834
+ "iopub.status.idle": "2026-05-30T01:08:25.631943Z",
1835
+ "shell.execute_reply": "2026-05-30T01:08:25.631245Z"
1836
+ }
1837
+ },
1838
  "outputs": [],
1839
  "source": [
1840
  "# ── Cell 8.1: Compile semua prediksi ─────────────────────────────────────────\n",
 
1865
  },
1866
  {
1867
  "cell_type": "code",
1868
+ "execution_count": 32,
1869
  "id": "0675c9b8",
1870
+ "metadata": {
1871
+ "execution": {
1872
+ "iopub.execute_input": "2026-05-30T01:08:25.634244Z",
1873
+ "iopub.status.busy": "2026-05-30T01:08:25.634046Z",
1874
+ "iopub.status.idle": "2026-05-30T01:08:25.647532Z",
1875
+ "shell.execute_reply": "2026-05-30T01:08:25.646412Z"
1876
+ }
1877
+ },
1878
+ "outputs": [
1879
+ {
1880
+ "name": "stdout",
1881
+ "output_type": "stream",
1882
+ "text": [
1883
+ "Submission preview (2 per task):\n",
1884
+ " id prediction\n",
1885
+ "zs_0001 horse\n",
1886
+ "zs_0002 monkey\n",
1887
+ "\n",
1888
+ " id prediction\n",
1889
+ "lp_0001 bird\n",
1890
+ "lp_0002 bird\n",
1891
+ "\n",
1892
+ " id prediction\n",
1893
+ "ret_0001 0\n",
1894
+ "ret_0002 1\n",
1895
+ "\n",
1896
+ " id prediction\n",
1897
+ "mcqa_0001 B\n",
1898
+ "mcqa_0002 B\n",
1899
+ "\n",
1900
+ "Saved: submission.csv (800 rows)\n"
1901
+ ]
1902
+ }
1903
+ ],
1904
  "source": [
1905
  "# ── Cell 8.2: Generate submission ────────────────────────────────────────────\n",
1906
  "submission = sample_sub.copy()\n",
 
1921
  },
1922
  {
1923
  "cell_type": "code",
1924
+ "execution_count": 33,
1925
  "id": "9fcd617f",
1926
+ "metadata": {
1927
+ "execution": {
1928
+ "iopub.execute_input": "2026-05-30T01:08:25.650270Z",
1929
+ "iopub.status.busy": "2026-05-30T01:08:25.649862Z",
1930
+ "iopub.status.idle": "2026-05-30T01:08:25.658680Z",
1931
+ "shell.execute_reply": "2026-05-30T01:08:25.657211Z"
1932
+ }
1933
+ },
1934
+ "outputs": [
1935
+ {
1936
+ "name": "stdout",
1937
+ "output_type": "stream",
1938
+ "text": [
1939
+ "Distribusi prediksi per task:\n",
1940
+ "\n",
1941
+ " Zero-shot (200 items): {'horse': 21, 'monkey': 21, 'dog': 21, 'car': 21, 'ship': 21, 'bird': 20, 'airplane': 19, 'cat': 19, 'deer': 19, 'truck': 18}\n",
1942
+ " Linear probe (200 items): {'bird': 21, 'deer': 21, 'dog': 21, 'car': 21, 'ship': 20, 'airplane': 20, 'horse': 20, 'monkey': 19, 'truck': 19, 'cat': 18}\n",
1943
+ " Retrieval (200 items): {1: 60, 3: 58, 0: 46, 2: 36}\n",
1944
+ " MCQA (200 items): {'A': 77, 'B': 76, 'C': 29, 'D': 17, 'E': 1}\n"
1945
+ ]
1946
+ }
1947
+ ],
1948
  "source": [
1949
  "# ── Cell 8.3: Sanity check ────────────────────────────────────────────────────\n",
1950
  "print(\"Distribusi prediksi per task:\\n\")\n",
 
1959
  ],
1960
  "metadata": {
1961
  "kernelspec": {
1962
+ "display_name": "Python3 (main venv)",
1963
  "language": "python",
1964
+ "name": "main"
1965
  },
1966
  "language_info": {
1967
+ "codemirror_mode": {
1968
+ "name": "ipython",
1969
+ "version": 3
1970
+ },
1971
+ "file_extension": ".py",
1972
+ "mimetype": "text/x-python",
1973
  "name": "python",
1974
+ "nbconvert_exporter": "python",
1975
+ "pygments_lexer": "ipython3",
1976
+ "version": "3.12.13"
1977
  }
1978
  },
1979
  "nbformat": 4,