File size: 93,085 Bytes
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
 
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
 
 
 
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
da59d46
3916521
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
da59d46
 
 
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
 
 
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
 
3916521
 
 
 
 
da59d46
3916521
 
 
da59d46
 
3916521
 
 
 
 
 
 
 
 
 
 
 
da59d46
 
 
3916521
 
da59d46
3916521
 
 
 
 
 
da59d46
 
3916521
da59d46
3916521
da59d46
 
3916521
da59d46
3916521
 
da59d46
 
 
 
 
 
 
 
 
 
 
 
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
da59d46
 
 
 
 
3916521
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
da59d46
 
 
 
 
 
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
 
 
3916521
 
da59d46
 
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
da59d46
3916521
 
da59d46
3916521
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
 
 
3916521
 
da59d46
3916521
 
da59d46
 
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
 
 
3916521
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
da59d46
 
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
 
 
3916521
 
da59d46
3916521
 
 
 
 
 
da59d46
 
3916521
da59d46
3916521
da59d46
 
3916521
da59d46
3916521
 
da59d46
 
 
 
 
 
 
 
 
 
 
 
3916521
da59d46
 
 
 
 
 
 
 
 
 
 
 
3916521
da59d46
 
 
 
 
 
 
 
 
 
 
 
3916521
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
da59d46
3916521
 
da59d46
3916521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7eb11cd7-6200-45f9-822f-45b8b392c4bd",
   "metadata": {},
   "source": [
    "# Setup"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4ca90151-0b89-4870-8213-9d49cb68c555",
   "metadata": {},
   "source": [
    "## Config\n",
    "Set the tokens based on the numbers in [02-poe-token-count-exploration.ipynb](02-poe-token-count-exploration.ipynb). I like to give a little buffer in-case an explanation goes over."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5238c6e9-9425-4ced-a16a-998e775e7342",
   "metadata": {},
   "outputs": [],
   "source": [
    "INPUT_TOKENS = 300\n",
    "OUTPUT_TOKENS = 1600\n",
    "\n",
    "INPUT_DATASET = 'derek-thomas/labeled-multiple-choice-explained-mistral-tokenized'\n",
    "OUTPUT_DATASET = 'derek-thomas/labeled-multiple-choice-explained-mistral-results'\n",
    "BASE_MODEL = 'mistralai/Mistral-7B-Instruct-v0.3'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f4eca659-f11f-4d25-886a-9d7af4f38411",
   "metadata": {},
   "source": [
    "# Setup\n",
    "Here we create the pydantic models for each of our experiments. Note because of how you specify field names in pydantic, we need to use an `alias` and `populate_by_name`. Given that our `Final Answer` is always a letter between a-h we can use an enumeration."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c5367700-0e9d-435b-875a-02a73b292ade",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pydantic import BaseModel, Field\n",
    "from typing import List\n",
    "from enum import Enum\n",
    "import json\n",
    "\n",
    "\n",
    "class FinalAnswerEnum(str, Enum):\n",
    "    a = \"a\"\n",
    "    b = \"b\"\n",
    "    c = \"c\"\n",
    "    d = \"d\"\n",
    "    e = \"e\"\n",
    "    f = \"f\"\n",
    "    g = \"g\"\n",
    "    h = \"h\"\n",
    "\n",
    "class RFAModel(BaseModel):\n",
    "    reasoning: str = Field(..., alias=\"Reasoning\")\n",
    "    final_answer: FinalAnswerEnum = Field(..., alias=\"Final Answer\")\n",
    "\n",
    "    class Config:\n",
    "        populate_by_name = True\n",
    "        \n",
    "class FARModel(BaseModel):\n",
    "    final_answer: FinalAnswerEnum = Field(..., alias=\"Final Answer\")\n",
    "    reasoning: str = Field(..., alias=\"Reasoning\")\n",
    "\n",
    "    class Config:\n",
    "        populate_by_name = True\n",
    "        \n",
    "class FAModel(BaseModel):\n",
    "    final_answer: FinalAnswerEnum = Field(..., alias=\"Final Answer\")\n",
    "\n",
    "    class Config:\n",
    "        populate_by_name = True"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7e0f51c0-c4f7-4299-9a24-a4a90d4a9f2a",
   "metadata": {},
   "source": [
    "We generated lots of experiments in [derek-thomas/labeled-multiple-choice-explained-mistral-tokenized](https://huggingface.co/datasets/derek-thomas/labeled-multiple-choice-explained-mistral-tokenized/viewer?row=0). Now we will aggregate everything we need in `experiments` for convenience."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5d0bd22f-293e-4c15-9dfe-8070553f42b5",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'derek-thomas/mistral-v03-poe-RFA-mistral,derek-thomas/mistral-v03-poe-FAR-mistral,derek-thomas/mistral-v03-poe-RFA-gpt3-5,derek-thomas/mistral-v03-poe-FAR-gpt3-5,derek-thomas/mistral-v03-poe-FA'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "experiments = {\n",
    "    'RFA-mistral': {\n",
    "        'pydantic': RFAModel,\n",
    "        \"lora\": \"derek-thomas/mistral-v03-poe-RFA-mistral\",\n",
    "        \"column\": 'user_prompt_RFA',\n",
    "    },\n",
    "    'FAR-mistral': {\n",
    "        'pydantic': FARModel,\n",
    "        \"lora\": \"derek-thomas/mistral-v03-poe-FAR-mistral\",\n",
    "        \"column\": 'user_prompt_FAR',\n",
    "    },\n",
    "    'RFA-gpt3-5': {\n",
    "        'pydantic': RFAModel,\n",
    "        \"lora\": \"derek-thomas/mistral-v03-poe-RFA-gpt3-5\",\n",
    "        \"column\": 'user_prompt_RFA',\n",
    "    },\n",
    "    'FAR-gpt3-5': {\n",
    "        'pydantic': FARModel,\n",
    "        \"lora\": \"derek-thomas/mistral-v03-poe-FAR-gpt3-5\",\n",
    "        \"column\": 'user_prompt_FAR',\n",
    "    },\n",
    "    'FA': {\n",
    "        'pydantic': FAModel,\n",
    "        \"lora\": \"derek-thomas/mistral-v03-poe-FA\",\n",
    "        \"column\": 'user_prompt_FA',\n",
    "    },\n",
    "    'base': {\n",
    "        'pydantic': FAModel,\n",
    "        \"lora\": None,\n",
    "        \"column\": 'user_prompt_FA',\n",
    "    },\n",
    "}\n",
    "\n",
    "LORAS_STRING = ','.join([v['lora'] for _, v in experiments.items() if v and v.get('lora') is not None])\n",
    "LORAS_STRING"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6f8826fb-76ea-464f-8146-262bda0b58bc",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "50dbecc676db4dc78dd1974d2f1a87dc",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "VBox(children=(HTML(value='<center> <img\\nsrc=https://huggingface.co/front/assets/huggingface_logo-noborder.sv…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from huggingface_hub import login, get_token\n",
    "\n",
    "# Log in to your Hugging Face account\n",
    "login()  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a9e2d29c-1f8e-4a70-839f-f61ae396d6f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "from transformers import AutoTokenizer\n",
    "\n",
    "tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL, token=get_token())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3aa16403-88e4-4eba-a45b-3d91db9bb58d",
   "metadata": {},
   "outputs": [],
   "source": [
    "from datasets import load_dataset\n",
    "\n",
    "# Load dataset (test split)\n",
    "dataset = load_dataset(INPUT_DATASET, split='test')\n",
    "df = dataset.to_pandas()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c787fbb8-beae-4bb0-860d-0ce4d0c9b9a4",
   "metadata": {},
   "source": [
    "# Evaluation"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a35d4955-61e5-4143-ab92-7e9b8a49ea1b",
   "metadata": {},
   "source": [
    "## Endpoint Configuration\n",
    "Im using 8 replicas so I can move quickly! The try/except is in-case I need to make manual changes and I want to load the endpoint."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "619fbe5e-e35d-430b-a617-9223ba6babd0",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from huggingface_hub import create_inference_endpoint\n",
    "from huggingface_hub import get_inference_endpoint\n",
    "\n",
    "\n",
    "def get_my_endpoint():\n",
    "    name = f\"prompt-order-experiment\"\n",
    "    namespace='derek-thomas'\n",
    "    try:\n",
    "        endpoint = get_inference_endpoint(name, namespace=namespace)\n",
    "    except:\n",
    "        # Custom Docker image details\n",
    "        custom_image = {\n",
    "            \"health_route\": \"/health\",\n",
    "            \"url\": \"ghcr.io/huggingface/text-generation-inference:sha-caff779\",  # Needs to be >=2.4.2 to get ordering of json outputs\n",
    "            \"env\": {\n",
    "                \"LORA_ADAPTERS\": LORAS_STRING,\n",
    "                \"MAX_BATCH_PREFILL_TOKENS\": str(20*INPUT_TOKENS),\n",
    "                \"MAX_INPUT_TOKENS\": str(INPUT_TOKENS), \n",
    "                \"MAX_TOTAL_TOKENS\": str(INPUT_TOKENS + OUTPUT_TOKENS), \n",
    "                \"DISABLE_CUSTOM_KERNELS\": 'false',\n",
    "                \"MODEL_ID\": \"/repository\"\n",
    "            },\n",
    "        }\n",
    "        \n",
    "        secrets = {\n",
    "            \"HF_TOKEN\": get_token()\n",
    "        }\n",
    "        \n",
    "        # Creating the inference endpoint\n",
    "        endpoint = create_inference_endpoint(\n",
    "            name=name,\n",
    "            namespace=namespace,\n",
    "            repository='mistralai/Mistral-7B-Instruct-v0.3',\n",
    "            framework=\"pytorch\",\n",
    "            accelerator=\"gpu\",\n",
    "            instance_size=\"x1\",\n",
    "            instance_type=\"nvidia-l4\",\n",
    "            region=\"us-east-1\",\n",
    "            vendor=\"aws\",\n",
    "            min_replica=8,\n",
    "            max_replica=8,\n",
    "            task=\"text-generation\",\n",
    "            custom_image=custom_image,\n",
    "            secrets=secrets\n",
    "        )\n",
    "            \n",
    "    print(\"Your model is ready to use!\")\n",
    "    endpoint.wait()\n",
    "    return endpoint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "000b907a-224d-4dbf-aa0d-e0dbee1b8787",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Your model is ready to use!\n",
      "CPU times: user 21.1 ms, sys: 10 ms, total: 31.1 ms\n",
      "Wall time: 1.72 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "endpoint = get_my_endpoint()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5708f348-c11e-4b66-aeff-93f5ec08ab49",
   "metadata": {},
   "source": [
    "## Manual Evaluation\n",
    "Since we havent seen our models in use yet, its a good time to check them out!"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "328dd842-eaa4-470c-b761-7c403b453321",
   "metadata": {},
   "source": [
    "### Reasoning Final Answer\n",
    "In both mistral and gpt3-5 we should see the **Reasoning** first and then the **Final Answer** in the prompt and the responses."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "47af6191-7765-4047-bd8f-64aadb08434e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'<s>[INST] Answer the Question and include your Reasoning and the Final Answer in a json like: {\"Reasoning: \"...\", \"Final Answer\": \"x\"} where x is a letter that corresponds to the answer choice which is a letter between a and h.\\nQuestion: What are busses used for?\\nAnswer Choices: (a) Protective shelter (b) Transporting humans (c) Help other species benefit (d) Transporting airplanes (e) A backbone (f) Communication (g) Safe operation (h) Safe driving[/INST]'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "key = 'RFA-mistral'\n",
    "user_prompt_RFA = df.iloc[0][experiments[key]['column']]\n",
    "user_prompt_RFA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "1f976218-f33c-4db3-9797-3935e121e6b2",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\"Reasoning\": \"Busses are primarily used for transporting people, so the correct answer is (b) Transporting humans. The other options are not related to the function of a bus.\", \"Final Answer\": \"b\"}'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response = endpoint.client.text_generation(\n",
    "    prompt=user_prompt_RFA,\n",
    "    max_new_tokens=OUTPUT_TOKENS,\n",
    "    adapter_id=experiments[key]['lora'],\n",
    "    grammar={\"type\": \"json\", \"value\": experiments[key]['pydantic'].schema()},\n",
    ")\n",
    "response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "222e33b7-0158-44f8-8848-da5318e699b4",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\"Reasoning\": \"Busses are primarily used for transporting humans, especially in urban areas where public transportation is necessary. They provide a means of transportation for a large number of people at once, reducing traffic congestion and carbon emissions. Therefore, the correct answer is (b) transporting humans.\", \"Final Answer\": \"b\"}'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "key = 'RFA-gpt3-5'\n",
    "response = endpoint.client.text_generation(\n",
    "    prompt=user_prompt_RFA,\n",
    "    max_new_tokens=OUTPUT_TOKENS,\n",
    "    adapter_id=experiments[key]['lora'],\n",
    "    grammar={\"type\": \"json\", \"value\": experiments[key]['pydantic'].schema()},\n",
    ")\n",
    "response"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "138fd46d-896f-4b4b-90d3-d3fd7075f149",
   "metadata": {},
   "source": [
    "### Final Answer Reasoning \n",
    "In both mistral and gpt3-5 we should see the **Final Answer** first and then the **Reasoning** in the prompt and the responses."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "ec3e574b-f63f-4513-a6ae-335136543a8c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'<s>[INST] Answer the Question and include your Final Answer and the Reasoning in a json like: {\"Final Answer\": \"x\", \"Reasoning: \"...\"} where x is a letter that corresponds to the answer choice which is a letter between a and h.\\nQuestion: What are busses used for?\\nAnswer Choices: (a) Protective shelter (b) Transporting humans (c) Help other species benefit (d) Transporting airplanes (e) A backbone (f) Communication (g) Safe operation (h) Safe driving[/INST]'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "key = 'FAR-gpt3-5'\n",
    "user_prompt_FAR = df.iloc[0][experiments[key]['column']]\n",
    "user_prompt_FAR"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "24f30a15-5ec0-4f26-b32f-b4ccb429e6f9",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\"Final Answer\": \"b\", \"Reasoning\": \"Busses are primarily used for transporting humans, especially in urban areas, to facilitate commuting and travel. They are not used for protective shelter, helping other species benefit, transporting airplanes, serving as a backbone, communication, safe operation, or safe driving.\"}'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response = endpoint.client.text_generation(\n",
    "    prompt=user_prompt_FAR,\n",
    "    max_new_tokens=575,\n",
    "    adapter_id=experiments[key]['lora'],\n",
    "    grammar={\"type\": \"json\", \"value\": experiments[key]['pydantic'].schema()},\n",
    ")\n",
    "response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "32536844-211d-4856-983c-d5787734d420",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\"Final Answer\": \"b\", \"Reasoning\": \"Busses are primarily used for transporting humans, especially in urban areas, to facilitate their travel from one place to another. The other options are incorrect because busses do not provide protective shelter, do not help other species benefit, are not used to transport airplanes, do not serve as a backbone, are not used for communication, and are not related to safe operation or driving.\"}'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "key = 'FAR-mistral'\n",
    "response = endpoint.client.text_generation(\n",
    "    prompt=user_prompt_FAR,\n",
    "    max_new_tokens=575,\n",
    "    adapter_id=experiments[key]['lora'],\n",
    "    grammar={\"type\": \"json\", \"value\": experiments[key]['pydantic'].schema()},\n",
    ")\n",
    "response"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5482cf12-880c-4112-ba87-059a03a3f466",
   "metadata": {},
   "source": [
    "### Final Answer \n",
    "Here we should juse see the **Final Answer** and no **Reasoning**."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "71a9f634-319c-40c2-8f66-18e282732320",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'<s>[INST] Answer the Question and include your Final Answer in a json like: {\"Final Answer\": \"x\"} where x is a letter that corresponds to the answer choice which is a letter between a and h.\\nQuestion: What are busses used for?\\nAnswer Choices: (a) Protective shelter (b) Transporting humans (c) Help other species benefit (d) Transporting airplanes (e) A backbone (f) Communication (g) Safe operation (h) Safe driving[/INST]'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "key = 'FA'\n",
    "user_prompt_FA = df.iloc[0][experiments[key]['column']]\n",
    "user_prompt_FA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "1cded37d-b907-4f4d-9b8c-c2167c6ba213",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"{'Final Answer': 'b'}\""
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response = endpoint.client.text_generation(\n",
    "    prompt=user_prompt_FA,\n",
    "    max_new_tokens=575,\n",
    "    adapter_id=experiments[key]['lora'],\n",
    ")\n",
    "response"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "122b8563-3220-43ac-9e0d-ef84ebcbb9e1",
   "metadata": {},
   "source": [
    "## Evaluation Loop\n",
    "I used 20x the prefill than the input and 8 replicas so I should capacity for ~160 parallel requests. Im only using 128 but it should be pretty fast."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "fbc69ea7-e2ca-4405-82f0-5af95375ec88",
   "metadata": {},
   "outputs": [],
   "source": [
    "import nest_asyncio\n",
    "import asyncio\n",
    "from transformers import AutoTokenizer\n",
    "from tqdm.auto import tqdm\n",
    "\n",
    "# Allow nested event loops in Jupyter\n",
    "nest_asyncio.apply()\n",
    "\n",
    "\n",
    "# Semaphore to limit concurrency\n",
    "CONCURRENCY_LIMIT = 100 \n",
    "MAX_NEW_TOKENS = OUTPUT_TOKENS\n",
    "semaphore = asyncio.Semaphore(CONCURRENCY_LIMIT)\n",
    "\n",
    "# Progress bar\n",
    "progress_bar = None  # Global to allow updates from within async functions\n",
    "\n",
    "# Function to send asynchronous requests to the endpoint\n",
    "async def fetch_response_async(async_client, prompt, lora_id, pydantic_model):\n",
    "    async with semaphore:  # Limit the number of concurrent requests\n",
    "        response = await async_client.text_generation(\n",
    "            prompt=prompt,\n",
    "            max_new_tokens=MAX_NEW_TOKENS,\n",
    "            adapter_id=lora_id if lora_id else None,\n",
    "            grammar={\"type\": \"json\", \"value\": pydantic_model.schema()}\n",
    "        )\n",
    "        progress_bar.update(1)  # Update the progress bar when the request is complete\n",
    "        return response\n",
    "\n",
    "# Function to process a single conversation type asynchronously\n",
    "async def process_conversation_type(conversation_type, model_info, df, tokenizer, async_client):\n",
    "    response_column = f\"responses_{conversation_type.replace('-','_')}\"\n",
    "    responses = []  # Temporary list to hold responses for the current conversation type\n",
    "\n",
    "    tasks = []\n",
    "    for _, item in df.iterrows():\n",
    "        prompt = item.get(model_info[\"column\"])\n",
    "        tasks.append(fetch_response_async(async_client, prompt, model_info[\"lora\"], model_info[\"pydantic\"]))\n",
    "\n",
    "    # Wait for all tasks to complete\n",
    "    responses = await asyncio.gather(*tasks)\n",
    "\n",
    "    # If responses are strings, use them directly; otherwise, extract 'generated_text'\n",
    "    try:\n",
    "        df[response_column] = [resp[\"generated_text\"] for resp in responses]\n",
    "    except TypeError:  # Fallback in case responses are raw strings\n",
    "        df[response_column] = responses\n",
    "\n",
    "# Main function to handle all conversation types\n",
    "async def main(df, models, tokenizer, async_client):\n",
    "    global progress_bar\n",
    "    total_requests = len(df) * len(models)  # Total number of requests across all conversation types\n",
    "    progress_bar = tqdm(total=total_requests, desc=\"Processing requests\")\n",
    "\n",
    "    tasks = []\n",
    "    for conversation_type, model_info in models.items():\n",
    "        tasks.append(process_conversation_type(conversation_type, model_info, df, tokenizer, async_client))\n",
    "    await asyncio.gather(*tasks)\n",
    "\n",
    "    progress_bar.close()  # Close the progress bar when done\n",
    "\n",
    "# Define parameters and run\n",
    "# await main(df, experiments, tokenizer, endpoint.async_client)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9662adde-4ea4-4254-a6be-c619ed9557c8",
   "metadata": {},
   "source": [
    "This is the same as above but with a couple nice features like time-out in case you run into any issues."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "e2671c78-6cd1-4bb7-aa04-b695bfb02115",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "be0bd3e278ae4d90a161918772ee71e8",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Processing requests:   0%|          | 0/10098 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import nest_asyncio\n",
    "import asyncio\n",
    "from transformers import AutoTokenizer\n",
    "from tqdm.auto import tqdm\n",
    "import time\n",
    "\n",
    "# Allow nested event loops in Jupyter\n",
    "nest_asyncio.apply()\n",
    "\n",
    "# Semaphore to limit concurrency\n",
    "CONCURRENCY_LIMIT = 100 \n",
    "MAX_NEW_TOKENS = OUTPUT_TOKENS\n",
    "semaphore = asyncio.Semaphore(CONCURRENCY_LIMIT)\n",
    "\n",
    "# Progress bar\n",
    "progress_bar = None  # Global to allow updates from within async functions\n",
    "\n",
    "# Retry parameters\n",
    "MAX_RETRIES = 3\n",
    "BACKOFF_TIME = 2  # Time in seconds before retrying\n",
    "\n",
    "# Function to send asynchronous requests to the endpoint with retries\n",
    "async def fetch_response_async(async_client, prompt, lora_id, pydantic_model):\n",
    "    retries = 0\n",
    "    while retries < MAX_RETRIES:\n",
    "        try:\n",
    "            async with semaphore:  # Limit the number of concurrent requests\n",
    "                response = await async_client.text_generation(\n",
    "                    prompt=prompt,\n",
    "                    max_new_tokens=MAX_NEW_TOKENS,\n",
    "                    adapter_id=lora_id if lora_id else None,\n",
    "                    grammar={\"type\": \"json\", \"value\": pydantic_model.schema()}\n",
    "                )\n",
    "                progress_bar.update(1)  # Update the progress bar when the request is complete\n",
    "                return response\n",
    "        except Exception as e:\n",
    "            retries += 1\n",
    "            if retries >= MAX_RETRIES:\n",
    "                raise e  # If we've exhausted retries, re-raise the error\n",
    "            else:\n",
    "                print(f\"Error: {e}. Retrying... ({retries}/{MAX_RETRIES})\")\n",
    "                await asyncio.sleep(BACKOFF_TIME)  # Wait before retrying\n",
    "\n",
    "# Function to process a single conversation type asynchronously\n",
    "async def process_conversation_type(conversation_type, model_info, df, tokenizer, async_client):\n",
    "    response_column = f\"responses_{conversation_type.replace('-','_')}\"\n",
    "    responses = []  # Temporary list to hold responses for the current conversation type\n",
    "\n",
    "    tasks = []\n",
    "    for _, item in df.iterrows():\n",
    "        prompt = item.get(model_info[\"column\"])\n",
    "        tasks.append(fetch_response_async(async_client, prompt, model_info[\"lora\"], model_info[\"pydantic\"]))\n",
    "\n",
    "    # Wait for all tasks to complete\n",
    "    responses = await asyncio.gather(*tasks)\n",
    "\n",
    "    # If responses are strings, use them directly; otherwise, extract 'generated_text'\n",
    "    try:\n",
    "        df[response_column] = [resp[\"generated_text\"] for resp in responses]\n",
    "    except TypeError:  # Fallback in case responses are raw strings\n",
    "        df[response_column] = responses\n",
    "\n",
    "# Main function to handle all conversation types\n",
    "async def main(df, models, tokenizer, async_client):\n",
    "    global progress_bar\n",
    "    total_requests = len(df) * len(models)  # Total number of requests across all conversation types\n",
    "    progress_bar = tqdm(total=total_requests, desc=\"Processing requests\")\n",
    "\n",
    "    tasks = []\n",
    "    for conversation_type, model_info in models.items():\n",
    "        tasks.append(process_conversation_type(conversation_type, model_info, df, tokenizer, async_client))\n",
    "    await asyncio.gather(*tasks)\n",
    "\n",
    "    progress_bar.close()  # Close the progress bar when done\n",
    "\n",
    "# Define parameters and run\n",
    "await main(df, experiments, tokenizer, endpoint.async_client)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d562e0b4-96ae-4259-925d-4d62b8c49641",
   "metadata": {},
   "source": [
    "It took `00:10:43`. Not bad! That should be around `$1.14` total at `$0.80/gpu/hr`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "8f81466e-80fb-4915-9c68-dfbe168e052b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "InferenceEndpoint(name='prompt-order-experiment', namespace='derek-thomas', repository='mistralai/Mistral-7B-Instruct-v0.3', status='paused', url=None)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "endpoint.pause()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "f5a79dad-2475-4324-8a2b-77b33e9c0822",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_backup = df.copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "3473d555-927a-49ab-8e15-9097ed455c48",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>topic</th>\n",
       "      <th>question_text</th>\n",
       "      <th>answer_key</th>\n",
       "      <th>gpt3_5_reasoning</th>\n",
       "      <th>mistral_reasoning</th>\n",
       "      <th>answer_choices</th>\n",
       "      <th>user_prompt</th>\n",
       "      <th>user_prompt_RFA</th>\n",
       "      <th>conversation_RFA_gpt3_5</th>\n",
       "      <th>conversation_RFA_mistral</th>\n",
       "      <th>...</th>\n",
       "      <th>conversation_FAR_gpt3_5</th>\n",
       "      <th>conversation_FAR_mistral</th>\n",
       "      <th>user_prompt_FA</th>\n",
       "      <th>conversation_FA</th>\n",
       "      <th>responses_RFA_mistral</th>\n",
       "      <th>responses_FAR_mistral</th>\n",
       "      <th>responses_RFA_gpt3_5</th>\n",
       "      <th>responses_FAR_gpt3_5</th>\n",
       "      <th>responses_FA</th>\n",
       "      <th>responses_base</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Transportation</td>\n",
       "      <td>What are busses used for?</td>\n",
       "      <td>b</td>\n",
       "      <td>a) Protective shelter: This option is incorrec...</td>\n",
       "      <td>1. Start by reading the question carefully: \"C...</td>\n",
       "      <td>(a) Protective shelter (b) Transporting humans...</td>\n",
       "      <td>Question: What are busses used for?\\nAnswer Ch...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>{\"Reasoning\": \"Busses are primarily used for t...</td>\n",
       "      <td>{\"Final Answer\": \"b\", \"Reasoning\": \"Busses are...</td>\n",
       "      <td>{\"Reasoning\": \"Busses are primarily used for t...</td>\n",
       "      <td>{\"Final Answer\": \"b\", \"Reasoning\": \"Busses are...</td>\n",
       "      <td>{ \"Final Answer\": \"b\" }</td>\n",
       "      <td>{\"Final Answer\": \"b\"}</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Climate change</td>\n",
       "      <td>Which of the following does not contribute to ...</td>\n",
       "      <td>g</td>\n",
       "      <td>a) Nucleus of a cell: This option is not relat...</td>\n",
       "      <td>To solve this question, let's first understand...</td>\n",
       "      <td>(a) Nucleus of a cell (b) Flying in a plane (c...</td>\n",
       "      <td>Question: Which of the following does not cont...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>{\"Reasoning\": \"Global warming is primarily cau...</td>\n",
       "      <td>{\"Final Answer\": \"g\", \"Reasoning\": \"Riding a b...</td>\n",
       "      <td>{\"Reasoning\": \"The nucleus of a cell (option a...</td>\n",
       "      <td>{ \"Final Answer\": \"a\" ,\"Reasoning\": \"The nucle...</td>\n",
       "      <td>{\"Final Answer\": \"a\"}</td>\n",
       "      <td>{\"Final Answer\": \"a\"}</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Photography</td>\n",
       "      <td>What uses electrical energy converted from che...</td>\n",
       "      <td>b</td>\n",
       "      <td>a) Sunlight: Sunlight is a form of energy that...</td>\n",
       "      <td>1. Read the question and options carefully: Th...</td>\n",
       "      <td>(a) Sunlight (b) Cameras (c) Cells (d) Buses (...</td>\n",
       "      <td>Question: What uses electrical energy converte...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>{\"Reasoning\": \"The question asks for an organi...</td>\n",
       "      <td>{\"Final Answer\": \"b\", \"Reasoning\": \"Cameras ar...</td>\n",
       "      <td>{\"Reasoning\": \"The correct answer is (c) Cells...</td>\n",
       "      <td>{\"Final Answer\": \"c\", \"Reasoning\": \"Cells are ...</td>\n",
       "      <td>{\"Final Answer\": \"b\"}</td>\n",
       "      <td>{\"Final Answer\": \"c\"}</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Microbiology</td>\n",
       "      <td>Bacteria causes what to be harmed?</td>\n",
       "      <td>a</td>\n",
       "      <td>Now, let's go through each option and explain ...</td>\n",
       "      <td>To answer this question correctly, let's follo...</td>\n",
       "      <td>(a) Plants (b) Electronics (c) Fossils (d) Hum...</td>\n",
       "      <td>Question: Bacteria causes what to be harmed?\\n...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>{\"Reasoning\": \"The question asks about what is...</td>\n",
       "      <td>{\"Final Answer\": \"d\", \"Reasoning\": \"Bacteria c...</td>\n",
       "      <td>{\"Reasoning\": \"Bacteria are microorganisms tha...</td>\n",
       "      <td>{\"Final Answer\": \"d\", \"Reasoning\": \"Bacteria c...</td>\n",
       "      <td>{\"Final Answer\": \"e\"}</td>\n",
       "      <td>{\"Final Answer\": \"d\"}</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Biology</td>\n",
       "      <td>Plants and snakes live _.?</td>\n",
       "      <td>a</td>\n",
       "      <td>b) Important habitats: This option is incorrec...</td>\n",
       "      <td>1. Read the question and options carefully: Th...</td>\n",
       "      <td>(a) Almost everywhere (b) Important habitats (...</td>\n",
       "      <td>Question: Plants and snakes live _.?\\nAnswer C...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>{\"Reasoning\": \"The question asks for the livin...</td>\n",
       "      <td>{\"Final Answer\": \"a\", \"Reasoning\": \"Plants and...</td>\n",
       "      <td>{\"Reasoning\": \"The question asks about the liv...</td>\n",
       "      <td>{ \"Final Answer\": \"a\" ,\"Reasoning\": \"Plants an...</td>\n",
       "      <td>{\"Final Answer\": \"a\"}</td>\n",
       "      <td>{\"Final Answer\": \"g\"}</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1678</th>\n",
       "      <td>Biology</td>\n",
       "      <td>New resources required for creation can be red...</td>\n",
       "      <td>g</td>\n",
       "      <td>a) Mining: Mining involves extracting minerals...</td>\n",
       "      <td>1. Start by reading the question and options c...</td>\n",
       "      <td>(a) Mining (b) Mutations (c) Fossil fuels (d) ...</td>\n",
       "      <td>Question: New resources required for creation ...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>{\"Reasoning\": \"The question asks for a way to ...</td>\n",
       "      <td>{\"Final Answer\": \"g\", \"Reasoning\": \"Recycling ...</td>\n",
       "      <td>{\"Reasoning\": \"Mining, fossil fuels, deforesta...</td>\n",
       "      <td>{ \"Final Answer\": \"g\" ,\"Reasoning\": \"Recycling...</td>\n",
       "      <td>{\"Final Answer\": \"g\"}</td>\n",
       "      <td>{\"Final Answer\": \"g\"}</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1679</th>\n",
       "      <td>Biology</td>\n",
       "      <td>A drought dehydrates an entire what?</td>\n",
       "      <td>d</td>\n",
       "      <td>a) Body water: This option is incorrect becaus...</td>\n",
       "      <td>(a) Watershred - This is not a scientific term...</td>\n",
       "      <td>(a) Body water (b) Dried fruit (c) Bodily wate...</td>\n",
       "      <td>Question: A drought dehydrates an entire what?...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>{\"Reasoning\": \"The question asks for a term th...</td>\n",
       "      <td>{\"Final Answer\": \"d\", \"Reasoning\": \"A drought ...</td>\n",
       "      <td>{\"Reasoning\": \"A drought is a prolonged period...</td>\n",
       "      <td>{ \"Final Answer\": \"d\" ,\"Reasoning\": \"A drought...</td>\n",
       "      <td>{\"Final Answer\": \"a\"}</td>\n",
       "      <td>{\"Final Answer\": \"d\"}</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1680</th>\n",
       "      <td>Biology</td>\n",
       "      <td>An animal requires ingestion to do what?</td>\n",
       "      <td>e</td>\n",
       "      <td>a) Aerobic capacity: This option is not logica...</td>\n",
       "      <td>1. Read the question and options carefully: \"W...</td>\n",
       "      <td>(a) Aerobic capacity (b) Die (c) Water conserv...</td>\n",
       "      <td>Question: An animal requires ingestion to do w...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>{\"Reasoning\": \"Ingestion is the process of tak...</td>\n",
       "      <td>{\"Final Answer\": \"e\", \"Reasoning\": \"Ingestion ...</td>\n",
       "      <td>{\"Reasoning\": \"Ingestion is the process of tak...</td>\n",
       "      <td>{\"Final Answer\": \"e\", \"Reasoning\": \"Ingestion ...</td>\n",
       "      <td>{\"Final Answer\": \"e\"}</td>\n",
       "      <td>{\"Final Answer\": \"d\"}</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1681</th>\n",
       "      <td>Biology</td>\n",
       "      <td>Ultraviolet light can cause what?</td>\n",
       "      <td>b</td>\n",
       "      <td>a) Ultraviolet light does not cause heat energ...</td>\n",
       "      <td>1. First, read the question and options carefu...</td>\n",
       "      <td>(a) Heat energy (b) Skin cancer (c) Killing in...</td>\n",
       "      <td>Question: Ultraviolet light can cause what?\\nA...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>{\"Reasoning\": \"Ultraviolet (UV) light is a typ...</td>\n",
       "      <td>{\"Final Answer\": \"b\", \"Reasoning\": \"Ultraviole...</td>\n",
       "      <td>{\"Reasoning\": \"Ultraviolet (UV) light is a typ...</td>\n",
       "      <td>{ \"Final Answer\": \"b\" ,\"Reasoning\": \"Ultraviol...</td>\n",
       "      <td>{\"Final Answer\": \"b\"}</td>\n",
       "      <td>{\"Final Answer\": \"b\"}</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1682</th>\n",
       "      <td>Physical activity</td>\n",
       "      <td>What can increase a body's strength?</td>\n",
       "      <td>c</td>\n",
       "      <td>a) Four limbs: This option is not correct beca...</td>\n",
       "      <td>(a) Communication: In this context, the questi...</td>\n",
       "      <td>(a) Four limbs (b) Disease (c) Running (d) Bic...</td>\n",
       "      <td>Question: What can increase a body's strength?...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>{\"Reasoning\": \"The correct answer is 'Exercise...</td>\n",
       "      <td>{\"Final Answer\": \"c\", \"Reasoning\": \"Running is...</td>\n",
       "      <td>{\"Reasoning\": \"A body's strength is primarily ...</td>\n",
       "      <td>{\"Final Answer\": \"c\", \"Reasoning\": \"Running is...</td>\n",
       "      <td>{\"Final Answer\": \"f\"}</td>\n",
       "      <td>{\"Final Answer\": \"c\"}</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1683 rows × 21 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  topic                                      question_text  \\\n",
       "0        Transportation                          What are busses used for?   \n",
       "1        Climate change  Which of the following does not contribute to ...   \n",
       "2           Photography  What uses electrical energy converted from che...   \n",
       "3          Microbiology                 Bacteria causes what to be harmed?   \n",
       "4               Biology                         Plants and snakes live _.?   \n",
       "...                 ...                                                ...   \n",
       "1678            Biology  New resources required for creation can be red...   \n",
       "1679            Biology               A drought dehydrates an entire what?   \n",
       "1680            Biology           An animal requires ingestion to do what?   \n",
       "1681            Biology                  Ultraviolet light can cause what?   \n",
       "1682  Physical activity               What can increase a body's strength?   \n",
       "\n",
       "     answer_key                                   gpt3_5_reasoning  \\\n",
       "0             b  a) Protective shelter: This option is incorrec...   \n",
       "1             g  a) Nucleus of a cell: This option is not relat...   \n",
       "2             b  a) Sunlight: Sunlight is a form of energy that...   \n",
       "3             a  Now, let's go through each option and explain ...   \n",
       "4             a  b) Important habitats: This option is incorrec...   \n",
       "...         ...                                                ...   \n",
       "1678          g  a) Mining: Mining involves extracting minerals...   \n",
       "1679          d  a) Body water: This option is incorrect becaus...   \n",
       "1680          e  a) Aerobic capacity: This option is not logica...   \n",
       "1681          b  a) Ultraviolet light does not cause heat energ...   \n",
       "1682          c  a) Four limbs: This option is not correct beca...   \n",
       "\n",
       "                                      mistral_reasoning  \\\n",
       "0     1. Start by reading the question carefully: \"C...   \n",
       "1     To solve this question, let's first understand...   \n",
       "2     1. Read the question and options carefully: Th...   \n",
       "3     To answer this question correctly, let's follo...   \n",
       "4     1. Read the question and options carefully: Th...   \n",
       "...                                                 ...   \n",
       "1678  1. Start by reading the question and options c...   \n",
       "1679  (a) Watershred - This is not a scientific term...   \n",
       "1680  1. Read the question and options carefully: \"W...   \n",
       "1681  1. First, read the question and options carefu...   \n",
       "1682  (a) Communication: In this context, the questi...   \n",
       "\n",
       "                                         answer_choices  \\\n",
       "0     (a) Protective shelter (b) Transporting humans...   \n",
       "1     (a) Nucleus of a cell (b) Flying in a plane (c...   \n",
       "2     (a) Sunlight (b) Cameras (c) Cells (d) Buses (...   \n",
       "3     (a) Plants (b) Electronics (c) Fossils (d) Hum...   \n",
       "4     (a) Almost everywhere (b) Important habitats (...   \n",
       "...                                                 ...   \n",
       "1678  (a) Mining (b) Mutations (c) Fossil fuels (d) ...   \n",
       "1679  (a) Body water (b) Dried fruit (c) Bodily wate...   \n",
       "1680  (a) Aerobic capacity (b) Die (c) Water conserv...   \n",
       "1681  (a) Heat energy (b) Skin cancer (c) Killing in...   \n",
       "1682  (a) Four limbs (b) Disease (c) Running (d) Bic...   \n",
       "\n",
       "                                            user_prompt  \\\n",
       "0     Question: What are busses used for?\\nAnswer Ch...   \n",
       "1     Question: Which of the following does not cont...   \n",
       "2     Question: What uses electrical energy converte...   \n",
       "3     Question: Bacteria causes what to be harmed?\\n...   \n",
       "4     Question: Plants and snakes live _.?\\nAnswer C...   \n",
       "...                                                 ...   \n",
       "1678  Question: New resources required for creation ...   \n",
       "1679  Question: A drought dehydrates an entire what?...   \n",
       "1680  Question: An animal requires ingestion to do w...   \n",
       "1681  Question: Ultraviolet light can cause what?\\nA...   \n",
       "1682  Question: What can increase a body's strength?...   \n",
       "\n",
       "                                        user_prompt_RFA  \\\n",
       "0     <s>[INST] Answer the Question and include your...   \n",
       "1     <s>[INST] Answer the Question and include your...   \n",
       "2     <s>[INST] Answer the Question and include your...   \n",
       "3     <s>[INST] Answer the Question and include your...   \n",
       "4     <s>[INST] Answer the Question and include your...   \n",
       "...                                                 ...   \n",
       "1678  <s>[INST] Answer the Question and include your...   \n",
       "1679  <s>[INST] Answer the Question and include your...   \n",
       "1680  <s>[INST] Answer the Question and include your...   \n",
       "1681  <s>[INST] Answer the Question and include your...   \n",
       "1682  <s>[INST] Answer the Question and include your...   \n",
       "\n",
       "                                conversation_RFA_gpt3_5  \\\n",
       "0     <s>[INST] Answer the Question and include your...   \n",
       "1     <s>[INST] Answer the Question and include your...   \n",
       "2     <s>[INST] Answer the Question and include your...   \n",
       "3     <s>[INST] Answer the Question and include your...   \n",
       "4     <s>[INST] Answer the Question and include your...   \n",
       "...                                                 ...   \n",
       "1678  <s>[INST] Answer the Question and include your...   \n",
       "1679  <s>[INST] Answer the Question and include your...   \n",
       "1680  <s>[INST] Answer the Question and include your...   \n",
       "1681  <s>[INST] Answer the Question and include your...   \n",
       "1682  <s>[INST] Answer the Question and include your...   \n",
       "\n",
       "                               conversation_RFA_mistral  ...  \\\n",
       "0     <s>[INST] Answer the Question and include your...  ...   \n",
       "1     <s>[INST] Answer the Question and include your...  ...   \n",
       "2     <s>[INST] Answer the Question and include your...  ...   \n",
       "3     <s>[INST] Answer the Question and include your...  ...   \n",
       "4     <s>[INST] Answer the Question and include your...  ...   \n",
       "...                                                 ...  ...   \n",
       "1678  <s>[INST] Answer the Question and include your...  ...   \n",
       "1679  <s>[INST] Answer the Question and include your...  ...   \n",
       "1680  <s>[INST] Answer the Question and include your...  ...   \n",
       "1681  <s>[INST] Answer the Question and include your...  ...   \n",
       "1682  <s>[INST] Answer the Question and include your...  ...   \n",
       "\n",
       "                                conversation_FAR_gpt3_5  \\\n",
       "0     <s>[INST] Answer the Question and include your...   \n",
       "1     <s>[INST] Answer the Question and include your...   \n",
       "2     <s>[INST] Answer the Question and include your...   \n",
       "3     <s>[INST] Answer the Question and include your...   \n",
       "4     <s>[INST] Answer the Question and include your...   \n",
       "...                                                 ...   \n",
       "1678  <s>[INST] Answer the Question and include your...   \n",
       "1679  <s>[INST] Answer the Question and include your...   \n",
       "1680  <s>[INST] Answer the Question and include your...   \n",
       "1681  <s>[INST] Answer the Question and include your...   \n",
       "1682  <s>[INST] Answer the Question and include your...   \n",
       "\n",
       "                               conversation_FAR_mistral  \\\n",
       "0     <s>[INST] Answer the Question and include your...   \n",
       "1     <s>[INST] Answer the Question and include your...   \n",
       "2     <s>[INST] Answer the Question and include your...   \n",
       "3     <s>[INST] Answer the Question and include your...   \n",
       "4     <s>[INST] Answer the Question and include your...   \n",
       "...                                                 ...   \n",
       "1678  <s>[INST] Answer the Question and include your...   \n",
       "1679  <s>[INST] Answer the Question and include your...   \n",
       "1680  <s>[INST] Answer the Question and include your...   \n",
       "1681  <s>[INST] Answer the Question and include your...   \n",
       "1682  <s>[INST] Answer the Question and include your...   \n",
       "\n",
       "                                         user_prompt_FA  \\\n",
       "0     <s>[INST] Answer the Question and include your...   \n",
       "1     <s>[INST] Answer the Question and include your...   \n",
       "2     <s>[INST] Answer the Question and include your...   \n",
       "3     <s>[INST] Answer the Question and include your...   \n",
       "4     <s>[INST] Answer the Question and include your...   \n",
       "...                                                 ...   \n",
       "1678  <s>[INST] Answer the Question and include your...   \n",
       "1679  <s>[INST] Answer the Question and include your...   \n",
       "1680  <s>[INST] Answer the Question and include your...   \n",
       "1681  <s>[INST] Answer the Question and include your...   \n",
       "1682  <s>[INST] Answer the Question and include your...   \n",
       "\n",
       "                                        conversation_FA  \\\n",
       "0     <s>[INST] Answer the Question and include your...   \n",
       "1     <s>[INST] Answer the Question and include your...   \n",
       "2     <s>[INST] Answer the Question and include your...   \n",
       "3     <s>[INST] Answer the Question and include your...   \n",
       "4     <s>[INST] Answer the Question and include your...   \n",
       "...                                                 ...   \n",
       "1678  <s>[INST] Answer the Question and include your...   \n",
       "1679  <s>[INST] Answer the Question and include your...   \n",
       "1680  <s>[INST] Answer the Question and include your...   \n",
       "1681  <s>[INST] Answer the Question and include your...   \n",
       "1682  <s>[INST] Answer the Question and include your...   \n",
       "\n",
       "                                  responses_RFA_mistral  \\\n",
       "0     {\"Reasoning\": \"Busses are primarily used for t...   \n",
       "1     {\"Reasoning\": \"Global warming is primarily cau...   \n",
       "2     {\"Reasoning\": \"The question asks for an organi...   \n",
       "3     {\"Reasoning\": \"The question asks about what is...   \n",
       "4     {\"Reasoning\": \"The question asks for the livin...   \n",
       "...                                                 ...   \n",
       "1678  {\"Reasoning\": \"The question asks for a way to ...   \n",
       "1679  {\"Reasoning\": \"The question asks for a term th...   \n",
       "1680  {\"Reasoning\": \"Ingestion is the process of tak...   \n",
       "1681  {\"Reasoning\": \"Ultraviolet (UV) light is a typ...   \n",
       "1682  {\"Reasoning\": \"The correct answer is 'Exercise...   \n",
       "\n",
       "                                  responses_FAR_mistral  \\\n",
       "0     {\"Final Answer\": \"b\", \"Reasoning\": \"Busses are...   \n",
       "1     {\"Final Answer\": \"g\", \"Reasoning\": \"Riding a b...   \n",
       "2     {\"Final Answer\": \"b\", \"Reasoning\": \"Cameras ar...   \n",
       "3     {\"Final Answer\": \"d\", \"Reasoning\": \"Bacteria c...   \n",
       "4     {\"Final Answer\": \"a\", \"Reasoning\": \"Plants and...   \n",
       "...                                                 ...   \n",
       "1678  {\"Final Answer\": \"g\", \"Reasoning\": \"Recycling ...   \n",
       "1679  {\"Final Answer\": \"d\", \"Reasoning\": \"A drought ...   \n",
       "1680  {\"Final Answer\": \"e\", \"Reasoning\": \"Ingestion ...   \n",
       "1681  {\"Final Answer\": \"b\", \"Reasoning\": \"Ultraviole...   \n",
       "1682  {\"Final Answer\": \"c\", \"Reasoning\": \"Running is...   \n",
       "\n",
       "                                   responses_RFA_gpt3_5  \\\n",
       "0     {\"Reasoning\": \"Busses are primarily used for t...   \n",
       "1     {\"Reasoning\": \"The nucleus of a cell (option a...   \n",
       "2     {\"Reasoning\": \"The correct answer is (c) Cells...   \n",
       "3     {\"Reasoning\": \"Bacteria are microorganisms tha...   \n",
       "4     {\"Reasoning\": \"The question asks about the liv...   \n",
       "...                                                 ...   \n",
       "1678  {\"Reasoning\": \"Mining, fossil fuels, deforesta...   \n",
       "1679  {\"Reasoning\": \"A drought is a prolonged period...   \n",
       "1680  {\"Reasoning\": \"Ingestion is the process of tak...   \n",
       "1681  {\"Reasoning\": \"Ultraviolet (UV) light is a typ...   \n",
       "1682  {\"Reasoning\": \"A body's strength is primarily ...   \n",
       "\n",
       "                                   responses_FAR_gpt3_5  \\\n",
       "0     {\"Final Answer\": \"b\", \"Reasoning\": \"Busses are...   \n",
       "1     { \"Final Answer\": \"a\" ,\"Reasoning\": \"The nucle...   \n",
       "2     {\"Final Answer\": \"c\", \"Reasoning\": \"Cells are ...   \n",
       "3     {\"Final Answer\": \"d\", \"Reasoning\": \"Bacteria c...   \n",
       "4     { \"Final Answer\": \"a\" ,\"Reasoning\": \"Plants an...   \n",
       "...                                                 ...   \n",
       "1678  { \"Final Answer\": \"g\" ,\"Reasoning\": \"Recycling...   \n",
       "1679  { \"Final Answer\": \"d\" ,\"Reasoning\": \"A drought...   \n",
       "1680  {\"Final Answer\": \"e\", \"Reasoning\": \"Ingestion ...   \n",
       "1681  { \"Final Answer\": \"b\" ,\"Reasoning\": \"Ultraviol...   \n",
       "1682  {\"Final Answer\": \"c\", \"Reasoning\": \"Running is...   \n",
       "\n",
       "                 responses_FA         responses_base  \n",
       "0     { \"Final Answer\": \"b\" }  {\"Final Answer\": \"b\"}  \n",
       "1       {\"Final Answer\": \"a\"}  {\"Final Answer\": \"a\"}  \n",
       "2       {\"Final Answer\": \"b\"}  {\"Final Answer\": \"c\"}  \n",
       "3       {\"Final Answer\": \"e\"}  {\"Final Answer\": \"d\"}  \n",
       "4       {\"Final Answer\": \"a\"}  {\"Final Answer\": \"g\"}  \n",
       "...                       ...                    ...  \n",
       "1678    {\"Final Answer\": \"g\"}  {\"Final Answer\": \"g\"}  \n",
       "1679    {\"Final Answer\": \"a\"}  {\"Final Answer\": \"d\"}  \n",
       "1680    {\"Final Answer\": \"e\"}  {\"Final Answer\": \"d\"}  \n",
       "1681    {\"Final Answer\": \"b\"}  {\"Final Answer\": \"b\"}  \n",
       "1682    {\"Final Answer\": \"f\"}  {\"Final Answer\": \"c\"}  \n",
       "\n",
       "[1683 rows x 21 columns]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "8619f9f5-9fe4-433e-b524-51c2b12e8d12",
   "metadata": {},
   "outputs": [],
   "source": [
    "def extract_final_answer(response):\n",
    "    try:\n",
    "        answer = json.loads(response).get(\"Final Answer\")\n",
    "    except:\n",
    "        answer = 'x'\n",
    "    return answer\n",
    "\n",
    "# Create new columns for predictions\n",
    "df['predictions_base'] = df['responses_base'].apply(extract_final_answer)\n",
    "df['predictions_FA'] = df['responses_FA'].apply(extract_final_answer)\n",
    "df['predictions_RFA_mistral'] = df['responses_RFA_mistral'].apply(extract_final_answer)\n",
    "df['predictions_FAR_mistral'] = df['responses_FAR_mistral'].apply(extract_final_answer)\n",
    "df['predictions_RFA_gpt3_5'] = df['responses_RFA_gpt3_5'].apply(extract_final_answer)\n",
    "df['predictions_FAR_gpt3_5'] = df['responses_FAR_gpt3_5'].apply(extract_final_answer)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "938cf2a3-2fed-42a3-82ec-a56cb0ea9f37",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Base: \t\t\t\t\t\t45.22%\n",
      "Final Answer: \t\t\t\t\t64.53%\n",
      "Reasoning and then the Final Answer (Mistral): \t55.02%\n",
      "Final Answer and then the Reasoning (Mistral): \t61.79%\n",
      "Reasoning and then the Final Answer (GPT-3.5): \t57.28%\n",
      "Final Answer and then the Reasoning (GPT-3.5): \t61.62%\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import accuracy_score\n",
    "\n",
    "print(f\"Base: \\t\\t\\t\\t\\t\\t{round(accuracy_score(y_true=df['answer_key'], y_pred=df['predictions_base']) * 100, 2)}%\")\n",
    "print(f\"Final Answer: \\t\\t\\t\\t\\t{round(accuracy_score(y_true=df['answer_key'], y_pred=df['predictions_FA']) * 100, 2)}%\")\n",
    "print(f\"Reasoning and then the Final Answer (Mistral): \\t{round(accuracy_score(y_true=df['answer_key'], y_pred=df['predictions_RFA_mistral']) * 100, 2)}%\")\n",
    "print(f\"Final Answer and then the Reasoning (Mistral): \\t{round(accuracy_score(y_true=df['answer_key'], y_pred=df['predictions_FAR_mistral']) * 100, 2)}%\")\n",
    "print(f\"Reasoning and then the Final Answer (GPT-3.5): \\t{round(accuracy_score(y_true=df['answer_key'], y_pred=df['predictions_RFA_gpt3_5']) * 100, 2)}%\")\n",
    "print(f\"Final Answer and then the Reasoning (GPT-3.5): \\t{round(accuracy_score(y_true=df['answer_key'], y_pred=df['predictions_FAR_gpt3_5']) * 100, 2)}%\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "83aae472-513b-43c3-9ee8-64d4cda775e0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>topic</th>\n",
       "      <th>question_text</th>\n",
       "      <th>answer_key</th>\n",
       "      <th>gpt3_5_reasoning</th>\n",
       "      <th>mistral_reasoning</th>\n",
       "      <th>answer_choices</th>\n",
       "      <th>user_prompt</th>\n",
       "      <th>user_prompt_RFA</th>\n",
       "      <th>conversation_RFA_gpt3_5</th>\n",
       "      <th>conversation_RFA_mistral</th>\n",
       "      <th>...</th>\n",
       "      <th>responses_RFA_gpt3_5</th>\n",
       "      <th>responses_FAR_gpt3_5</th>\n",
       "      <th>responses_FA</th>\n",
       "      <th>responses_base</th>\n",
       "      <th>predictions_base</th>\n",
       "      <th>predictions_FA</th>\n",
       "      <th>predictions_FAR_mistral</th>\n",
       "      <th>predictions_RFA_gpt3_5</th>\n",
       "      <th>predictions_FAR_gpt3_5</th>\n",
       "      <th>predictions_RFA_mistral</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Transportation</td>\n",
       "      <td>What are busses used for?</td>\n",
       "      <td>b</td>\n",
       "      <td>a) Protective shelter: This option is incorrec...</td>\n",
       "      <td>1. Start by reading the question carefully: \"C...</td>\n",
       "      <td>(a) Protective shelter (b) Transporting humans...</td>\n",
       "      <td>Question: What are busses used for?\\nAnswer Ch...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>{\"Reasoning\": \"Busses are primarily used for t...</td>\n",
       "      <td>{\"Final Answer\": \"b\", \"Reasoning\": \"Busses are...</td>\n",
       "      <td>{ \"Final Answer\": \"b\" }</td>\n",
       "      <td>{\"Final Answer\": \"b\"}</td>\n",
       "      <td>b</td>\n",
       "      <td>b</td>\n",
       "      <td>b</td>\n",
       "      <td>b</td>\n",
       "      <td>b</td>\n",
       "      <td>b</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Climate change</td>\n",
       "      <td>Which of the following does not contribute to ...</td>\n",
       "      <td>g</td>\n",
       "      <td>a) Nucleus of a cell: This option is not relat...</td>\n",
       "      <td>To solve this question, let's first understand...</td>\n",
       "      <td>(a) Nucleus of a cell (b) Flying in a plane (c...</td>\n",
       "      <td>Question: Which of the following does not cont...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>{\"Reasoning\": \"The nucleus of a cell (option a...</td>\n",
       "      <td>{ \"Final Answer\": \"a\" ,\"Reasoning\": \"The nucle...</td>\n",
       "      <td>{\"Final Answer\": \"a\"}</td>\n",
       "      <td>{\"Final Answer\": \"a\"}</td>\n",
       "      <td>a</td>\n",
       "      <td>a</td>\n",
       "      <td>g</td>\n",
       "      <td>a</td>\n",
       "      <td>a</td>\n",
       "      <td>g</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Photography</td>\n",
       "      <td>What uses electrical energy converted from che...</td>\n",
       "      <td>b</td>\n",
       "      <td>a) Sunlight: Sunlight is a form of energy that...</td>\n",
       "      <td>1. Read the question and options carefully: Th...</td>\n",
       "      <td>(a) Sunlight (b) Cameras (c) Cells (d) Buses (...</td>\n",
       "      <td>Question: What uses electrical energy converte...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>{\"Reasoning\": \"The correct answer is (c) Cells...</td>\n",
       "      <td>{\"Final Answer\": \"c\", \"Reasoning\": \"Cells are ...</td>\n",
       "      <td>{\"Final Answer\": \"b\"}</td>\n",
       "      <td>{\"Final Answer\": \"c\"}</td>\n",
       "      <td>c</td>\n",
       "      <td>b</td>\n",
       "      <td>b</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>e</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Microbiology</td>\n",
       "      <td>Bacteria causes what to be harmed?</td>\n",
       "      <td>a</td>\n",
       "      <td>Now, let's go through each option and explain ...</td>\n",
       "      <td>To answer this question correctly, let's follo...</td>\n",
       "      <td>(a) Plants (b) Electronics (c) Fossils (d) Hum...</td>\n",
       "      <td>Question: Bacteria causes what to be harmed?\\n...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>{\"Reasoning\": \"Bacteria are microorganisms tha...</td>\n",
       "      <td>{\"Final Answer\": \"d\", \"Reasoning\": \"Bacteria c...</td>\n",
       "      <td>{\"Final Answer\": \"e\"}</td>\n",
       "      <td>{\"Final Answer\": \"d\"}</td>\n",
       "      <td>d</td>\n",
       "      <td>e</td>\n",
       "      <td>d</td>\n",
       "      <td>d</td>\n",
       "      <td>d</td>\n",
       "      <td>e</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Biology</td>\n",
       "      <td>Plants and snakes live _.?</td>\n",
       "      <td>a</td>\n",
       "      <td>b) Important habitats: This option is incorrec...</td>\n",
       "      <td>1. Read the question and options carefully: Th...</td>\n",
       "      <td>(a) Almost everywhere (b) Important habitats (...</td>\n",
       "      <td>Question: Plants and snakes live _.?\\nAnswer C...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>{\"Reasoning\": \"The question asks about the liv...</td>\n",
       "      <td>{ \"Final Answer\": \"a\" ,\"Reasoning\": \"Plants an...</td>\n",
       "      <td>{\"Final Answer\": \"a\"}</td>\n",
       "      <td>{\"Final Answer\": \"g\"}</td>\n",
       "      <td>g</td>\n",
       "      <td>a</td>\n",
       "      <td>a</td>\n",
       "      <td>f</td>\n",
       "      <td>a</td>\n",
       "      <td>b</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1678</th>\n",
       "      <td>Biology</td>\n",
       "      <td>New resources required for creation can be red...</td>\n",
       "      <td>g</td>\n",
       "      <td>a) Mining: Mining involves extracting minerals...</td>\n",
       "      <td>1. Start by reading the question and options c...</td>\n",
       "      <td>(a) Mining (b) Mutations (c) Fossil fuels (d) ...</td>\n",
       "      <td>Question: New resources required for creation ...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>{\"Reasoning\": \"Mining, fossil fuels, deforesta...</td>\n",
       "      <td>{ \"Final Answer\": \"g\" ,\"Reasoning\": \"Recycling...</td>\n",
       "      <td>{\"Final Answer\": \"g\"}</td>\n",
       "      <td>{\"Final Answer\": \"g\"}</td>\n",
       "      <td>g</td>\n",
       "      <td>g</td>\n",
       "      <td>g</td>\n",
       "      <td>g</td>\n",
       "      <td>g</td>\n",
       "      <td>g</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1679</th>\n",
       "      <td>Biology</td>\n",
       "      <td>A drought dehydrates an entire what?</td>\n",
       "      <td>d</td>\n",
       "      <td>a) Body water: This option is incorrect becaus...</td>\n",
       "      <td>(a) Watershred - This is not a scientific term...</td>\n",
       "      <td>(a) Body water (b) Dried fruit (c) Bodily wate...</td>\n",
       "      <td>Question: A drought dehydrates an entire what?...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>{\"Reasoning\": \"A drought is a prolonged period...</td>\n",
       "      <td>{ \"Final Answer\": \"d\" ,\"Reasoning\": \"A drought...</td>\n",
       "      <td>{\"Final Answer\": \"a\"}</td>\n",
       "      <td>{\"Final Answer\": \"d\"}</td>\n",
       "      <td>d</td>\n",
       "      <td>a</td>\n",
       "      <td>d</td>\n",
       "      <td>d</td>\n",
       "      <td>d</td>\n",
       "      <td>d</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1680</th>\n",
       "      <td>Biology</td>\n",
       "      <td>An animal requires ingestion to do what?</td>\n",
       "      <td>e</td>\n",
       "      <td>a) Aerobic capacity: This option is not logica...</td>\n",
       "      <td>1. Read the question and options carefully: \"W...</td>\n",
       "      <td>(a) Aerobic capacity (b) Die (c) Water conserv...</td>\n",
       "      <td>Question: An animal requires ingestion to do w...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>{\"Reasoning\": \"Ingestion is the process of tak...</td>\n",
       "      <td>{\"Final Answer\": \"e\", \"Reasoning\": \"Ingestion ...</td>\n",
       "      <td>{\"Final Answer\": \"e\"}</td>\n",
       "      <td>{\"Final Answer\": \"d\"}</td>\n",
       "      <td>d</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>c</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1681</th>\n",
       "      <td>Biology</td>\n",
       "      <td>Ultraviolet light can cause what?</td>\n",
       "      <td>b</td>\n",
       "      <td>a) Ultraviolet light does not cause heat energ...</td>\n",
       "      <td>1. First, read the question and options carefu...</td>\n",
       "      <td>(a) Heat energy (b) Skin cancer (c) Killing in...</td>\n",
       "      <td>Question: Ultraviolet light can cause what?\\nA...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>{\"Reasoning\": \"Ultraviolet (UV) light is a typ...</td>\n",
       "      <td>{ \"Final Answer\": \"b\" ,\"Reasoning\": \"Ultraviol...</td>\n",
       "      <td>{\"Final Answer\": \"b\"}</td>\n",
       "      <td>{\"Final Answer\": \"b\"}</td>\n",
       "      <td>b</td>\n",
       "      <td>b</td>\n",
       "      <td>b</td>\n",
       "      <td>b</td>\n",
       "      <td>b</td>\n",
       "      <td>b</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1682</th>\n",
       "      <td>Physical activity</td>\n",
       "      <td>What can increase a body's strength?</td>\n",
       "      <td>c</td>\n",
       "      <td>a) Four limbs: This option is not correct beca...</td>\n",
       "      <td>(a) Communication: In this context, the questi...</td>\n",
       "      <td>(a) Four limbs (b) Disease (c) Running (d) Bic...</td>\n",
       "      <td>Question: What can increase a body's strength?...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>&lt;s&gt;[INST] Answer the Question and include your...</td>\n",
       "      <td>...</td>\n",
       "      <td>{\"Reasoning\": \"A body's strength is primarily ...</td>\n",
       "      <td>{\"Final Answer\": \"c\", \"Reasoning\": \"Running is...</td>\n",
       "      <td>{\"Final Answer\": \"f\"}</td>\n",
       "      <td>{\"Final Answer\": \"c\"}</td>\n",
       "      <td>c</td>\n",
       "      <td>f</td>\n",
       "      <td>c</td>\n",
       "      <td>d</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1683 rows × 27 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  topic                                      question_text  \\\n",
       "0        Transportation                          What are busses used for?   \n",
       "1        Climate change  Which of the following does not contribute to ...   \n",
       "2           Photography  What uses electrical energy converted from che...   \n",
       "3          Microbiology                 Bacteria causes what to be harmed?   \n",
       "4               Biology                         Plants and snakes live _.?   \n",
       "...                 ...                                                ...   \n",
       "1678            Biology  New resources required for creation can be red...   \n",
       "1679            Biology               A drought dehydrates an entire what?   \n",
       "1680            Biology           An animal requires ingestion to do what?   \n",
       "1681            Biology                  Ultraviolet light can cause what?   \n",
       "1682  Physical activity               What can increase a body's strength?   \n",
       "\n",
       "     answer_key                                   gpt3_5_reasoning  \\\n",
       "0             b  a) Protective shelter: This option is incorrec...   \n",
       "1             g  a) Nucleus of a cell: This option is not relat...   \n",
       "2             b  a) Sunlight: Sunlight is a form of energy that...   \n",
       "3             a  Now, let's go through each option and explain ...   \n",
       "4             a  b) Important habitats: This option is incorrec...   \n",
       "...         ...                                                ...   \n",
       "1678          g  a) Mining: Mining involves extracting minerals...   \n",
       "1679          d  a) Body water: This option is incorrect becaus...   \n",
       "1680          e  a) Aerobic capacity: This option is not logica...   \n",
       "1681          b  a) Ultraviolet light does not cause heat energ...   \n",
       "1682          c  a) Four limbs: This option is not correct beca...   \n",
       "\n",
       "                                      mistral_reasoning  \\\n",
       "0     1. Start by reading the question carefully: \"C...   \n",
       "1     To solve this question, let's first understand...   \n",
       "2     1. Read the question and options carefully: Th...   \n",
       "3     To answer this question correctly, let's follo...   \n",
       "4     1. Read the question and options carefully: Th...   \n",
       "...                                                 ...   \n",
       "1678  1. Start by reading the question and options c...   \n",
       "1679  (a) Watershred - This is not a scientific term...   \n",
       "1680  1. Read the question and options carefully: \"W...   \n",
       "1681  1. First, read the question and options carefu...   \n",
       "1682  (a) Communication: In this context, the questi...   \n",
       "\n",
       "                                         answer_choices  \\\n",
       "0     (a) Protective shelter (b) Transporting humans...   \n",
       "1     (a) Nucleus of a cell (b) Flying in a plane (c...   \n",
       "2     (a) Sunlight (b) Cameras (c) Cells (d) Buses (...   \n",
       "3     (a) Plants (b) Electronics (c) Fossils (d) Hum...   \n",
       "4     (a) Almost everywhere (b) Important habitats (...   \n",
       "...                                                 ...   \n",
       "1678  (a) Mining (b) Mutations (c) Fossil fuels (d) ...   \n",
       "1679  (a) Body water (b) Dried fruit (c) Bodily wate...   \n",
       "1680  (a) Aerobic capacity (b) Die (c) Water conserv...   \n",
       "1681  (a) Heat energy (b) Skin cancer (c) Killing in...   \n",
       "1682  (a) Four limbs (b) Disease (c) Running (d) Bic...   \n",
       "\n",
       "                                            user_prompt  \\\n",
       "0     Question: What are busses used for?\\nAnswer Ch...   \n",
       "1     Question: Which of the following does not cont...   \n",
       "2     Question: What uses electrical energy converte...   \n",
       "3     Question: Bacteria causes what to be harmed?\\n...   \n",
       "4     Question: Plants and snakes live _.?\\nAnswer C...   \n",
       "...                                                 ...   \n",
       "1678  Question: New resources required for creation ...   \n",
       "1679  Question: A drought dehydrates an entire what?...   \n",
       "1680  Question: An animal requires ingestion to do w...   \n",
       "1681  Question: Ultraviolet light can cause what?\\nA...   \n",
       "1682  Question: What can increase a body's strength?...   \n",
       "\n",
       "                                        user_prompt_RFA  \\\n",
       "0     <s>[INST] Answer the Question and include your...   \n",
       "1     <s>[INST] Answer the Question and include your...   \n",
       "2     <s>[INST] Answer the Question and include your...   \n",
       "3     <s>[INST] Answer the Question and include your...   \n",
       "4     <s>[INST] Answer the Question and include your...   \n",
       "...                                                 ...   \n",
       "1678  <s>[INST] Answer the Question and include your...   \n",
       "1679  <s>[INST] Answer the Question and include your...   \n",
       "1680  <s>[INST] Answer the Question and include your...   \n",
       "1681  <s>[INST] Answer the Question and include your...   \n",
       "1682  <s>[INST] Answer the Question and include your...   \n",
       "\n",
       "                                conversation_RFA_gpt3_5  \\\n",
       "0     <s>[INST] Answer the Question and include your...   \n",
       "1     <s>[INST] Answer the Question and include your...   \n",
       "2     <s>[INST] Answer the Question and include your...   \n",
       "3     <s>[INST] Answer the Question and include your...   \n",
       "4     <s>[INST] Answer the Question and include your...   \n",
       "...                                                 ...   \n",
       "1678  <s>[INST] Answer the Question and include your...   \n",
       "1679  <s>[INST] Answer the Question and include your...   \n",
       "1680  <s>[INST] Answer the Question and include your...   \n",
       "1681  <s>[INST] Answer the Question and include your...   \n",
       "1682  <s>[INST] Answer the Question and include your...   \n",
       "\n",
       "                               conversation_RFA_mistral  ...  \\\n",
       "0     <s>[INST] Answer the Question and include your...  ...   \n",
       "1     <s>[INST] Answer the Question and include your...  ...   \n",
       "2     <s>[INST] Answer the Question and include your...  ...   \n",
       "3     <s>[INST] Answer the Question and include your...  ...   \n",
       "4     <s>[INST] Answer the Question and include your...  ...   \n",
       "...                                                 ...  ...   \n",
       "1678  <s>[INST] Answer the Question and include your...  ...   \n",
       "1679  <s>[INST] Answer the Question and include your...  ...   \n",
       "1680  <s>[INST] Answer the Question and include your...  ...   \n",
       "1681  <s>[INST] Answer the Question and include your...  ...   \n",
       "1682  <s>[INST] Answer the Question and include your...  ...   \n",
       "\n",
       "                                   responses_RFA_gpt3_5  \\\n",
       "0     {\"Reasoning\": \"Busses are primarily used for t...   \n",
       "1     {\"Reasoning\": \"The nucleus of a cell (option a...   \n",
       "2     {\"Reasoning\": \"The correct answer is (c) Cells...   \n",
       "3     {\"Reasoning\": \"Bacteria are microorganisms tha...   \n",
       "4     {\"Reasoning\": \"The question asks about the liv...   \n",
       "...                                                 ...   \n",
       "1678  {\"Reasoning\": \"Mining, fossil fuels, deforesta...   \n",
       "1679  {\"Reasoning\": \"A drought is a prolonged period...   \n",
       "1680  {\"Reasoning\": \"Ingestion is the process of tak...   \n",
       "1681  {\"Reasoning\": \"Ultraviolet (UV) light is a typ...   \n",
       "1682  {\"Reasoning\": \"A body's strength is primarily ...   \n",
       "\n",
       "                                   responses_FAR_gpt3_5  \\\n",
       "0     {\"Final Answer\": \"b\", \"Reasoning\": \"Busses are...   \n",
       "1     { \"Final Answer\": \"a\" ,\"Reasoning\": \"The nucle...   \n",
       "2     {\"Final Answer\": \"c\", \"Reasoning\": \"Cells are ...   \n",
       "3     {\"Final Answer\": \"d\", \"Reasoning\": \"Bacteria c...   \n",
       "4     { \"Final Answer\": \"a\" ,\"Reasoning\": \"Plants an...   \n",
       "...                                                 ...   \n",
       "1678  { \"Final Answer\": \"g\" ,\"Reasoning\": \"Recycling...   \n",
       "1679  { \"Final Answer\": \"d\" ,\"Reasoning\": \"A drought...   \n",
       "1680  {\"Final Answer\": \"e\", \"Reasoning\": \"Ingestion ...   \n",
       "1681  { \"Final Answer\": \"b\" ,\"Reasoning\": \"Ultraviol...   \n",
       "1682  {\"Final Answer\": \"c\", \"Reasoning\": \"Running is...   \n",
       "\n",
       "                 responses_FA         responses_base predictions_base  \\\n",
       "0     { \"Final Answer\": \"b\" }  {\"Final Answer\": \"b\"}                b   \n",
       "1       {\"Final Answer\": \"a\"}  {\"Final Answer\": \"a\"}                a   \n",
       "2       {\"Final Answer\": \"b\"}  {\"Final Answer\": \"c\"}                c   \n",
       "3       {\"Final Answer\": \"e\"}  {\"Final Answer\": \"d\"}                d   \n",
       "4       {\"Final Answer\": \"a\"}  {\"Final Answer\": \"g\"}                g   \n",
       "...                       ...                    ...              ...   \n",
       "1678    {\"Final Answer\": \"g\"}  {\"Final Answer\": \"g\"}                g   \n",
       "1679    {\"Final Answer\": \"a\"}  {\"Final Answer\": \"d\"}                d   \n",
       "1680    {\"Final Answer\": \"e\"}  {\"Final Answer\": \"d\"}                d   \n",
       "1681    {\"Final Answer\": \"b\"}  {\"Final Answer\": \"b\"}                b   \n",
       "1682    {\"Final Answer\": \"f\"}  {\"Final Answer\": \"c\"}                c   \n",
       "\n",
       "     predictions_FA predictions_FAR_mistral predictions_RFA_gpt3_5  \\\n",
       "0                 b                       b                      b   \n",
       "1                 a                       g                      a   \n",
       "2                 b                       b                      c   \n",
       "3                 e                       d                      d   \n",
       "4                 a                       a                      f   \n",
       "...             ...                     ...                    ...   \n",
       "1678              g                       g                      g   \n",
       "1679              a                       d                      d   \n",
       "1680              e                       e                      e   \n",
       "1681              b                       b                      b   \n",
       "1682              f                       c                      d   \n",
       "\n",
       "     predictions_FAR_gpt3_5 predictions_RFA_mistral  \n",
       "0                         b                       b  \n",
       "1                         a                       g  \n",
       "2                         c                       e  \n",
       "3                         d                       e  \n",
       "4                         a                       b  \n",
       "...                     ...                     ...  \n",
       "1678                      g                       g  \n",
       "1679                      d                       d  \n",
       "1680                      e                       c  \n",
       "1681                      b                       b  \n",
       "1682                      c                       c  \n",
       "\n",
       "[1683 rows x 27 columns]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "45c08dd4-0b98-4e0f-b487-549f60518a4e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "23d5dbd0a91d436fb9920dfe81e4803a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Uploading the dataset shards:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0b25bcb277574e8792b14e838a32fe25",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Creating parquet from Arrow format:   0%|          | 0/2 [00:00<?, ?ba/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "CommitInfo(commit_url='https://huggingface.co/datasets/derek-thomas/labeled-multiple-choice-explained-mistral-results/commit/796d0867b715f2fad05d6e54ad1e0e0504ca670c', commit_message='Upload dataset', commit_description='', oid='796d0867b715f2fad05d6e54ad1e0e0504ca670c', pr_url=None, repo_url=RepoUrl('https://huggingface.co/datasets/derek-thomas/labeled-multiple-choice-explained-mistral-results', endpoint='https://huggingface.co', repo_type='dataset', repo_id='derek-thomas/labeled-multiple-choice-explained-mistral-results'), pr_revision=None, pr_num=None)"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from datasets import Dataset, DatasetDict\n",
    "\n",
    "# Create dataset from df\n",
    "df.reset_index(drop=True, inplace=True)\n",
    "dataset = Dataset.from_pandas(df)\n",
    "\n",
    "# Push dataset to the hub\n",
    "dataset.push_to_hub(OUTPUT_DATASET)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "45ed7bf8-54de-4f4d-aab5-b78af8f54ccc",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}