|
| 1 | +""" |
| 2 | +Take in a YAML, and output all "other" splits with this YAML |
| 3 | +""" |
| 4 | + |
| 5 | +import argparse |
| 6 | +import logging |
| 7 | +import os |
| 8 | + |
| 9 | +import yaml |
| 10 | +from tqdm import tqdm |
| 11 | + |
| 12 | + |
| 13 | +eval_logger = logging.getLogger("lm-eval") |
| 14 | + |
| 15 | +countries = { |
| 16 | + "KSA": "Gulf", |
| 17 | + "UAE": "Gulf", |
| 18 | + "Yemen": "Gulf", |
| 19 | + "Lebanon": "Levant", |
| 20 | + "Syria": "Levant", |
| 21 | + "Palestine": "Levant", |
| 22 | + "Jordan": "Levant", |
| 23 | + "Tunisia": "North Africa", |
| 24 | + "Algeria": "North Africa", |
| 25 | + "Morocco": "North Africa", |
| 26 | + "Libya": "North Africa", |
| 27 | + "Egypt": "Nile Valley", |
| 28 | + "Sudan": "Nile Valley", |
| 29 | +} |
| 30 | + |
| 31 | +VERSION = 0 |
| 32 | + |
| 33 | + |
| 34 | +def parse_args(): |
| 35 | + parser = argparse.ArgumentParser() |
| 36 | + parser.add_argument( |
| 37 | + "--base_yaml_path", default="_default_arab_culture_mcq_template_yaml" |
| 38 | + ) |
| 39 | + parser.add_argument("--save_prefix_path", default="arab_culture") |
| 40 | + return parser.parse_args() |
| 41 | + |
| 42 | + |
| 43 | +if __name__ == "__main__": |
| 44 | + args = parse_args() |
| 45 | + |
| 46 | + # get filename of base_yaml so we can `"include": ` it in our "other" YAMLs. |
| 47 | + base_yaml_name = os.path.split(args.base_yaml_path)[-1] |
| 48 | + # with open(args.base_yaml_path, encoding="utf-8") as f: |
| 49 | + # base_yaml = yaml.full_load(f) |
| 50 | + |
| 51 | + ALL_REGIONS = [] |
| 52 | + for country, region in tqdm(countries.items()): |
| 53 | + if region not in ALL_REGIONS: |
| 54 | + ALL_REGIONS.append(region) |
| 55 | + |
| 56 | + # description = f"The following are multiple choice questions (with answers) about {' '.join(subject.split('_'))}.\n\n" |
| 57 | + |
| 58 | + yaml_dict = { |
| 59 | + "include": base_yaml_name, |
| 60 | + "tag": f"arab_culture_{region.lower().replace(' ', '_')}_tasks", |
| 61 | + "task": f"arab_culture_{country.lower().replace(' ', '_')}", |
| 62 | + "task_alias": country, |
| 63 | + "dataset_name": country, |
| 64 | + # "description": description, |
| 65 | + } |
| 66 | + |
| 67 | + file_save_path = ( |
| 68 | + args.save_prefix_path |
| 69 | + + f"_{country.lower().replace(' ', '_').replace('(', '').replace(')', '')}.yaml" |
| 70 | + ) |
| 71 | + eval_logger.info(f"Saving yaml for subset {country} to {file_save_path}") |
| 72 | + with open(file_save_path, "w", encoding="utf-8") as yaml_file: |
| 73 | + yaml.dump( |
| 74 | + yaml_dict, |
| 75 | + yaml_file, |
| 76 | + allow_unicode=True, |
| 77 | + default_style='"', |
| 78 | + ) |
| 79 | + |
| 80 | + arab_culture_mcq_regions = [ |
| 81 | + f"arab_culture_{region.lower().replace(' ', '_')}" for region in ALL_REGIONS |
| 82 | + ] |
| 83 | + |
| 84 | + file_save_path = args.save_prefix_path + ".yaml" |
| 85 | + |
| 86 | + eval_logger.info(f"Saving benchmark config to {file_save_path}") |
| 87 | + |
| 88 | + for region in ALL_REGIONS: |
| 89 | + file_save_path = ( |
| 90 | + args.save_prefix_path + f"_{region.lower().replace(' ', '_')}.yaml" |
| 91 | + ) |
| 92 | + eval_logger.info(f"Saving yaml for subset {region} to {file_save_path}") |
| 93 | + with open("_" + file_save_path, "w", encoding="utf-8") as yaml_file: |
| 94 | + yaml.dump( |
| 95 | + { |
| 96 | + "group": f"arab_culture_{region.lower().replace(' ', '_')}", |
| 97 | + "group_alias": region, |
| 98 | + "task": [f"arab_culture_{region.lower().replace(' ', '_')}_tasks"], |
| 99 | + "aggregate_metric_list": {"metric": "acc", "weight_by_size": True}, |
| 100 | + "metadata": { |
| 101 | + "description": "arab Culture tasks", |
| 102 | + "version": VERSION, |
| 103 | + }, |
| 104 | + }, |
| 105 | + yaml_file, |
| 106 | + indent=4, |
| 107 | + default_flow_style=False, |
| 108 | + ) |
| 109 | + |
| 110 | + file_save_path = args.save_prefix_path + ".yaml" |
| 111 | + with open("_" + file_save_path, "w", encoding="utf-8") as yaml_file: |
| 112 | + yaml.dump( |
| 113 | + { |
| 114 | + "group": "arab_culture", |
| 115 | + "task": arab_culture_mcq_regions, |
| 116 | + "aggregate_metric_list": {"metric": "acc", "weight_by_size": True}, |
| 117 | + "metadata": {"description": "Arab Culture tasks", "version": VERSION}, |
| 118 | + }, |
| 119 | + yaml_file, |
| 120 | + indent=4, |
| 121 | + default_flow_style=False, |
| 122 | + ) |
0 commit comments