File size: 38,275 Bytes
d37d581 |
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 |
from functools import partial
import json
import multiprocessing
import os
import random
from datasets import load_dataset
# pip install -q iso-639
from iso639 import languages
from promptsource.templates import DatasetTemplates
# Set to False to use multilingual prompts e.g. 'id' for xcopa/id instead of 'en'
USE_ENGLISH_PROMPTS = True
MAX_EXAMPLES_PER_DATASET_PROMPT = 100_000
STORY_CLOZE_DIR = "/gpfswork/rech/six/commun/code/tr13f-6B3-ml-t0/story_cloze_data"
XSTORY_CLOZE_DIR = "/gpfswork/rech/six/commun/code/tr13f-6B3-ml-t0/xstory_cloze_data"
# Some datasets have test sets with hidden labels which will still compile but only to noise
# e.g. piqa test labels are all [-1] which still works on list indices resulting in
# noise samples where the label is always the same
SKIP_PROMPTS = {
"common_gen": {"test": ["all"]},
"piqa": {"test": ["all"]},
"qasc": {"test": ["all"]},
"imdb": {"unsupervised": ["all"]},
"glue/qqp": {"test": ["all"]},
"qasc": {"test": ["all"]},
"cosmos_qa": {"test": [
"description_context_question_answer_text",
"description_context_question_text",
"description_context_question_answer_id",
"context_answer_to_question",
"context_description_question_answer_text",
"context_description_question_answer_id",
"context_question_description_answer_id",
"context_description_question_text",
"context_question_description_answer_text",
"only_question_answer",
"no_prompt_id",
"context_question_description_text",
"no_prompt_text",
]},
"clue/tnews": {"test": ["all"]},
"clue/csl": {"test": ["all"]},
"clue/cmrc2018": {"test": ["generate_question", "in_an_exam", "answer_in_the_passage", "answer_following_question", "xp3longcontinue"]},
"clue/drcd": {"test": ["generate_question", "in_an_exam", "answer_in_the_passage", "answer_following_question", "xp3longcontinue"]},
"hellaswag": {"test": ["complete_first_then", "Topic of the context", "Open-ended completion", "Randomized prompts template", "Appropriate continuation - Yes or No", "Predict ending with hint", "Open-ended start", "Reversed appropriate continuation - Yes or No", "how_ends", "if_begins_how_continues"]},
}
DS_TO_ENG_PROMPT = {
"xcopa": "en",
"Muennighoff/xstory_cloze": "en",
"Muennighoff/xwinograd": "en",
'GEM/wiki_lingua': 'en_en', # Contains correct language names
'xnli': 'en',
"paws-x": "en",
"mlqa": "mlqa.en.en",
"xquad": "xquad.en",
"khalidalt/tydiqa-primary": "english",
"khalidalt/tydiqa-goldp": "english",
"pasinit/xlwic": "en",
"GEM/xlsum": "english",
"GEM/BiSECT": "en",
}
BIAS_FAIRNESS = [
('crows_pairs', None),
('jigsaw_toxicity_pred', None),
('super_glue','axg'),
('wino_bias','type1_anti'),
('wino_bias','type2_anti'),
('wino_bias','type1_pro'),
('wino_bias','type2_pro'),
]
EVAL_DATASETS_L1 = [
# ('super_glue','wsc.fixed'), # Not used due to time constraints
('winogrande','winogrande_xl'),
('super_glue','cb'),
('super_glue','rte'),
('anli',None),
('story_cloze', '2016'),
('Muennighoff/xstory_cloze', 'ar'),
('Muennighoff/xstory_cloze', 'es'),
('Muennighoff/xstory_cloze', 'eu'),
('Muennighoff/xstory_cloze', 'id'),
('Muennighoff/xstory_cloze', 'hi'),
('Muennighoff/xstory_cloze', 'te'),
('Muennighoff/xstory_cloze', 'sw'),
('Muennighoff/xstory_cloze', 'zh'),
# ('hellaswag', None), # Not used due to time constraints
('super_glue', 'copa'),
# Multilingual
('Muennighoff/xwinograd','en'),
('Muennighoff/xwinograd','fr'),
('Muennighoff/xwinograd','pt'),
('Muennighoff/xwinograd','zh'),
# ('clue', 'cluewsc2020'), # Included in 'Muennighoff/xwinograd','zh'
('xcopa','id'),
('xcopa','ta'),
('xcopa','sw'),
('xcopa','vi'),
('xcopa','zh'),
("xnli", "ar"),
("xnli", "en"),
("xnli", "es"),
("xnli", "fr"),
("xnli", "hi"),
("xnli", "sw"),
("xnli", "ur"),
("xnli", "vi"),
("xnli", "zh"),
# ("openai_humaneval", None), # Used without prompts in evaluation
# ("multi_eurlex", "all_languages")
]
ADD_TRAIN_DATASETS_L1_XP3ALL = [
('super_glue','wsc.fixed'),
('winogrande','winogrande_xl'),
('story_cloze', '2016'),
('Muennighoff/xstory_cloze', 'ar'),
('Muennighoff/xstory_cloze', 'es'),
('Muennighoff/xstory_cloze', 'eu'),
('Muennighoff/xstory_cloze', 'id'),
('Muennighoff/xstory_cloze', 'hi'),
('Muennighoff/xstory_cloze', 'te'),
('Muennighoff/xstory_cloze', 'sw'),
('Muennighoff/xstory_cloze', 'zh'),
('hellaswag', None),
('super_glue', 'copa'),
# Multilingual
('Muennighoff/xwinograd','en'),
('Muennighoff/xwinograd','fr'),
('Muennighoff/xwinograd','pt'),
('Muennighoff/xwinograd','zh'),
('clue', 'cluewsc2020'),
('xcopa','id'),
('xcopa','ta'),
('xcopa','sw'),
('xcopa','vi'),
('xcopa','zh'),
("multi_eurlex", "all_languages")
# ("openai_humaneval", None), # Low quality prompts
]
EVAL_DATASETS_L2 = [
('Muennighoff/xwinograd','jp'),
('Muennighoff/xwinograd','ru'),
('xcopa','et'),
('xcopa','ht'),
('xcopa','it'),
('xcopa','qu'),
('xcopa','th'),
('xcopa','tr'),
("xnli", "bg"),
("xnli", "de"),
("xnli", "el"),
("xnli", "ru"),
("xnli", "th"),
("xnli", "tr"),
]
TRAIN_DATASETS = [
# English-only
('glue','mrpc'),
('glue','qqp'),
('paws','labeled_final'),
('ai2_arc','ARC-Challenge'),
('ai2_arc','ARC-Easy'),
('kilt_tasks','hotpotqa'),
('trivia_qa','unfiltered'),
('web_questions',None),
('wiki_qa',None),
('adversarial_qa','dbidaf'),
('adversarial_qa','dbert'),
('adversarial_qa','droberta'),
('duorc','SelfRC'),
('duorc','ParaphraseRC'),
('ropes',None),
('squad_v2',None),
('super_glue','record'),
('quoref',None),
('cos_e','v1.11'),
('cosmos_qa',None),
('dream',None),
('openbookqa','main'),
('qasc',None),
('quail',None),
('quarel',None),
('quartz',None),
('race','high'),
('race','middle'),
('sciq',None),
('social_i_qa',None),
('super_glue','boolq'),
('super_glue','multirc'),
('wiki_hop','original'),
('wiqa',None),
('piqa',None),
('amazon_polarity',None),
('app_reviews',None),
('imdb',None),
('rotten_tomatoes',None),
('yelp_review_full',None),
('common_gen',None),
('wiki_bio',None),
('cnn_dailymail','3.0.0'),
('gigaword',None),
('multi_news',None),
('samsum',None),
('xsum',None),
('ag_news',None),
('dbpedia_14',None),
('trec',None),
# Multilingual
('GEM/wiki_lingua', 'ar'),
('GEM/wiki_lingua', 'en'),
('GEM/wiki_lingua', 'es'),
('GEM/wiki_lingua', 'fr'),
('GEM/wiki_lingua', 'hi'),
('GEM/wiki_lingua', 'id'),
('GEM/wiki_lingua', 'pt'),
('GEM/wiki_lingua', 'vi'),
('GEM/wiki_lingua', 'zh'),
('Helsinki-NLP/tatoeba_mt', 'ara-eng'),
('Helsinki-NLP/tatoeba_mt', 'ara-fra'),
('Helsinki-NLP/tatoeba_mt', 'ara-spa'),
('Helsinki-NLP/tatoeba_mt', 'ben-eng'),
('Helsinki-NLP/tatoeba_mt', 'cat-eng'),
('Helsinki-NLP/tatoeba_mt', 'cat-fra'),
('Helsinki-NLP/tatoeba_mt', 'cat-por'),
('Helsinki-NLP/tatoeba_mt', 'cat-spa'),
('Helsinki-NLP/tatoeba_mt', 'eng-cmn_Hans'),
('Helsinki-NLP/tatoeba_mt', 'eng-cmn_Hant'),
('Helsinki-NLP/tatoeba_mt', 'eng-eus'),
('Helsinki-NLP/tatoeba_mt', 'eng-fra'),
('Helsinki-NLP/tatoeba_mt', 'eng-hin'),
('Helsinki-NLP/tatoeba_mt', 'eng-ind'),
('Helsinki-NLP/tatoeba_mt', 'eng-mal'),
('Helsinki-NLP/tatoeba_mt', 'eng-mar'),
('Helsinki-NLP/tatoeba_mt', 'eng-por'),
('Helsinki-NLP/tatoeba_mt', 'eng-run'),
('Helsinki-NLP/tatoeba_mt', 'eng-spa'),
('Helsinki-NLP/tatoeba_mt', 'eng-swa'),
('Helsinki-NLP/tatoeba_mt', 'eng-tam'),
('Helsinki-NLP/tatoeba_mt', 'eng-tel'),
('Helsinki-NLP/tatoeba_mt', 'eng-urd'),
('Helsinki-NLP/tatoeba_mt', 'eng-vie'),
('Helsinki-NLP/tatoeba_mt', 'eng-zho'),
('Helsinki-NLP/tatoeba_mt', 'eus-spa'),
('Helsinki-NLP/tatoeba_mt', 'fra-cmn_Hans'),
('Helsinki-NLP/tatoeba_mt', 'fra-cmn_Hant'),
('Helsinki-NLP/tatoeba_mt', 'fra-ind'),
('Helsinki-NLP/tatoeba_mt', 'fra-por'),
('Helsinki-NLP/tatoeba_mt', 'fra-run'),
('Helsinki-NLP/tatoeba_mt', 'fra-spa'),
('Helsinki-NLP/tatoeba_mt', 'fra-vie'),
('Helsinki-NLP/tatoeba_mt', 'fra-zho'),
('Helsinki-NLP/tatoeba_mt', 'hin-urd'),
('Helsinki-NLP/tatoeba_mt', 'hin-zho'),
('Helsinki-NLP/tatoeba_mt', 'por-cmn_Hans'),
('Helsinki-NLP/tatoeba_mt', 'por-cmn_Hant'),
('Helsinki-NLP/tatoeba_mt', 'por-spa'),
('Helsinki-NLP/tatoeba_mt', 'por-zho'),
('Helsinki-NLP/tatoeba_mt', 'run-spa'),
('Helsinki-NLP/tatoeba_mt', 'spa-cmn_Hans'),
('Helsinki-NLP/tatoeba_mt', 'spa-cmn_Hant'),
('Helsinki-NLP/tatoeba_mt', 'spa-vie'),
('Helsinki-NLP/tatoeba_mt', 'spa-zho'),
('Helsinki-NLP/tatoeba_mt', 'vie-cmn_Hans'),
('Helsinki-NLP/tatoeba_mt', 'vie-zho'),
('xquad', 'xquad.ar'),
('xquad', 'xquad.zh'),
('xquad', 'xquad.vi'),
('xquad', 'xquad.en'),
('xquad', 'xquad.es'),
('xquad', 'xquad.hi'),
('mlqa', 'mlqa.ar.ar'),
('mlqa', 'mlqa.vi.vi'),
('mlqa', 'mlqa.zh.zh'),
('mlqa', 'mlqa.es.es'),
('mlqa', 'mlqa.en.en'),
('mlqa', 'mlqa.hi.hi'),
('mlqa', 'mlqa.ar.vi'),
('mlqa', 'mlqa.ar.zh'),
('mlqa', 'mlqa.ar.es'),
('mlqa', 'mlqa.ar.en'),
('mlqa', 'mlqa.ar.hi'),
('mlqa', 'mlqa.vi.ar'),
('mlqa', 'mlqa.vi.zh'),
('mlqa', 'mlqa.vi.es'),
('mlqa', 'mlqa.vi.en'),
('mlqa', 'mlqa.vi.hi'),
('mlqa', 'mlqa.zh.ar'),
('mlqa', 'mlqa.zh.vi'),
('mlqa', 'mlqa.zh.es'),
('mlqa', 'mlqa.zh.en'),
('mlqa', 'mlqa.zh.hi'),
('mlqa', 'mlqa.es.ar'),
('mlqa', 'mlqa.es.vi'),
('mlqa', 'mlqa.es.zh'),
('mlqa', 'mlqa.es.en'),
('mlqa', 'mlqa.es.hi'),
('mlqa', 'mlqa.en.ar'),
('mlqa', 'mlqa.es.vi'),
('mlqa', 'mlqa.es.zh'),
('mlqa', 'mlqa.es.es'),
('mlqa', 'mlqa.es.hi'),
('mlqa', 'mlqa.hi.ar'),
('mlqa', 'mlqa.hi.vi'),
('mlqa', 'mlqa.hi.zh'),
('mlqa', 'mlqa.hi.es'),
('mlqa', 'mlqa.hi.en'),
('paws-x', 'en'),
('paws-x', 'es'),
('paws-x', 'fr'),
('paws-x', 'zh'),
('khalidalt/tydiqa-primary', 'arabic'),
('khalidalt/tydiqa-primary', 'bengali'),
('khalidalt/tydiqa-primary', 'english'),
('khalidalt/tydiqa-primary', 'indonesian'),
('khalidalt/tydiqa-primary', 'swahili'),
('khalidalt/tydiqa-primary', 'telugu'),
('khalidalt/tydiqa-goldp', 'arabic'),
('khalidalt/tydiqa-goldp', 'bengali'),
('khalidalt/tydiqa-goldp', 'english'),
('khalidalt/tydiqa-goldp', 'indonesian'),
('khalidalt/tydiqa-goldp', 'swahili'),
('khalidalt/tydiqa-goldp', 'telugu'),
('Muennighoff/mbpp', 'sanitized'),
("great_code", None),
("neural_code_search", "evaluation_dataset"),
("codeparrot/codecomplex", "codeparrot--codecomplex"),
("codeparrot/github-jupyter-text-code-pairs", None),
("codeparrot/apps", "all"),
("codeparrot/xlcost-text-to-code", "Python-program-level"),
("codeparrot/xlcost-text-to-code", "C-program-level"),
("codeparrot/xlcost-text-to-code", "C++-program-level"),
("codeparrot/xlcost-text-to-code", "Csharp-program-level"),
("codeparrot/xlcost-text-to-code", "Java-program-level"),
("codeparrot/xlcost-text-to-code", "Javascript-program-level"),
("codeparrot/xlcost-text-to-code", "PHP-program-level"),
("teven/code_contests", None),
("teven/code_docstring_corpus", "top_level"),
("Fraser/python-state-changes", None),
('clue', 'c3'),
('clue', 'cmrc2018'),
('clue', 'csl'),
('clue', 'drcd'),
('clue', 'tnews'),
('super_glue', 'wic'),
('pasinit/xlwic', "xlwic_en_zh"),
('pasinit/xlwic', "xlwic_fr_fr"),
('GEM/BiSECT', "en"),
('GEM/BiSECT', "es"),
('GEM/BiSECT', "fr"),
('GEM/xlsum', "arabic"),
('GEM/xlsum', "bengali"),
('GEM/xlsum', "chinese_simplified"),
('GEM/xlsum', "chinese_traditional"),
('GEM/xlsum', "english"),
('GEM/xlsum', "french"),
('GEM/xlsum', "gujarati"),
('GEM/xlsum', "hindi"),
('GEM/xlsum', "igbo"),
('GEM/xlsum', "indonesian"),
('GEM/xlsum', "kirundi"),
('GEM/xlsum', "marathi"),
('GEM/xlsum', "nepali"),
('GEM/xlsum', "portuguese"),
('GEM/xlsum', "punjabi"),
('GEM/xlsum', "spanish"),
('GEM/xlsum', "swahili"),
('GEM/xlsum', "tamil"),
('GEM/xlsum', "telugu"),
('GEM/xlsum', "urdu"),
('GEM/xlsum', "vietnamese"),
('GEM/xlsum', "yoruba"),
# flores200, wmt & more wikilingua added below
]
TRAIN_DATASETS_RU = [
('GEM/xlsum', "russian"),
('khalidalt/tydiqa-primary', 'russian'),
('khalidalt/tydiqa-goldp', 'russian'),
('xquad', 'xquad.ru'),
('Helsinki-NLP/tatoeba_mt', "ara-rus"),
('Helsinki-NLP/tatoeba_mt', "eng-rus"),
('Helsinki-NLP/tatoeba_mt', "eus-rus"),
('Helsinki-NLP/tatoeba_mt', "fra-rus"),
('Helsinki-NLP/tatoeba_mt', "rus-cmn_Hans"),
('Helsinki-NLP/tatoeba_mt', "rus-cmn_Hant"),
('Helsinki-NLP/tatoeba_mt', "rus-rus"),
('Helsinki-NLP/tatoeba_mt', "rus-spa"),
('Helsinki-NLP/tatoeba_mt', "rus-uig_Arab"),
('Helsinki-NLP/tatoeba_mt', "rus-vie"),
('Helsinki-NLP/tatoeba_mt', "rus-zho"),
('GEM/wiki_lingua', 'ru'),
]
TRAIN_DATASETS_TH = [
('GEM/xlsum', "thai"),
('khalidalt/tydiqa-primary', 'thai'),
('khalidalt/tydiqa-goldp', 'thai'),
('xquad', 'xquad.th'),
]
FLORES_LANGS = [
("Acehnese (Arabic script)", "ace_Arab"),
("Acehnese (Latin script)", "ace_Latn"),
("Mesopotamian Arabic", "acm_Arab"),
("Ta’izzi-Adeni Arabic", "acq_Arab"),
("Tunisian Arabic", "aeb_Arab"),
("Afrikaans", "afr_Latn"),
("South Levantine Arabic", "ajp_Arab"),
("Akan", "aka_Latn"),
("Amharic", "amh_Ethi"),
("North Levantine Arabic", "apc_Arab"),
("Modern Standard Arabic", "arb_Arab"),
("Modern Standard Arabic (Romanized)", "arb_Latn"),
("Najdi Arabic", "ars_Arab"),
("Moroccan Arabic", "ary_Arab"),
("Egyptian Arabic", "arz_Arab"),
("Assamese", "asm_Beng"),
("Asturian", "ast_Latn"),
("Awadhi", "awa_Deva"),
("Central Aymara", "ayr_Latn"),
("South Azerbaijani", "azb_Arab"),
("North Azerbaijani", "azj_Latn"),
("Bashkir", "bak_Cyrl"),
("Bambara", "bam_Latn"),
("Balinese", "ban_Latn"),
("Belarusian", "bel_Cyrl"),
("Bemba", "bem_Latn"),
("Bengali", "ben_Beng"),
("Bhojpuri", "bho_Deva"),
("Banjar (Arabic script)", "bjn_Arab"),
("Banjar (Latin script)", "bjn_Latn"),
("Standard Tibetan", "bod_Tibt"),
("Bosnian", "bos_Latn"),
("Buginese", "bug_Latn"),
("Bulgarian", "bul_Cyrl"),
("Catalan", "cat_Latn"),
("Cebuano", "ceb_Latn"),
("Czech", "ces_Latn"),
("Chokwe", "cjk_Latn"),
("Central Kurdish", "ckb_Arab"),
("Crimean Tatar", "crh_Latn"),
("Welsh", "cym_Latn"),
("Danish", "dan_Latn"),
("German", "deu_Latn"),
("Southwestern Dinka", "dik_Latn"),
("Dyula", "dyu_Latn"),
("Dzongkha", "dzo_Tibt"),
("Greek", "ell_Grek"),
("English", "eng_Latn"),
("Esperanto", "epo_Latn"),
("Estonian", "est_Latn"),
("Basque", "eus_Latn"),
("Ewe", "ewe_Latn"),
("Faroese", "fao_Latn"),
("Fijian", "fij_Latn"),
("Finnish", "fin_Latn"),
("Fon", "fon_Latn"),
("French", "fra_Latn"),
("Friulian", "fur_Latn"),
("Nigerian Fulfulde", "fuv_Latn"),
("Scottish Gaelic", "gla_Latn"),
("Irish", "gle_Latn"),
("Galician", "glg_Latn"),
("Guarani", "grn_Latn"),
("Gujarati", "guj_Gujr"),
("Haitian Creole", "hat_Latn"),
("Hausa", "hau_Latn"),
("Hebrew", "heb_Hebr"),
("Hindi", "hin_Deva"),
("Chhattisgarhi", "hne_Deva"),
("Croatian", "hrv_Latn"),
("Hungarian", "hun_Latn"),
("Armenian", "hye_Armn"),
("Igbo", "ibo_Latn"),
("Ilocano", "ilo_Latn"),
("Indonesian", "ind_Latn"),
("Icelandic", "isl_Latn"),
("Italian", "ita_Latn"),
("Javanese", "jav_Latn"),
("Japanese", "jpn_Jpan"),
("Kabyle", "kab_Latn"),
("Jingpho", "kac_Latn"),
("Kamba", "kam_Latn"),
("Kannada", "kan_Knda"),
("Kashmiri (Arabic script)", "kas_Arab"),
("Kashmiri (Devanagari script)", "kas_Deva"),
("Georgian", "kat_Geor"),
("Central Kanuri (Arabic script)", "knc_Arab"),
("Central Kanuri (Latin script)", "knc_Latn"),
("Kazakh", "kaz_Cyrl"),
("Kabiyè", "kbp_Latn"),
("Kabuverdianu", "kea_Latn"),
("Khmer", "khm_Khmr"),
("Kikuyu", "kik_Latn"),
("Kinyarwanda", "kin_Latn"),
("Kyrgyz", "kir_Cyrl"),
("Kimbundu", "kmb_Latn"),
("Northern Kurdish", "kmr_Latn"),
("Kikongo", "kon_Latn"),
("Korean", "kor_Hang"),
("Lao", "lao_Laoo"),
("Ligurian", "lij_Latn"),
("Limburgish", "lim_Latn"),
("Lingala", "lin_Latn"),
("Lithuanian", "lit_Latn"),
("Lombard", "lmo_Latn"),
("Latgalian", "ltg_Latn"),
("Luxembourgish", "ltz_Latn"),
("Luba-Kasai", "lua_Latn"),
("Ganda", "lug_Latn"),
("Luo", "luo_Latn"),
("Mizo", "lus_Latn"),
("Standard Latvian", "lvs_Latn"),
("Magahi", "mag_Deva"),
("Maithili", "mai_Deva"),
("Malayalam", "mal_Mlym"),
("Marathi", "mar_Deva"),
("Minangkabau (Arabic script)", "min_Arab"),
("Minangkabau (Latin script)", "min_Latn"),
("Macedonian", "mkd_Cyrl"),
("Plateau Malagasy", "plt_Latn"),
("Maltese", "mlt_Latn"),
("Meitei (Bengali script)", "mni_Beng"),
("Halh Mongolian", "khk_Cyrl"),
("Mossi", "mos_Latn"),
("Maori", "mri_Latn"),
("Burmese", "mya_Mymr"),
("Dutch", "nld_Latn"),
("Norwegian Nynorsk", "nno_Latn"),
("Norwegian Bokmål", "nob_Latn"),
("Nepali", "npi_Deva"),
("Northern Sotho", "nso_Latn"),
("Nuer", "nus_Latn"),
("Nyanja", "nya_Latn"),
("Occitan", "oci_Latn"),
("West Central Oromo", "gaz_Latn"),
("Odia", "ory_Orya"),
("Pangasinan", "pag_Latn"),
("Eastern Panjabi", "pan_Guru"),
("Papiamento", "pap_Latn"),
("Western Persian", "pes_Arab"),
("Polish", "pol_Latn"),
("Portuguese", "por_Latn"),
("Dari", "prs_Arab"),
("Southern Pashto", "pbt_Arab"),
("Ayacucho Quechua", "quy_Latn"),
("Romanian", "ron_Latn"),
("Rundi", "run_Latn"),
("Russian", "rus_Cyrl"),
("Sango", "sag_Latn"),
("Sanskrit", "san_Deva"),
("Santali", "sat_Olck"),
("Sicilian", "scn_Latn"),
("Shan", "shn_Mymr"),
("Sinhala", "sin_Sinh"),
("Slovak", "slk_Latn"),
("Slovenian", "slv_Latn"),
("Samoan", "smo_Latn"),
("Shona", "sna_Latn"),
("Sindhi", "snd_Arab"),
("Somali", "som_Latn"),
("Southern Sotho", "sot_Latn"),
("Spanish", "spa_Latn"),
("Tosk Albanian", "als_Latn"),
("Sardinian", "srd_Latn"),
("Serbian", "srp_Cyrl"),
("Swati", "ssw_Latn"),
("Sundanese", "sun_Latn"),
("Swedish", "swe_Latn"),
("Swahili", "swh_Latn"),
("Silesian", "szl_Latn"),
("Tamil", "tam_Taml"),
("Tatar", "tat_Cyrl"),
("Telugu", "tel_Telu"),
("Tajik", "tgk_Cyrl"),
("Tagalog", "tgl_Latn"),
("Thai", "tha_Thai"),
("Tigrinya", "tir_Ethi"),
("Tamasheq (Latin script)", "taq_Latn"),
("Tamasheq (Tifinagh script)", "taq_Tfng"),
("Tok Pisin", "tpi_Latn"),
("Tswana", "tsn_Latn"),
("Tsonga", "tso_Latn"),
("Turkmen", "tuk_Latn"),
("Tumbuka", "tum_Latn"),
("Turkish", "tur_Latn"),
("Twi", "twi_Latn"),
("Central Atlas Tamazight", "tzm_Tfng"),
("Uyghur", "uig_Arab"),
("Ukrainian", "ukr_Cyrl"),
("Umbundu", "umb_Latn"),
("Urdu", "urd_Arab"),
("Northern Uzbek", "uzn_Latn"),
("Venetian", "vec_Latn"),
("Vietnamese", "vie_Latn"),
("Waray", "war_Latn"),
("Wolof", "wol_Latn"),
("Xhosa", "xho_Latn"),
("Eastern Yiddish", "ydd_Hebr"),
("Yoruba", "yor_Latn"),
("Yue Chinese", "yue_Hant"),
("Chinese (Simplified)", "zho_Hans"),
("Chinese (Traditional)", "zho_Hant"),
("Standard Malay", "zsm_Latn"),
("Zulu", "zul_Latn"),
]
WMT22_LANGS = [
("afr", "eng"),
("afr", "som"),
("amh", "eng"),
("amh", "fra"),
("amh", "nya"),
("amh", "orm"),
("amh", "sna"),
("amh", "som"),
("amh", "ssw"),
("amh", "swh"),
("amh", "tsn"),
("amh", "tso"),
("amh", "umb"),
("amh", "xho"),
("amh", "yor"),
("amh", "zul"),
("eng", "fuv"),
("eng", "hau"),
("eng", "ibo"),
("eng", "kam"),
("eng", "kin"),
("eng", "lin"),
("eng", "lug"),
("eng", "luo"),
("eng", "nso"),
("eng", "nya"),
("eng", "orm"),
("eng", "sna"),
("eng", "som"),
("eng", "ssw"),
("eng", "swh"),
("eng", "tsn"),
("eng", "tso"),
("eng", "umb"),
("eng", "wol"),
("eng", "xho"),
("eng", "yor"),
("eng", "zul"),
("fra", "hau"),
("fra", "ibo"),
("fra", "kam"),
("fra", "kin"),
("fra", "lin"),
("fra", "lug"),
("fra", "luo"),
("fra", "nso"),
("fra", "nya"),
("fra", "orm"),
("fra", "som"),
("fra", "ssw"),
("fra", "swh"),
("fra", "tsn"),
("fra", "tso"),
("fra", "umb"),
("fra", "wol"),
("fra", "xho"),
("fra", "zul"),
("fuv", "hau"),
("fuv", "ibo"),
("fuv", "kam"),
("fuv", "kin"),
("fuv", "lug"),
("fuv", "luo"),
("fuv", "nso"),
("fuv", "nya"),
("fuv", "orm"),
("fuv", "sna"),
("fuv", "som"),
("fuv", "ssw"),
("fuv", "swh"),
("fuv", "tsn"),
("fuv", "tso"),
("fuv", "umb"),
("fuv", "xho"),
("fuv", "yor"),
("fuv", "zul"),
("hau", "ibo"),
("hau", "kam"),
("hau", "kin"),
("hau", "lug"),
("hau", "luo"),
("hau", "nso"),
("hau", "nya"),
("hau", "orm"),
("hau", "sna"),
("hau", "som"),
("hau", "ssw"),
("hau", "swh"),
("hau", "tsn"),
("hau", "tso"),
("hau", "umb"),
("hau", "xho"),
("hau", "yor"),
("hau", "zul"),
("ibo", "kam"),
("ibo", "kin"),
("ibo", "lug"),
("ibo", "luo"),
("ibo", "nso"),
("ibo", "nya"),
("ibo", "orm"),
("ibo", "sna"),
("ibo", "som"),
("ibo", "ssw"),
("ibo", "swh"),
("ibo", "tsn"),
("ibo", "tso"),
("ibo", "umb"),
("ibo", "xho"),
("ibo", "yor"),
("ibo", "zul"),
("kam", "kin"),
("kam", "lug"),
("kam", "luo"),
("kam", "nso"),
("kam", "nya"),
("kam", "orm"),
("kam", "sna"),
("kam", "som"),
("kam", "ssw"),
("kam", "swh"),
("kam", "tsn"),
("kam", "tso"),
("kam", "umb"),
("kam", "xho"),
("kam", "yor"),
("kam", "zul"),
("kin", "lug"),
("kin", "luo"),
("kin", "nso"),
("kin", "nya"),
("kin", "orm"),
("kin", "sna"),
("kin", "som"),
("kin", "ssw"),
("kin", "swh"),
("kin", "tsn"),
("kin", "tso"),
("kin", "umb"),
("kin", "xho"),
("kin", "yor"),
("kin", "zul"),
("lug", "luo"),
("lug", "nso"),
("lug", "nya"),
("lug", "orm"),
("lug", "sna"),
("lug", "som"),
("lug", "ssw"),
("lug", "swh"),
("lug", "tsn"),
("lug", "tso"),
("lug", "umb"),
("lug", "xho"),
("lug", "yor"),
("lug", "zul"),
("luo", "nso"),
("luo", "nya"),
("luo", "orm"),
("luo", "sna"),
("luo", "som"),
("luo", "ssw"),
("luo", "swh"),
("luo", "tsn"),
("luo", "tso"),
("luo", "umb"),
("luo", "xho"),
("luo", "yor"),
("luo", "zul"),
("nso", "nya"),
("nso", "orm"),
("nso", "sna"),
("nso", "som"),
("nso", "ssw"),
("nso", "swh"),
("nso", "tsn"),
("nso", "tso"),
("nso", "umb"),
("nso", "xho"),
("nso", "yor"),
("nso", "zul"),
("nya", "orm"),
("nya", "sna"),
("nya", "som"),
("nya", "ssw"),
("nya", "swh"),
("nya", "tsn"),
("nya", "tso"),
("nya", "umb"),
("nya", "xho"),
("nya", "yor"),
("nya", "zul"),
("orm", "sna"),
("orm", "som"),
("orm", "ssw"),
("orm", "swh"),
("orm", "tsn"),
("orm", "tso"),
("orm", "umb"),
("orm", "xho"),
("orm", "yor"),
("orm", "zul"),
("sna", "som"),
("sna", "ssw"),
("sna", "swh"),
("sna", "tsn"),
("sna", "tso"),
("sna", "umb"),
("sna", "xho"),
("sna", "yor"),
("sna", "zul"),
("som", "ssw"),
("som", "swh"),
("som", "tsn"),
("som", "tso"),
("som", "umb"),
("som", "wol"),
("som", "xho"),
("som", "yor"),
("som", "zul"),
("ssw", "swh"),
("ssw", "tsn"),
("ssw", "tso"),
("ssw", "umb"),
("ssw", "xho"),
("ssw", "yor"),
("ssw", "zul"),
("swh", "tsn"),
("swh", "tso"),
("swh", "umb"),
("swh", "xho"),
("swh", "yor"),
("swh", "zul"),
("tsn", "tso"),
("tsn", "umb"),
("tsn", "xho"),
("tsn", "yor"),
("tsn", "zul"),
("tso", "umb"),
("tso", "xho"),
("tso", "yor"),
("tso", "zul"),
("umb", "xho"),
("umb", "yor"),
("umb", "zul"),
("xho", "yor"),
("xho", "zul"),
("yor", "zul"),
]
# Copied from metadata
SINGLE_LANGUAGE = "ru"
SINGLE_LANGUAGE_LONG = "rus"
SINGLE_LANGUAGE_NAME = "Russian"
BLOOM_LANGS = """
- ak
- ar
- as
- bm
- bn
- ca
- code
- en
- es
- eu
- fon
- fr
- gu
- hi
- id
- ig
- ki
- kn
- lg
- ln
- ml
- mr
- ne
- nso
- ny
- or
- pa
- pt
- rn
- rw
- sn
- st
- sw
- ta
- te
- tn
- ts
- tum
- tw
- ur
- vi
- wo
- xh
- yo
- zh
- zu
- ru
"""
DS_TO_LANG = {
'Muennighoff/mbpp': 'code',
'openai_humaneval': 'code',
"great_code": "code",
"neural_code_search": "code",
"codeparrot/codecomplex": "code",
"codeparrot/github-jupyter-text-code-pairs": "code",
"codeparrot/apps": "code",
"Fraser/python-state-changes": "code",
"codeparrot/xlcost-text-to-code": "code",
"teven/code_contests": "code",
"teven/code_docstring_corpus": "code",
"clue": "zh",
"cmn": "zh", # == zho
"npi": "ne", # == npe
"ory": "or", # == ori
"swh": "sw", # == swa
"kirundi": "rn", # == rundi
"punjabi": "pa", # == panjabi
"chinese_simplified": "zh",
"chinese_traditional": "zh",
}
bloom_lang_codes_iso3 = []
bloom_lang_codes_iso2 = []
for lang in BLOOM_LANGS.split("\n")[1:-1]:
iso2 = lang.replace("- ", "")
DS_TO_LANG[iso2] = iso2
try:
name = languages.get(alpha2=iso2)
DS_TO_LANG[name.name.lower()] = iso2
# name is e.g. 'swahili (macrolanguage)' also add swahili
DS_TO_LANG[name.name.lower().split(" ")[0]] = iso2
iso3 = name.part3
DS_TO_LANG[iso3] = iso2
except KeyError:
print(f"Could not find iso3 code for {lang}.")
# Add GEM multilingual
WIKILINGUA_LANGS = ["ar", "en", "es", "fr", "hi", "id", "pt", "vi", "zh"] + [SINGLE_LANGUAGE]
for l1_code in WIKILINGUA_LANGS:
for l2_code in WIKILINGUA_LANGS:
if l1_code == l2_code:
continue
if SINGLE_LANGUAGE:
if (l1_code != SINGLE_LANGUAGE) and (l2_code != SINGLE_LANGUAGE):
continue
TRAIN_DATASETS_RU.append(("GEM/wiki_lingua", f"{l1_code}_{l2_code}"))
# Add flores200
for (l1_name, l1_code) in FLORES_LANGS:
for (l2_name, l2_code) in FLORES_LANGS:
if l1_code.split("_")[0] not in DS_TO_LANG or l2_code.split("_")[0] not in DS_TO_LANG:
print(f"Skipping as {l1_name} or {l2_name} was not pre-trained on.")
continue
elif l1_name == l2_name:
continue
if (SINGLE_LANGUAGE_NAME not in l1_name) and (SINGLE_LANGUAGE_NAME not in l2_name):
print(f"Skipping {l1_name}, {l2_name}, {SINGLE_LANGUAGE_NAME}")
continue
TRAIN_DATASETS_RU.append(("facebook/flores", f"{l1_code}-{l2_code}"))
# Add wmt22
for (l1_code, l2_code) in WMT22_LANGS:
if l1_code not in DS_TO_LANG or l2_code not in DS_TO_LANG:
print(f"Skipping as {l1_code} or {l2_code} was not pre-trained on.")
continue
elif l1_code == l2_code:
continue
if SINGLE_LANGUAGE_LONG:
if (l1_code != SINGLE_LANGUAGE_LONG) and (l2_code != SINGLE_LANGUAGE_LONG):
continue
TRAIN_DATASETS_RU.append(("allenai/wmt22_african", f"{l1_code}-{l2_code}"))
### DATASET CREATION ###
# Copied from promptsource.utils
def removeHyphen(example):
example_clean = {}
for key in example.keys():
if "-" in key:
new_key = key.replace("-", "_")
example_clean[new_key] = example[key]
else:
example_clean[key] = example[key]
example = example_clean
return example
def apply_template(dataset, template, strip_connection=True):
def map_fn(ex):
ex = removeHyphen(ex)
try:
inputs_and_targets = template.apply(
ex,
strip_connection=strip_connection,
truncate=True,
)
# Skip ValueError("Prompt did not produce an input and at least one target.")
# which happens for some prompts with if else clauses based on inputs producing occasional
# empty targets
except ValueError:
return {"inputs": "", "targets": ""}
if len(inputs_and_targets) == 2:
# Note that the signature changed in promptsource
# In 0.1.0 template.apply returned two strings; In >0.3.0 it retuns a str & list
inputs, targets = inputs_and_targets
if len(targets) > 1:
# Safer to skip, as could be a bug
print(f"Found targets longer than 1. Inputs: {inputs} ; Targets {targets}. Skipping.")
return {"inputs": "", "targets": ""}
targets = targets[0]
return {"inputs": inputs, "targets": targets}
# When template results in an empty example, template.apply returns [""]
# Also, if the template gets split wrong, len can be > 2
# We will filter these out later
else:
# inputs is a str by default & targets a str
return {"inputs": "", "targets": ""}
def filter_fn(ex):
return len(ex["inputs"]) > 0 and len(ex["targets"]) > 0
original_columns = dataset.column_names
dataset = dataset.map(map_fn).filter(filter_fn)
# map keeps original columns, remove them
return dataset.remove_columns(set(original_columns) - {"inputs", "targets"})
def add_language_name_wikilingua(example):
example["source_language_name"] = languages.get(alpha2=example["source_language"]).name
example["target_language_name"] = languages.get(alpha2=example["target_language"]).name
return example
def filter_l1_l2_wikilingua(example, l1, l2):
return example["source_language"] == l1 and example["target_language"] == l2
def filter_empty_solution_apps(example):
return bool(example["solutions"])
def add_solution_apps(example):
example["solution"] = random.choice(json.loads(example["solutions"]))
return example
def clean_code_xlcost(example):
clean_lines = []
cur_indent = 0
for line in example["code"].split("NEW_LINE"):
cur_indent += line.count("INDENT")
cur_indent -= line.count("DEDENT")
line = line.replace("INDENT", "").replace("DEDENT", "")
line = line.replace("STRNEWLINE", "\n")
line = line.replace("TABSYMBOL", "\t")
clean_lines.append("\t" * cur_indent + line.strip())
example["code_clean"] = "\n".join(clean_lines)
return example
def write_to_jsonl_hub(ds, split="train"):
### GET DATASET & LANGUAGE ###
ds_name, subset_name = ds
is_wikilingua_cross_lingual = (ds_name == "GEM/wiki_lingua") and ("_") in subset_name
lang_dir = DS_TO_LANG.get(ds_name, None)
if lang_dir is None:
lang_dir = DS_TO_LANG.get(subset_name, "en")
if ds_name == "facebook/flores":
lang_dir = DS_TO_LANG.get(subset_name.split("-")[-1].split("_")[0])
elif is_wikilingua_cross_lingual or ds_name == "pasinit/xlwic":
lang_dir = DS_TO_LANG.get(subset_name.split("_")[-1])
elif ds_name == "xquad":
lang_dir = DS_TO_LANG.get(subset_name.split(".")[1])
elif ds_name == "mlqa":
# Classify it by the target language for cross-lingual (i.e. what the loss is computed on)
lang_dir = DS_TO_LANG.get(subset_name.split(".")[1])
os.makedirs(lang_dir, exist_ok=True)
if ds_name == "Helsinki-NLP/tatoeba_mt":
ds = load_dataset(ds_name, subset_name, ignore_verifications=True, revision="49aa20ac768eabc5a106a123549ea58053fc9b40")
elif ds_name == "story_cloze":
ds = load_dataset(ds_name, subset_name, data_dir=STORY_CLOZE_DIR)
elif ds_name == "Muennighoff/xstory_cloze":
ds = load_dataset(ds_name, subset_name, data_dir=XSTORY_CLOZE_DIR)
else:
ds = load_dataset(ds_name, subset_name)
if ds_name == "GEM/wiki_lingua":
# Add names, e.g. Chinese for zh to use them in the jinja prompts
ds = ds.map(add_language_name_wikilingua)
if is_wikilingua_cross_lingual:
# Keep only L1 -> L2 (L2 -> L1 will be a separate dataset)
ds = ds.filter(partial(filter_l1_l2_wikilingua, l1=subset_name.split("_")[0], l2=subset_name.split("_")[1]))
elif ds_name == "codeparrot/apps":
ds = ds.filter(filter_empty_solution_apps).map(add_solution_apps)
elif ds_name == "codeparrot/xlcost-text-to-code":
ds = ds.map(clean_code_xlcost)
### SELECT SPLITS ###
dataset_splits = list(ds.keys())
if subset_name == "xlwic_en_zh":
# Train set is en; val & test are zh
dataset_splits.remove("train")
elif ds_name == "teven/code_docstring_corpus":
# Bad quality split
dataset_splits.remove("class_level")
if split == "validation":
if split not in dataset_splits or len(dataset_splits) == 1:
print(f"Validation not found for {ds_name}")
return
dataset_splits = ["validation"]
elif split == "train":
# Use as much as possible
# Would need to remove e.g. test datasets to benchmark same task performance
if len(dataset_splits) > 1 and "validation" in dataset_splits:
dataset_splits.remove("validation")
# WikiLingua
if "sampled_validation" in dataset_splits:
dataset_splits.remove("sampled_validation")
if "sampled_test" in dataset_splits:
dataset_splits.remove("sampled_test")
### SELECT PROMPTS ###
if subset_name is None:
prompt_dataset_name = ds_name
else:
subset_name_prompt = subset_name
if USE_ENGLISH_PROMPTS and ds_name in DS_TO_ENG_PROMPT:
subset_name_prompt = DS_TO_ENG_PROMPT[ds_name]
prompt_dataset_name = f"{ds_name}/{subset_name_prompt}"
prompts = DatasetTemplates(prompt_dataset_name)
### PROCESS ###
for split in dataset_splits:
for t_name in prompts.all_template_names:
print(f"Running {ds_name}/{subset_name}/{split}/{t_name}")
if SKIP_PROMPTS.get(prompt_dataset_name, {}).get(split, False):
if ("all" in SKIP_PROMPTS[prompt_dataset_name][split]) or (t_name in SKIP_PROMPTS[prompt_dataset_name][split]):
print(f"Skipping DS: {prompt_dataset_name} Split {split} Prompt {t_name}")
continue
if ds_name == "Helsinki-NLP/tatoeba_mt":
# E.g. translate-this-ara-eng, where eng is the target
lang_dir = DS_TO_LANG.get(t_name.split("-")[-1].split("_")[0], "en")
elif ds_name in ("allenai/wmt22_african", "multi_eurlex"):
# One prompt in multi_eurlex has -source+target appended to the languages
lang_dir = DS_TO_LANG.get(t_name.replace("-source+target", "").split("-")[-1])
out_path = os.path.join(
lang_dir,
f'xp3_{ds_name}_{subset_name}_{split}_{t_name}.jsonl'.replace("/", "_").replace(" ", "_")
)
if os.path.exists(out_path):
print("Skipping as exists: ", out_path)
continue
assert len(ds[split]) > 0, f"Got empty: {ds_name}"
try:
if ds_name == "allenai/wmt22_african":
# Sort by laser score, i.e. by increasing confidence & limit samples due to mediocre quality
ds[split] = ds[split].sort("laser_score", reverse=True)
max_range = min(len(ds[split]), MAX_EXAMPLES_PER_DATASET_PROMPT // 2)
else:
# Allow 5x buffer for empty examples
max_range = min(len(ds[split]), MAX_EXAMPLES_PER_DATASET_PROMPT * 5)
# Shuffle to avoid using the same subset
# Leave \n in-between input & targets for code
out_ds = apply_template(
dataset=ds[split].shuffle().select(list(range(max_range))),
template=prompts[t_name],
strip_connection=False if lang_dir == "code" else True
)
# Keep X shortest examples
max_range = min(len(out_ds), MAX_EXAMPLES_PER_DATASET_PROMPT)
out_ds = out_ds.sort("inputs").select(list(range(max_range)))
except Exception as e:
print(f"Skipping due to {e}. DS: {ds_name}/{subset_name} Template: {t_name}")
continue
# Do not force ascii to allow chars like é
if len(out_ds) > 0:
out_ds.to_json(out_path, orient="records", lines=True, force_ascii=False)
# Testing:
#TRAIN_DATASETS = [
# ('xquad', 'xquad.ar'),
#]
#for ds in TRAIN_DATASETS_RU:
# write_to_jsonl_hub(ds, split="train")
with multiprocessing.Pool(processes=32) as pool:
pool.map(partial(write_to_jsonl_hub, split="train"), TRAIN_DATASETS_RU)
#pool.map(partial(write_to_jsonl_hub, split="train"), TRAIN_DATASETS)
#pool.map(partial(write_to_jsonl_hub, split="validation"), TRAIN_DATASETS)
#pool.map(partial(write_to_jsonl_hub, split="train"), ADD_TRAIN_DATASETS_L1_XP3ALL)
#pool.map(partial(write_to_jsonl_hub, split="validation"), ADD_TRAIN_DATASETS_L1_XP3ALL)
|