File size: 60,083 Bytes
b83b354
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "executionInfo": {
     "elapsed": 476,
     "status": "ok",
     "timestamp": 1720679526275,
     "user": {
      "displayName": "HUANG DONGHAO _",
      "userId": "00977795705617022768"
     },
     "user_tz": -480
    },
    "id": "uWKRSV6eZsCn"
   },
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "application/vnd.databricks.v1+cell": {
     "cellMetadata": {
      "byteLimit": 2048000,
      "rowLimit": 10000
     },
     "inputWidgets": {},
     "nuid": "6d394937-6c99-4a7c-9d32-7600a280032f",
     "showTitle": false,
     "title": ""
    },
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 5,
     "status": "ok",
     "timestamp": 1720679529345,
     "user": {
      "displayName": "HUANG DONGHAO _",
      "userId": "00977795705617022768"
     },
     "user_tz": -480
    },
    "id": "G5pNu3zgZBrL",
    "outputId": "160a554f-fb08-4aa0-bc00-0422fb7c1fac"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "workding dir: d:\\code\\projects\\rapget-translation\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import sys\n",
    "from pathlib import Path\n",
    "\n",
    "# check if workding_dir is in local variables\n",
    "if \"workding_dir\" not in locals():\n",
    "    workding_dir = str(Path.cwd().parent)\n",
    "\n",
    "os.chdir(workding_dir)\n",
    "sys.path.append(workding_dir)\n",
    "print(\"workding dir:\", workding_dir)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "application/vnd.databricks.v1+cell": {
     "cellMetadata": {
      "byteLimit": 2048000,
      "rowLimit": 10000
     },
     "inputWidgets": {},
     "nuid": "9f67ec60-2f24-411c-84eb-0dd664b44775",
     "showTitle": false,
     "title": ""
    },
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 3,
     "status": "ok",
     "timestamp": 1720679529345,
     "user": {
      "displayName": "HUANG DONGHAO _",
      "userId": "00977795705617022768"
     },
     "user_tz": -480
    },
    "id": "hPCC-6m7ZBrM",
    "outputId": "c7aa2c96-5e99-440a-c148-201d79465ff9"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "loading env vars from: d:\\code\\projects\\rapget-translation\\.env\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from dotenv import find_dotenv, load_dotenv\n",
    "\n",
    "found_dotenv = find_dotenv(\".env\")\n",
    "\n",
    "if len(found_dotenv) == 0:\n",
    "    found_dotenv = find_dotenv(\".env.example\")\n",
    "print(f\"loading env vars from: {found_dotenv}\")\n",
    "load_dotenv(found_dotenv, override=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "application/vnd.databricks.v1+cell": {
     "cellMetadata": {
      "byteLimit": 2048000,
      "rowLimit": 10000
     },
     "inputWidgets": {},
     "nuid": "f1597656-8042-4878-9d3b-9ebfb8dd86dc",
     "showTitle": false,
     "title": ""
    },
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 3,
     "status": "ok",
     "timestamp": 1720679529345,
     "user": {
      "displayName": "HUANG DONGHAO _",
      "userId": "00977795705617022768"
     },
     "user_tz": -480
    },
    "id": "1M3IraVtZBrM",
    "outputId": "29ab35f6-2970-4ade-d85d-3174acf8cda0"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "01-ai/Yi-1.5-9B-Chat None True datasets/mac/mac.tsv results/mac-results_few_shots_4bit.csv False 300\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "model_name = os.getenv(\"MODEL_NAME\")\n",
    "adapter_name_or_path = os.getenv(\"ADAPTER_NAME_OR_PATH\")\n",
    "load_in_4bit = os.getenv(\"LOAD_IN_4BIT\") == \"true\"\n",
    "data_path = os.getenv(\"DATA_PATH\")\n",
    "results_path = os.getenv(\"RESULTS_PATH\")\n",
    "use_english_datasets = os.getenv(\"USE_ENGLISH_DATASETS\") == \"true\"\n",
    "max_new_tokens = int(os.getenv(\"MAX_NEW_TOKENS\", 2048))\n",
    "\n",
    "print(\n",
    "    model_name,\n",
    "    adapter_name_or_path,\n",
    "    load_in_4bit,\n",
    "    data_path,\n",
    "    results_path,\n",
    "    use_english_datasets,\n",
    "    max_new_tokens,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "application/vnd.databricks.v1+cell": {
     "cellMetadata": {
      "byteLimit": 2048000,
      "rowLimit": 10000
     },
     "inputWidgets": {},
     "nuid": "b2a43943-9324-4839-9a47-cfa72de2244b",
     "showTitle": false,
     "title": ""
    },
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 564,
     "status": "ok",
     "timestamp": 1720679529907,
     "user": {
      "displayName": "HUANG DONGHAO _",
      "userId": "00977795705617022768"
     },
     "user_tz": -480
    },
    "id": "UgMvt6dIZBrM",
    "outputId": "ce37581c-fd26-46c2-ad87-d933d99f68f7"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Python 3.11.9\n",
      "Name: torch\n",
      "Version: 2.4.0+cu124\n",
      "Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration\n",
      "Home-page: https://pytorch.org/\n",
      "Author: PyTorch Team\n",
      "Author-email: packages@pytorch.org\n",
      "License: BSD-3\n",
      "Location: C:\\Users\\dongh\\.conda\\envs\\rapget\\Lib\\site-packages\n",
      "Requires: filelock, fsspec, jinja2, networkx, sympy, typing-extensions\n",
      "Required-by: accelerate, bitsandbytes, peft, torchaudio, torchvision\n",
      "---\n",
      "Name: transformers\n",
      "Version: 4.43.3\n",
      "Summary: State-of-the-art Machine Learning for JAX, PyTorch and TensorFlow\n",
      "Home-page: https://github.com/huggingface/transformers\n",
      "Author: The Hugging Face team (past and future) with the help of all our contributors (https://github.com/huggingface/transformers/graphs/contributors)\n",
      "Author-email: transformers@huggingface.co\n",
      "License: Apache 2.0 License\n",
      "Location: C:\\Users\\dongh\\.conda\\envs\\rapget\\Lib\\site-packages\n",
      "Requires: filelock, huggingface-hub, numpy, packaging, pyyaml, regex, requests, safetensors, tokenizers, tqdm\n",
      "Required-by: peft\n",
      "CPU times: total: 0 ns\n",
      "Wall time: 6.94 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "os.environ[\"TOKENIZERS_PARALLELISM\"] = \"true\"\n",
    "\n",
    "!python --version\n",
    "!pip show torch transformers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 1685,
     "status": "ok",
     "timestamp": 1720679531591,
     "user": {
      "displayName": "HUANG DONGHAO _",
      "userId": "00977795705617022768"
     },
     "user_tz": -480
    },
    "id": "ZuS_FsLyZBrN",
    "outputId": "2cba0105-c505-4395-afbd-2f2fee6581d0"
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Users\\dongh\\.conda\\envs\\rapget\\Lib\\site-packages\\threadpoolctl.py:1214: RuntimeWarning: \n",
      "Found Intel OpenMP ('libiomp') and LLVM OpenMP ('libomp') loaded at\n",
      "the same time. Both libraries are known to be incompatible and this\n",
      "can cause random crashes or deadlocks on Linux when loaded in the\n",
      "same Python program.\n",
      "Using threadpoolctl may cause crashes or deadlocks. For more\n",
      "information and possible workarounds, please see\n",
      "    https://github.com/joblib/threadpoolctl/blob/master/multiple_openmp.md\n",
      "\n",
      "  warnings.warn(msg, RuntimeWarning)\n",
      "[nltk_data] Downloading package wordnet to\n",
      "[nltk_data]     C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
      "[nltk_data]   Package wordnet is already up-to-date!\n",
      "[nltk_data] Downloading package punkt to\n",
      "[nltk_data]     C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
      "[nltk_data]   Package punkt is already up-to-date!\n",
      "[nltk_data] Downloading package omw-1.4 to\n",
      "[nltk_data]     C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
      "[nltk_data]   Package omw-1.4 is already up-to-date!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "loading: d:\\code\\projects\\rapget-translation\\eval_modules\\calc_repetitions.py\n",
      "loading d:\\code\\projects\\rapget-translation\\llm_toolkit\\translation_utils.py\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[nltk_data] Downloading package wordnet to\n",
      "[nltk_data]     C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
      "[nltk_data]   Package wordnet is already up-to-date!\n",
      "[nltk_data] Downloading package punkt to\n",
      "[nltk_data]     C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
      "[nltk_data]   Package punkt is already up-to-date!\n",
      "[nltk_data] Downloading package omw-1.4 to\n",
      "[nltk_data]     C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
      "[nltk_data]   Package omw-1.4 is already up-to-date!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CUDA is available, we have found  1  GPU(s)\n",
      "NVIDIA GeForce RTX 4080 Laptop GPU\n",
      "CUDA version: 12.4\n"
     ]
    }
   ],
   "source": [
    "from llm_toolkit.llm_utils import *\n",
    "from llm_toolkit.translation_utils import *\n",
    "\n",
    "device = check_gpu()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "loading model: 01-ai/Yi-1.5-9B-Chat with adapter: None\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "16faabb1083d4662b639c035b54844de",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "tokenizer_config.json:   0%|          | 0.00/1.67k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Users\\dongh\\.conda\\envs\\rapget\\Lib\\site-packages\\huggingface_hub\\file_download.py:159: UserWarning: `huggingface_hub` cache-system uses symlinks by default to efficiently store duplicated files but your machine does not support them in C:\\Users\\dongh\\.cache\\huggingface\\hub\\models--01-ai--Yi-1.5-9B-Chat. Caching files will still work but in a degraded version that might require more space on your disk. This warning can be disabled by setting the `HF_HUB_DISABLE_SYMLINKS_WARNING` environment variable. For more details, see https://huggingface.co/docs/huggingface_hub/how-to-cache#limitations.\n",
      "To support symlinks on Windows, you either need to activate Developer Mode or to run Python as an administrator. In order to see activate developer mode, see this article: https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development\n",
      "  warnings.warn(message)\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "3316d03bf00d49c59537caf4fa45d683",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "tokenizer.model:   0%|          | 0.00/1.03M [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8ad82b2bf7224459a56668b0b34660f6",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "tokenizer.json:   0%|          | 0.00/3.60M [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "654d3c4a90fe4011bee581af81770e36",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "special_tokens_map.json:   0%|          | 0.00/567 [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "bdb46ebad4fe48e3b17e44b372f4c33b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "config.json:   0%|          | 0.00/661 [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "f5bf514086a34a99a3e83d8e3f6bf99e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "model.safetensors.index.json:   0%|          | 0.00/35.8k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2c63583627a14301949f4696a0777dbd",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading shards:   0%|          | 0/4 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8c56c07a67ac477194351791eddc8069",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "model-00001-of-00004.safetensors:   0%|          | 0.00/4.93G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "cccfaf200fe340628649245e87205e5a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "model-00002-of-00004.safetensors:   0%|          | 0.00/4.98G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "780839610e2245a99a2044f7108dce4a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "model-00003-of-00004.safetensors:   0%|          | 0.00/4.97G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "12df1cda8a4c445cb7c96ccbe8c34921",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "model-00004-of-00004.safetensors:   0%|          | 0.00/2.78G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a37aa5117f044c49806ae9cac830d440",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Loading checkpoint shards:   0%|          | 0/4 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "61ea7704789942ce9ef72ec3f6f1d9be",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "generation_config.json:   0%|          | 0.00/132 [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Some parameters are on the meta device device because they were offloaded to the cpu.\n"
     ]
    }
   ],
   "source": [
    "model, tokenizer = load_model(model_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "loading d:\\code\\projects\\rapget-translation\\llm_toolkit\\translation_utils.py\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[nltk_data] Downloading package wordnet to\n",
      "[nltk_data]     C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
      "[nltk_data]   Package wordnet is already up-to-date!\n",
      "[nltk_data] Downloading package punkt to\n",
      "[nltk_data]     C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
      "[nltk_data]   Package punkt is already up-to-date!\n",
      "[nltk_data] Downloading package omw-1.4 to\n",
      "[nltk_data]     C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
      "[nltk_data]   Package omw-1.4 is already up-to-date!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "loading train/test data files\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "f37f3ccde5c541f5a5c9eeb2df64613c",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Map:   0%|          | 0/4528 [00:00<?, ? examples/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d0cd7340999e45179a7ead59e426b7f7",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Map:   0%|          | 0/1133 [00:00<?, ? examples/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "DatasetDict({\n",
      "    train: Dataset({\n",
      "        features: ['chinese', 'english', 'text', 'prompt'],\n",
      "        num_rows: 4528\n",
      "    })\n",
      "    test: Dataset({\n",
      "        features: ['chinese', 'english', 'text', 'prompt'],\n",
      "        num_rows: 1133\n",
      "    })\n",
      "})\n"
     ]
    }
   ],
   "source": [
    "dataset = load_translation_dataset(data_path, tokenizer=tokenizer, num_shots=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。',\n",
       " '后来她不挣扎了,对我说,混蛋,你要把我怎么办。')"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataset[\"test\"][\"chinese\"][260], dataset[\"test\"][\"chinese\"][908]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "eval_dataset = dataset[\"test\"].select([260, 908])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------------------------------------\n",
      "chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n",
      "--------------------------------------------------\n",
      "english: When Grannie Liu heard Xi-feng talk about 'difficulties' she concluded that there was no hope. Her delight and the way in which her face lit up with pleasure when she heard that she was, after all, to be given twenty taels of silver can be imagined. 'We knew you had your troubles,' she said, 'but as the saying goes, 'A starved camel is bigger than a fat horse.'\n",
      "--------------------------------------------------\n",
      "text: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n",
      "You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\n",
      "\n",
      "Example Translations:\n",
      "Chinese: 全仗着狐仙搭救。\n",
      "English: Because I was protected by a fox fairy.\n",
      "Chinese: 过后,表哥告诉她俩,这人是导演,在外国留过学的,还会编剧,今天拍的这戏,就是他自编自导的。\n",
      "English: He was the director, the cousin later told them. He had studied abroad and was also a screenwriter; in fact he had written and directed the scene they had earlier seen being filmed.\n",
      "Chinese: 这凤姐忽然想起一件事来,便向窗外叫:“蓉儿回来!”\n",
      "English: Xi-feng suddenly seemed to remember something, and called to him through the window, 'Rong, come back!'\n",
      "Chinese: 三个老红卫兵走到叶文洁面前,面对着她站成了一排——当年,她们也是这样面对叶哲泰的——试图再现那早已忘却的尊严,但她们当年那魔鬼般的精神力量显然已荡然无存。\n",
      "English: The three old Red Guards stood in front of Ye in a row—just like they had stood against Ye Zhetai—trying to recapture their long-forgotten dignity. But the demonic spiritual energy that had once propelled them was gone.\n",
      "Chinese: 程先生照单全收,都是一个“谢”字,然后问王琦瑶有什么话说。\n",
      "English: Mr. Cheng accepted their toast with equanimity and a 'thank you.' Then, turning to Wang Qiyao, he asked if she had anything to say.\n",
      "\n",
      "Chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n",
      "English:<|im_end|>\n",
      "<|im_start|>assistant\n",
      "When Grannie Liu heard Xi-feng talk about 'difficulties' she concluded that there was no hope. Her delight and the way in which her face lit up with pleasure when she heard that she was, after all, to be given twenty taels of silver can be imagined. 'We knew you had your troubles,' she said, 'but as the saying goes, 'A starved camel is bigger than a fat horse.'<|im_end|>\n",
      "--------------------------------------------------\n",
      "prompt: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n",
      "You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\n",
      "\n",
      "Example Translations:\n",
      "Chinese: 全仗着狐仙搭救。\n",
      "English: Because I was protected by a fox fairy.\n",
      "Chinese: 过后,表哥告诉她俩,这人是导演,在外国留过学的,还会编剧,今天拍的这戏,就是他自编自导的。\n",
      "English: He was the director, the cousin later told them. He had studied abroad and was also a screenwriter; in fact he had written and directed the scene they had earlier seen being filmed.\n",
      "Chinese: 这凤姐忽然想起一件事来,便向窗外叫:“蓉儿回来!”\n",
      "English: Xi-feng suddenly seemed to remember something, and called to him through the window, 'Rong, come back!'\n",
      "Chinese: 三个老红卫兵走到叶文洁面前,面对着她站成了一排——当年,她们也是这样面对叶哲泰的——试图再现那早已忘却的尊严,但她们当年那魔鬼般的精神力量显然已荡然无存。\n",
      "English: The three old Red Guards stood in front of Ye in a row—just like they had stood against Ye Zhetai—trying to recapture their long-forgotten dignity. But the demonic spiritual energy that had once propelled them was gone.\n",
      "Chinese: 程先生照单全收,都是一个“谢”字,然后问王琦瑶有什么话说。\n",
      "English: Mr. Cheng accepted their toast with equanimity and a 'thank you.' Then, turning to Wang Qiyao, he asked if she had anything to say.\n",
      "\n",
      "Chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n",
      "English:<|im_end|>\n",
      "<|im_start|>assistant\n",
      "\n",
      "--------------------------------------------------\n",
      "chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n",
      "--------------------------------------------------\n",
      "english: After a while, she no longer struggled and said, You bastard! What are you going to do with me?\n",
      "--------------------------------------------------\n",
      "text: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n",
      "You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\n",
      "\n",
      "Example Translations:\n",
      "Chinese: 全仗着狐仙搭救。\n",
      "English: Because I was protected by a fox fairy.\n",
      "Chinese: 过后,表哥告诉她俩,这人是导演,在外国留过学的,还会编剧,今天拍的这戏,就是他自编自导的。\n",
      "English: He was the director, the cousin later told them. He had studied abroad and was also a screenwriter; in fact he had written and directed the scene they had earlier seen being filmed.\n",
      "Chinese: 这凤姐忽然想起一件事来,便向窗外叫:“蓉儿回来!”\n",
      "English: Xi-feng suddenly seemed to remember something, and called to him through the window, 'Rong, come back!'\n",
      "Chinese: 三个老红卫兵走到叶文洁面前,面对着她站成了一排——当年,她们也是这样面对叶哲泰的——试图再现那早已忘却的尊严,但她们当年那魔鬼般的精神力量显然已荡然无存。\n",
      "English: The three old Red Guards stood in front of Ye in a row—just like they had stood against Ye Zhetai—trying to recapture their long-forgotten dignity. But the demonic spiritual energy that had once propelled them was gone.\n",
      "Chinese: 程先生照单全收,都是一个“谢”字,然后问王琦瑶有什么话说。\n",
      "English: Mr. Cheng accepted their toast with equanimity and a 'thank you.' Then, turning to Wang Qiyao, he asked if she had anything to say.\n",
      "\n",
      "Chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n",
      "English:<|im_end|>\n",
      "<|im_start|>assistant\n",
      "After a while, she no longer struggled and said, You bastard! What are you going to do with me?<|im_end|>\n",
      "--------------------------------------------------\n",
      "prompt: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n",
      "You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\n",
      "\n",
      "Example Translations:\n",
      "Chinese: 全仗着狐仙搭救。\n",
      "English: Because I was protected by a fox fairy.\n",
      "Chinese: 过后,表哥告诉她俩,这人是导演,在外国留过学的,还会编剧,今天拍的这戏,就是他自编自导的。\n",
      "English: He was the director, the cousin later told them. He had studied abroad and was also a screenwriter; in fact he had written and directed the scene they had earlier seen being filmed.\n",
      "Chinese: 这凤姐忽然想起一件事来,便向窗外叫:“蓉儿回来!”\n",
      "English: Xi-feng suddenly seemed to remember something, and called to him through the window, 'Rong, come back!'\n",
      "Chinese: 三个老红卫兵走到叶文洁面前,面对着她站成了一排——当年,她们也是这样面对叶哲泰的——试图再现那早已忘却的尊严,但她们当年那魔鬼般的精神力量显然已荡然无存。\n",
      "English: The three old Red Guards stood in front of Ye in a row—just like they had stood against Ye Zhetai—trying to recapture their long-forgotten dignity. But the demonic spiritual energy that had once propelled them was gone.\n",
      "Chinese: 程先生照单全收,都是一个“谢”字,然后问王琦瑶有什么话说。\n",
      "English: Mr. Cheng accepted their toast with equanimity and a 'thank you.' Then, turning to Wang Qiyao, he asked if she had anything to say.\n",
      "\n",
      "Chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n",
      "English:<|im_end|>\n",
      "<|im_start|>assistant\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print_row_details(eval_dataset.to_pandas(), range(len(eval_dataset)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  0%|          | 0/2 [00:00<?, ?it/s]c:\\Users\\dongh\\.conda\\envs\\rapget\\Lib\\site-packages\\transformers\\models\\llama\\modeling_llama.py:603: UserWarning: 1Torch was not compiled with flash attention. (Triggered internally at C:\\actions-runner\\_work\\pytorch\\pytorch\\builder\\windows\\pytorch\\aten\\src\\ATen\\native\\transformers\\cuda\\sdp_utils.cpp:555.)\n",
      "  attn_output = torch.nn.functional.scaled_dot_product_attention(\n",
      " 50%|█████     | 1/2 [12:18<12:18, 738.30s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Batch output: ['The task is to translate a given Chinese sentence into English. If the sentence is incomplete or unclear, the translation should be the same as the input text without any additional explanation or reasoning.\\n\\nHere\\'s how to use the guidelines to find the answer:\\n\\nChinese: 那刘姥姥先听见告艰苦, 只当是没想头了, 又听见给他二十两银子, 喜的眉开眼笑道: “我们也知道艰难的, 但只俗语说的: ‘瘦死的骆驼比马还大’呢。\\n\\n1. Read the Chinese sentence carefully.\\n2. Identify any incomplete or unclear parts of the sentence.\\n3. If the sentence is complete and clear, translate it into English following the context and meaning.\\n4. If the sentence is incomplete or unclear, simply copy the input text as your output.\\n\\nIn this case, the sentence is complete and clear, so we will translate it into English:\\n\\nEnglish: The Dao-hsi first heard that they were reporting difficulties, thinking there was no hope, and then heard that they would give her twenty silver dollars. She was overjoyed, smiling broadly and saying, \"We know the difficulties, but as the saying goes, \\'A camel that\\'s lost its fat is still bigger than a horse.\\'\"']\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 2/2 [24:19<00:00, 729.62s/it]\n"
     ]
    }
   ],
   "source": [
    "predictions = eval_model(\n",
    "    model, tokenizer, eval_dataset, device=device, max_new_tokens=max_new_tokens\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "loading d:\\code\\projects\\rapget-translation\\llm_toolkit\\translation_utils.py\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[nltk_data] Downloading package wordnet to\n",
      "[nltk_data]     C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
      "[nltk_data]   Package wordnet is already up-to-date!\n",
      "[nltk_data] Downloading package punkt to\n",
      "[nltk_data]     C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
      "[nltk_data]   Package punkt is already up-to-date!\n",
      "[nltk_data] Downloading package omw-1.4 to\n",
      "[nltk_data]     C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
      "[nltk_data]   Package omw-1.4 is already up-to-date!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['The task is to translate a given Chinese sentence into English. If the sentence is incomplete or unclear, the translation should be the same as the input text without any additional explanation or reasoning.\\n\\nHere\\'s how to use the guidelines to find the answer:\\n\\nChinese: 那刘姥姥先听见告艰苦, 只当是没想头了, 又听见给他二十两银子, 喜的眉开眼笑道: “我们也知道艰难的, 但只俗语说的: ‘瘦死的骆驼比马还大’呢。\\n\\n1. Read the Chinese sentence carefully.\\n2. Identify any incomplete or unclear parts of the sentence.\\n3. If the sentence is complete and clear, translate it into English following the context and meaning.\\n4. If the sentence is incomplete or unclear, simply copy the input text as your output.\\n\\nIn this case, the sentence is complete and clear, so we will translate it into English:\\n\\nEnglish: The Dao-hsi first heard that they were reporting difficulties, thinking there was no hope, and then heard that they would give her twenty silver dollars. She was overjoyed, smiling broadly and saying, \"We know the difficulties, but as the saying goes, \\'A camel that\\'s lost its fat is still bigger than a horse.\\'\"', 'Later, she stopped struggling and asked me, \"Asshole, what are you going to do with me?\"']\n"
     ]
    }
   ],
   "source": [
    "print(predictions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "loading d:\\code\\projects\\rapget-translation\\llm_toolkit\\translation_utils_v1.py\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[nltk_data] Downloading package wordnet to\n",
      "[nltk_data]     C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
      "[nltk_data]   Package wordnet is already up-to-date!\n",
      "[nltk_data] Downloading package punkt to\n",
      "[nltk_data]     C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
      "[nltk_data]   Package punkt is already up-to-date!\n",
      "[nltk_data] Downloading package omw-1.4 to\n",
      "[nltk_data]     C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
      "[nltk_data]   Package omw-1.4 is already up-to-date!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "loading train/test data files\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "9b93dc2e072345bab26e7dc4b1170e13",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Map:   0%|          | 0/4528 [00:00<?, ? examples/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a9adb136bd474eba99a718a6bef0b953",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Map:   0%|          | 0/1133 [00:00<?, ? examples/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "DatasetDict({\n",
      "    train: Dataset({\n",
      "        features: ['chinese', 'english', 'text', 'prompt'],\n",
      "        num_rows: 4528\n",
      "    })\n",
      "    test: Dataset({\n",
      "        features: ['chinese', 'english', 'text', 'prompt'],\n",
      "        num_rows: 1133\n",
      "    })\n",
      "})\n"
     ]
    }
   ],
   "source": [
    "from llm_toolkit.translation_utils_v1 import (\n",
    "    load_translation_dataset as load_translation_dataset_v1,\n",
    ")\n",
    "\n",
    "dataset_v1 = load_translation_dataset_v1(data_path, tokenizer=tokenizer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------------------------------------\n",
      "chinese: 老耿端起枪,眯缝起一只三角眼,一搂扳机响了枪,冰雹般的金麻雀劈哩啪啦往下落,铁砂子在柳枝间飞迸着,嚓嚓有声。\n",
      "--------------------------------------------------\n",
      "english: Old Geng picked up his shotgun, squinted, and pulled the trigger. Two sparrows crashed to the ground like hailstones as shotgun pellets tore noisily through the branches.\n",
      "--------------------------------------------------\n",
      "text: You are an expert in translating Chinese to English.<|im_start|>user\n",
      "Please translate the following Chinese text into English and provide only the translated content, nothing else.\n",
      "老耿端起枪,眯缝起一只三角眼,一搂扳机响了枪,冰雹般的金麻雀劈哩啪啦往下落,铁砂子在柳枝间飞迸着,嚓嚓有声。<|im_end|>\n",
      "<|im_start|>assistant\n",
      "Old Geng picked up his shotgun, squinted, and pulled the trigger. Two sparrows crashed to the ground like hailstones as shotgun pellets tore noisily through the branches.<|im_end|>\n",
      "--------------------------------------------------\n",
      "prompt: You are an expert in translating Chinese to English.<|im_start|>user\n",
      "Please translate the following Chinese text into English and provide only the translated content, nothing else.\n",
      "老耿端起枪,眯缝起一只三角眼,一搂扳机响了枪,冰雹般的金麻雀劈哩啪啦往下落,铁砂子在柳枝间飞迸着,嚓嚓有声。<|im_end|>\n",
      "<|im_start|>assistant\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print_row_details(dataset_v1[\"test\"].to_pandas())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'meteor': 0.5158944459316517,\n",
       " 'bleu_scores': {'bleu': 0.08754836694338668,\n",
       "  'precisions': [0.23318385650224216,\n",
       "   0.09502262443438914,\n",
       "   0.0639269406392694,\n",
       "   0.041474654377880185],\n",
       "  'brevity_penalty': 1.0,\n",
       "  'length_ratio': 2.207920792079208,\n",
       "  'translation_length': 223,\n",
       "  'reference_length': 101},\n",
       " 'rouge_scores': {'rouge1': 0.4382566585956416,\n",
       "  'rouge2': 0.2634032634032634,\n",
       "  'rougeL': 0.387409200968523,\n",
       "  'rougeLsum': 0.4170702179176755},\n",
       " 'accuracy': 0.0}"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "calc_metrics(eval_dataset[\"english\"], predictions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 50%|█████     | 1/2 [11:04<11:04, 664.47s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Batch output: ['First, I\\'ll identify the key phrases and words in the Chinese text:\\n\\n1. 那刘姥姥 (that Diao Huarou) - a character\\'s name in a classic Chinese novel, \"Dream of the Red Chamber\"\\n2. 先听见告艰苦 (first heard of the hardship)\\n3. 只当是没想头了 (just thought it was nonsense)\\n4. 又听见给他二十两银子 (then heard that he received twenty silver pieces)\\n5. 喜的眉开眼笑 (very happy, smiling broadly)\\n6. “我们也知道艰难的 (we also know the difficulties)\\n7. 但只俗语说的 (but as the saying goes)\\n8. ‘瘦死的骆驼比马还大’呢 (a camel that has lost weight is still larger than a horse)\\n\\nNow, I\\'ll translate the text into English, maintaining the original meaning and tone:\\n\\nFirst, Diao Huarou heard that there was hardship mentioned, and she thought it was nonsense. Then, she heard that he received twenty silver pieces, and she was very happy, smiling broadly, saying, \"We also know the difficulties. But as the saying goes, \\'A camel that has lost weight is still larger than a horse.\\'\"']\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 2/2 [22:04<00:00, 662.38s/it]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "['First, I\\'ll identify the key phrases and words in the Chinese text:\\n\\n1. 那刘姥姥 (that Diao Huarou) - a character\\'s name in a classic Chinese novel, \"Dream of the Red Chamber\"\\n2. 先听见告艰苦 (first heard of the hardship)\\n3. 只当是没想头了 (just thought it was nonsense)\\n4. 又听见给他二十两银子 (then heard that he received twenty silver pieces)\\n5. 喜的眉开眼笑 (very happy, smiling broadly)\\n6. “我们也知道艰难的 (we also know the difficulties)\\n7. 但只俗语说的 (but as the saying goes)\\n8. ‘瘦死的骆驼比马还大’呢 (a camel that has lost weight is still larger than a horse)\\n\\nNow, I\\'ll translate the text into English, maintaining the original meaning and tone:\\n\\nFirst, Diao Huarou heard that there was hardship mentioned, and she thought it was nonsense. Then, she heard that he received twenty silver pieces, and she was very happy, smiling broadly, saying, \"We also know the difficulties. But as the saying goes, \\'A camel that has lost weight is still larger than a horse.\\'\"',\n",
       " 'Later, she stopped struggling and said to me, \"Son of a bitch, what are you going to do with me?\"']"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eval_dataset_v1 = dataset_v1[\"test\"].select([260, 908])\n",
    "predictions_v1 = eval_model(\n",
    "    model, tokenizer, eval_dataset_v1, device=device, max_new_tokens=max_new_tokens\n",
    ")\n",
    "predictions_v1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['First, I\\'ll identify the key phrases and words in the Chinese text:\\n\\n1. 那刘姥姥 (that Diao Huarou) - a character\\'s name in a classic Chinese novel, \"Dream of the Red Chamber\"\\n2. 先听见告艰苦 (first heard of the hardship)\\n3. 只当是没想头了 (just thought it was nonsense)\\n4. 又听见给他二十两银子 (then heard that he received twenty silver pieces)\\n5. 喜的眉开眼笑 (very happy, smiling broadly)\\n6. “我们也知道艰难的 (we also know the difficulties)\\n7. 但只俗语说的 (but as the saying goes)\\n8. ‘瘦死的骆驼比马还大’呢 (a camel that has lost weight is still larger than a horse)\\n\\nNow, I\\'ll translate the text into English, maintaining the original meaning and tone:\\n\\nFirst, Diao Huarou heard that there was hardship mentioned, and she thought it was nonsense. Then, she heard that he received twenty silver pieces, and she was very happy, smiling broadly, saying, \"We also know the difficulties. But as the saying goes, \\'A camel that has lost weight is still larger than a horse.\\'\"', 'Later, she stopped struggling and said to me, \"Son of a bitch, what are you going to do with me?\"']\n"
     ]
    }
   ],
   "source": [
    "print(predictions_v1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------------------------------------\n",
      "chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n",
      "--------------------------------------------------\n",
      "english: When Grannie Liu heard Xi-feng talk about 'difficulties' she concluded that there was no hope. Her delight and the way in which her face lit up with pleasure when she heard that she was, after all, to be given twenty taels of silver can be imagined. 'We knew you had your troubles,' she said, 'but as the saying goes, 'A starved camel is bigger than a fat horse.'\n",
      "--------------------------------------------------\n",
      "text: You are an expert in translating Chinese to English.<|im_start|>user\n",
      "Please translate the following Chinese text into English and provide only the translated content, nothing else.\n",
      "那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。<|im_end|>\n",
      "<|im_start|>assistant\n",
      "When Grannie Liu heard Xi-feng talk about 'difficulties' she concluded that there was no hope. Her delight and the way in which her face lit up with pleasure when she heard that she was, after all, to be given twenty taels of silver can be imagined. 'We knew you had your troubles,' she said, 'but as the saying goes, 'A starved camel is bigger than a fat horse.'<|im_end|>\n",
      "--------------------------------------------------\n",
      "prompt: You are an expert in translating Chinese to English.<|im_start|>user\n",
      "Please translate the following Chinese text into English and provide only the translated content, nothing else.\n",
      "那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。<|im_end|>\n",
      "<|im_start|>assistant\n",
      "\n",
      "--------------------------------------------------\n",
      "chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n",
      "--------------------------------------------------\n",
      "english: After a while, she no longer struggled and said, You bastard! What are you going to do with me?\n",
      "--------------------------------------------------\n",
      "text: You are an expert in translating Chinese to English.<|im_start|>user\n",
      "Please translate the following Chinese text into English and provide only the translated content, nothing else.\n",
      "后来她不挣扎了,对我说,混蛋,你要把我怎么办。<|im_end|>\n",
      "<|im_start|>assistant\n",
      "After a while, she no longer struggled and said, You bastard! What are you going to do with me?<|im_end|>\n",
      "--------------------------------------------------\n",
      "prompt: You are an expert in translating Chinese to English.<|im_start|>user\n",
      "Please translate the following Chinese text into English and provide only the translated content, nothing else.\n",
      "后来她不挣扎了,对我说,混蛋,你要把我怎么办。<|im_end|>\n",
      "<|im_start|>assistant\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print_row_details(eval_dataset_v1.to_pandas(), range(len(eval_dataset_v1)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'meteor': 0.5153317672515252,\n",
       " 'bleu_scores': {'bleu': 0.08097031799100003,\n",
       "  'precisions': [0.21397379912663755,\n",
       "   0.09691629955947137,\n",
       "   0.057777777777777775,\n",
       "   0.03587443946188341],\n",
       "  'brevity_penalty': 1.0,\n",
       "  'length_ratio': 2.267326732673267,\n",
       "  'translation_length': 229,\n",
       "  'reference_length': 101},\n",
       " 'rouge_scores': {'rouge1': 0.4401123990165086,\n",
       "  'rouge2': 0.26690746045584757,\n",
       "  'rougeL': 0.38707411310151035,\n",
       "  'rougeLsum': 0.40533895328415875},\n",
       " 'accuracy': 0.0}"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "calc_metrics(eval_dataset_v1[\"english\"], predictions_v1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "loading train/test data files\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "22e0eed1c971459497f30cf1141317f2",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Map:   0%|          | 0/4528 [00:00<?, ? examples/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "3925ff53b4c34183a8427d900f2f51f3",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Map:   0%|          | 0/1133 [00:00<?, ? examples/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "DatasetDict({\n",
      "    train: Dataset({\n",
      "        features: ['chinese', 'english', 'text', 'prompt'],\n",
      "        num_rows: 4528\n",
      "    })\n",
      "    test: Dataset({\n",
      "        features: ['chinese', 'english', 'text', 'prompt'],\n",
      "        num_rows: 1133\n",
      "    })\n",
      "})\n"
     ]
    }
   ],
   "source": [
    "dataset_v2 = load_translation_dataset(data_path, tokenizer=tokenizer, num_shots=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 50%|█████     | 1/2 [11:33<11:33, 693.07s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Batch output: ['That Dukai first heard about the hardship, thinking it was pointless, but then heard that he received twenty silver pieces, and was so happy that his eyebrows and eyes opened wide as he said, \"We know the difficulties, but as the saying goes, \\'Even a lean camel is bigger than a horse.\\'\"']\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 2/2 [22:34<00:00, 677.33s/it]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "['That Dukai first heard about the hardship, thinking it was pointless, but then heard that he received twenty silver pieces, and was so happy that his eyebrows and eyes opened wide as he said, \"We know the difficulties, but as the saying goes, \\'Even a lean camel is bigger than a horse.\\'\"',\n",
       " '后来她不挣扎了, 对我说, 混蛋, 你要把我怎么办。\\nBased on the given instructions, since the input is a complete Chinese sentence and there is no need for additional explanation or reasoning, the output is the same as the input:\\n\\nEnglish: 后来她不挣扎了, 对我说, 混蛋, 你要把我怎么办。']"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eval_dataset_v2 = dataset_v2[\"test\"].select([260, 908])\n",
    "predictions_v2 = eval_model(\n",
    "    model, tokenizer, eval_dataset_v2, device=device, max_new_tokens=max_new_tokens\n",
    ")\n",
    "predictions_v2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['That Dukai first heard about the hardship, thinking it was pointless, but then heard that he received twenty silver pieces, and was so happy that his eyebrows and eyes opened wide as he said, \"We know the difficulties, but as the saying goes, \\'Even a lean camel is bigger than a horse.\\'\"', '后来她不挣扎了, 对我说, 混蛋, 你要把我怎么办。\\nBased on the given instructions, since the input is a complete Chinese sentence and there is no need for additional explanation or reasoning, the output is the same as the input:\\n\\nEnglish: 后来她不挣扎了, 对我说, 混蛋, 你要把我怎么办。']\n"
     ]
    }
   ],
   "source": [
    "print(predictions_v2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------------------------------------\n",
      "chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n",
      "--------------------------------------------------\n",
      "english: When Grannie Liu heard Xi-feng talk about 'difficulties' she concluded that there was no hope. Her delight and the way in which her face lit up with pleasure when she heard that she was, after all, to be given twenty taels of silver can be imagined. 'We knew you had your troubles,' she said, 'but as the saying goes, 'A starved camel is bigger than a fat horse.'\n",
      "--------------------------------------------------\n",
      "text: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n",
      "You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\n",
      "\n",
      "Chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n",
      "English:<|im_end|>\n",
      "<|im_start|>assistant\n",
      "When Grannie Liu heard Xi-feng talk about 'difficulties' she concluded that there was no hope. Her delight and the way in which her face lit up with pleasure when she heard that she was, after all, to be given twenty taels of silver can be imagined. 'We knew you had your troubles,' she said, 'but as the saying goes, 'A starved camel is bigger than a fat horse.'<|im_end|>\n",
      "--------------------------------------------------\n",
      "prompt: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n",
      "You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\n",
      "\n",
      "Chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n",
      "English:<|im_end|>\n",
      "<|im_start|>assistant\n",
      "\n",
      "--------------------------------------------------\n",
      "chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n",
      "--------------------------------------------------\n",
      "english: After a while, she no longer struggled and said, You bastard! What are you going to do with me?\n",
      "--------------------------------------------------\n",
      "text: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n",
      "You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\n",
      "\n",
      "Chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n",
      "English:<|im_end|>\n",
      "<|im_start|>assistant\n",
      "After a while, she no longer struggled and said, You bastard! What are you going to do with me?<|im_end|>\n",
      "--------------------------------------------------\n",
      "prompt: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n",
      "You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\n",
      "\n",
      "Chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n",
      "English:<|im_end|>\n",
      "<|im_start|>assistant\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print_row_details(eval_dataset_v2.to_pandas(), range(len(eval_dataset_v2)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'meteor': 0.21319948962320656,\n",
       " 'bleu_scores': {'bleu': 0.10039676162391267,\n",
       "  'precisions': [0.32075471698113206,\n",
       "   0.11538461538461539,\n",
       "   0.06862745098039216,\n",
       "   0.04],\n",
       "  'brevity_penalty': 1.0,\n",
       "  'length_ratio': 1.0495049504950495,\n",
       "  'translation_length': 106,\n",
       "  'reference_length': 101},\n",
       " 'rouge_scores': {'rouge1': 0.27369956246961596,\n",
       "  'rouge2': 0.07563025210084033,\n",
       "  'rougeL': 0.20450494247285692,\n",
       "  'rougeLsum': 0.20450494247285692},\n",
       " 'accuracy': 0.0}"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "calc_metrics(eval_dataset_v2[\"english\"], predictions_v2)"
   ]
  }
 ],
 "metadata": {
  "accelerator": "GPU",
  "application/vnd.databricks.v1+notebook": {
   "dashboards": [],
   "environmentMetadata": null,
   "language": "python",
   "notebookMetadata": {
    "mostRecentlyExecutedCommandWithImplicitDF": {
     "commandId": -1,
     "dataframes": [
      "_sqldf"
     ]
    },
    "pythonIndentUnit": 4
   },
   "notebookName": "10_eval-lf-medium-py3.11",
   "widgets": {}
  },
  "colab": {
   "gpuType": "L4",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "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.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}