_generate_configs.py 3.9 KB
Newer Older
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
"""
Take in a YAML, and output all "other" splits with this YAML
"""

import argparse
import logging
import os

import yaml
from tqdm import tqdm


eval_logger = logging.getLogger("lm-eval")


MMLU_SUBJECTS = {
    "global_facts": "other",
    "high_school_european_history": "humanities",
    "high_school_geography": "social_sciences",
    "high_school_government_and_politics": "social_sciences",
    "high_school_psychology": "social_sciences",
    "high_school_statistics": "stem",
    "high_school_world_history": "humanities",
    "human_aging": "other",
    "international_law": "humanities",
    "jurisprudence": "humanities",
    "logical_fallacies": "humanities",
    "management": "other",
    "marketing": "other",
    "moral_disputes": "humanities",
    "moral_scenarios": "humanities",
    "nutrition": "other",
    "philosophy": "humanities",
    "professional_law": "humanities",
    "professional_psychology": "social_sciences",
    "public_relations": "social_sciences",
    "security_studies": "social_sciences",
    "sociology": "social_sciences",
    "world_religions": "humanities",
}


ARABIC_MMLU_SUBJECTS = {
    "islamic_studies": "humanities",
    "driving_test": "other",
    "natural_science": "stem",
    "history": "humanities",
    "general_knowledge": "other",
    "law": "humanities",
    "physics": "stem",
    "social_science": "social_sciences",
    "management_ar": "other",
    "arabic_language": "language",
    "political_science": "social_sciences",
    "philosophy_ar": "humanities",
    "accounting": "social_sciences",
    "computer_science": "stem",
    "geography": "social_sciences",
    "math": "stem",
    "biology": "stem",
    "economics": "social_sciences",
    "arabic_language_(general)": "language",
    "arabic_language_(grammar)": "language",
64
    "civics": "social_sciences",
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
}

DATASETS = {
    "mmlu": MMLU_SUBJECTS,
    "ar_mmlu": ARABIC_MMLU_SUBJECTS,
}


def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument("--base_yaml_path", default="_default_darijammlu_template_yaml")
    parser.add_argument("--save_prefix_path", default="darijammlu")
    return parser.parse_args()


if __name__ == "__main__":
    args = parse_args()

    # get filename of base_yaml so we can `"include": ` it in our "other" YAMLs.
    base_yaml_name = os.path.split(args.base_yaml_path)[-1]
    with open(args.base_yaml_path, encoding="utf-8") as f:
        base_yaml = yaml.full_load(f)

    ALL_CATEGORIES = []
    for dataset, SUBJECTS in DATASETS.items():
        for subject, category in tqdm(SUBJECTS.items()):
            if category not in ALL_CATEGORIES:
                ALL_CATEGORIES.append(category)

            yaml_dict = {
                "include": base_yaml_name,
96
97
98
99
                "tag": [
                    f"darijammlu_{category}_tasks",
                    "darijammlu_" + dataset + "_tasks",
                ],
100
101
102
103
104
                "task": f"darijammlu_{subject}",
                "task_alias": subject.replace("_", " "),
                "dataset_name": subject,
            }

105
            file_save_path = args.save_prefix_path + f"_{subject}.yaml"
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
            eval_logger.info(f"Saving yaml for subset {subject} to {file_save_path}")
            with open(file_save_path, "w", encoding="utf-8") as yaml_file:
                yaml.dump(
                    yaml_dict,
                    yaml_file,
                    allow_unicode=True,
                    default_style='"',
                )

    darijammlu_subcategories = [f"darijammlu_{category}" for category in ALL_CATEGORIES]

    file_save_path = args.save_prefix_path + ".yaml"

    eval_logger.info(f"Saving benchmark config to {file_save_path}")
    with open(file_save_path, "w", encoding="utf-8") as yaml_file:
        yaml.dump(
            {
                "group": "darijammlu",
                "task": darijammlu_subcategories,
            },
            yaml_file,
            indent=4,
            default_flow_style=False,
129
        )