Commit 3e8135ce authored by Baber's avatar Baber
Browse files

Merge branch 'main' into comma

parents 8e560c96 0c134ee9
import os
import shutil
import yaml
from lang_libs import LANG_LIBS, LANG_SUBJECTS
language_word_to_abbr = {
"English": "en",
"Japanese": "ja",
"Chinese": "zh",
"Korean": "ko",
"French": "fr",
"German": "de",
"Spanish": "es",
"Portuguese": "pt",
"Zulu": "zu",
"Swahili": "sw",
"Wolof": "wo",
"Yoruba": "yo",
"Thai": "th",
"Arabic": "ar",
"Hindi": "hi",
"Bengali": "bn",
"Marathi": "mr",
"Afrikaans": "af",
"Nepali": "ne",
"Telugu": "te",
"Urdu": "ur",
"Russian": "ru",
"Indonesian": "id",
"Czech": "cs",
"Hungarian": "hu",
"Italian": "it",
"Serbian": "sr",
"Ukrainian": "uk",
"Vietnamese": "vi",
}
language_abbr_to_word = {v: k for k, v in language_word_to_abbr.items()}
CURRENT_DIR = os.path.dirname(__file__)
if __name__ == "__main__":
mmlu_pro_config_dir = os.path.abspath(f"{CURRENT_DIR}/../mmlu_pro")
mmlu_prox_repo_id = "li-lab/MMLU-ProX-Lite"
for lang_abbr in language_abbr_to_word:
os.makedirs(f"{CURRENT_DIR}/{lang_abbr}", exist_ok=True)
lang_lib_list = LANG_LIBS[lang_abbr]
lang_sbj_dict = LANG_SUBJECTS[lang_abbr]
que_desc = lang_lib_list[3]
with (
open(f"{CURRENT_DIR}/template/_lang_template_yaml", "r") as reader,
open(
f"{CURRENT_DIR}/{lang_abbr}/_{lang_abbr}_lite_template_yaml",
"w",
) as writer,
):
for line in reader.readlines():
if "{repo_id}" in line:
line = line.format(repo_id=mmlu_prox_repo_id)
if "{lang}" in line:
line = line.format(lang=lang_abbr)
if "{ans_regex}" in line:
ans_regex = lang_lib_list[-1].replace(
"({})", r"\(?([ABCDEFGHIJ])\)?"
)
if lang_abbr == "en":
ans_regex = ans_regex.lstrip("the").strip()
line = line.format(ans_regex=ans_regex)
if "{que_prefix}" in line:
line = line.format(que_prefix=lang_lib_list[0])
writer.write(line)
shutil.copy(
f"{CURRENT_DIR}/template/utils.py", f"{CURRENT_DIR}/{lang_abbr}/utils.py"
)
group_name = f"mmlu_prox_lite_{lang_abbr}"
group_dict = dict(
group=group_name,
task=[f"{group_name}_{sbj}" for sbj in LANG_SUBJECTS[lang_abbr]],
aggregate_metric_list=[
dict(
aggregation="mean",
metric="exact_match",
weight_by_size=True,
filter_list="custom-extract",
)
],
metadata=dict(version=0.0),
)
with open(
f"{CURRENT_DIR}/{lang_abbr}/_{group_name}.yaml",
"w",
encoding="utf-8",
) as f:
yaml.dump(
group_dict,
f,
default_flow_style=False,
allow_unicode=True,
sort_keys=False,
)
for sbj in lang_sbj_dict:
with open(
f"{mmlu_pro_config_dir}/mmlu_pro_{sbj}.yaml", "r", encoding="utf-8"
) as f:
sbj_yaml_last_line = None
for line in f.readlines():
if line.startswith("process_docs:"):
sbj_yaml_last_line = line.strip()
sbj_dict = dict(
description=que_desc.format(
subject=lang_sbj_dict[sbj],
ans_suffix=lang_lib_list[5].format("X"),
)
+ "\n",
include=f"_{lang_abbr}_template_yaml",
task=f"{group_name}_{sbj}",
task_alias=sbj,
)
with open(
f"{CURRENT_DIR}/{lang_abbr}/{group_name}_{sbj}.yaml",
"w",
encoding="utf-8",
) as f:
yaml.dump(
sbj_dict,
f,
default_flow_style=False,
allow_unicode=True,
sort_keys=False,
)
with open(
f"{CURRENT_DIR}/{lang_abbr}/{group_name}_{sbj}.yaml",
"a",
encoding="utf-8",
) as f:
f.write(sbj_yaml_last_line + "\n")
print(f"Finished {lang_abbr}")
group: mmlu_prox_lite_mr
task:
- mmlu_prox_lite_mr_biology
- mmlu_prox_lite_mr_business
- mmlu_prox_lite_mr_chemistry
- mmlu_prox_lite_mr_computer_science
- mmlu_prox_lite_mr_economics
- mmlu_prox_lite_mr_engineering
- mmlu_prox_lite_mr_health
- mmlu_prox_lite_mr_history
- mmlu_prox_lite_mr_law
- mmlu_prox_lite_mr_math
- mmlu_prox_lite_mr_other
- mmlu_prox_lite_mr_philosophy
- mmlu_prox_lite_mr_physics
- mmlu_prox_lite_mr_psychology
aggregate_metric_list:
- aggregation: mean
metric: exact_match
weight_by_size: true
filter_list: custom-extract
metadata:
version: 0.0
group: mmlu_prox_mr
task:
- mmlu_prox_mr_biology
- mmlu_prox_mr_business
- mmlu_prox_mr_chemistry
- mmlu_prox_mr_computer_science
- mmlu_prox_mr_economics
- mmlu_prox_mr_engineering
- mmlu_prox_mr_health
- mmlu_prox_mr_history
- mmlu_prox_mr_law
- mmlu_prox_mr_math
- mmlu_prox_mr_other
- mmlu_prox_mr_philosophy
- mmlu_prox_mr_physics
- mmlu_prox_mr_psychology
aggregate_metric_list:
- aggregation: mean
metric: exact_match
weight_by_size: true
filter_list: custom-extract
metadata:
version: 0.0
dataset_path: li-lab/MMLU-ProX-Lite
dataset_name: mr
test_split: test
fewshot_split: validation
fewshot_config:
sampler: first_n
doc_to_text: !function utils.fewshot_to_text
doc_to_target: ""
output_type: generate_until
doc_to_text: !function utils.doc_to_text
doc_to_target: answer
filter_list:
- name: "custom-extract"
filter:
- function: "regex"
regex_pattern: 'उत्तर आहे \(?([ABCDEFGHIJ])\)?'
- function: "take_first"
generation_kwargs:
until:
- "</s>"
- "Q:"
- "प्रश्न:"
- "<|im_end|>"
do_sample: false
temperature: 0.0
max_gen_toks: 2048
num_fewshot: 5
metric_list:
- metric: exact_match
aggregation: mean
higher_is_better: true
ignore_case: true
ignore_punctuation: true
metadata:
version: 0.0
dataset_path: li-lab/MMLU-ProX
dataset_name: mr
test_split: test
fewshot_split: validation
fewshot_config:
sampler: first_n
doc_to_text: !function utils.fewshot_to_text
doc_to_target: ""
output_type: generate_until
doc_to_text: !function utils.doc_to_text
doc_to_target: answer
filter_list:
- name: "custom-extract"
filter:
- function: "regex"
regex_pattern: 'उत्तर आहे \(?([ABCDEFGHIJ])\)?'
- function: "take_first"
generation_kwargs:
until:
- "</s>"
- "Q:"
- "प्रश्न:"
- "<|im_end|>"
do_sample: false
temperature: 0.0
max_gen_toks: 2048
num_fewshot: 5
metric_list:
- metric: exact_match
aggregation: mean
higher_is_better: true
ignore_case: true
ignore_punctuation: true
metadata:
version: 0.0
description: 'खाली जीवशास्त्र विषयावरील बहुपर्यायी प्रश्न आहेत (उत्तरांसह). कृपया
पायरी पायरीने विचार करा आणि आपले उत्तर "उत्तर आहे (X)" असे संपवा, जिथे X हे योग्य
पर्यायाचे अक्षर आहे.
'
include: _mr_lite_template_yaml
task: mmlu_prox_lite_mr_biology
task_alias: biology
process_docs: !function utils.process_biology
description: 'खाली व्यवसाय विषयावरील बहुपर्यायी प्रश्न आहेत (उत्तरांसह). कृपया पायरी
पायरीने विचार करा आणि आपले उत्तर "उत्तर आहे (X)" असे संपवा, जिथे X हे योग्य पर्यायाचे
अक्षर आहे.
'
include: _mr_lite_template_yaml
task: mmlu_prox_lite_mr_business
task_alias: business
process_docs: !function utils.process_business
description: 'खाली रसायनशास्त्र विषयावरील बहुपर्यायी प्रश्न आहेत (उत्तरांसह). कृपया
पायरी पायरीने विचार करा आणि आपले उत्तर "उत्तर आहे (X)" असे संपवा, जिथे X हे योग्य
पर्यायाचे अक्षर आहे.
'
include: _mr_lite_template_yaml
task: mmlu_prox_lite_mr_chemistry
task_alias: chemistry
process_docs: !function utils.process_chemistry
description: 'खाली संगणकशास्त्र विषयावरील बहुपर्यायी प्रश्न आहेत (उत्तरांसह). कृपया
पायरी पायरीने विचार करा आणि आपले उत्तर "उत्तर आहे (X)" असे संपवा, जिथे X हे योग्य
पर्यायाचे अक्षर आहे.
'
include: _mr_lite_template_yaml
task: mmlu_prox_lite_mr_computer_science
task_alias: computer_science
process_docs: !function utils.process_computer_science
description: 'खाली अर्थशास्त्र विषयावरील बहुपर्यायी प्रश्न आहेत (उत्तरांसह). कृपया
पायरी पायरीने विचार करा आणि आपले उत्तर "उत्तर आहे (X)" असे संपवा, जिथे X हे योग्य
पर्यायाचे अक्षर आहे.
'
include: _mr_lite_template_yaml
task: mmlu_prox_lite_mr_economics
task_alias: economics
process_docs: !function utils.process_economics
description: 'खाली अभियांत्रिकी विषयावरील बहुपर्यायी प्रश्न आहेत (उत्तरांसह). कृपया
पायरी पायरीने विचार करा आणि आपले उत्तर "उत्तर आहे (X)" असे संपवा, जिथे X हे योग्य
पर्यायाचे अक्षर आहे.
'
include: _mr_lite_template_yaml
task: mmlu_prox_lite_mr_engineering
task_alias: engineering
process_docs: !function utils.process_engineering
description: 'खाली आरोग्य विषयावरील बहुपर्यायी प्रश्न आहेत (उत्तरांसह). कृपया पायरी
पायरीने विचार करा आणि आपले उत्तर "उत्तर आहे (X)" असे संपवा, जिथे X हे योग्य पर्यायाचे
अक्षर आहे.
'
include: _mr_lite_template_yaml
task: mmlu_prox_lite_mr_health
task_alias: health
process_docs: !function utils.process_health
description: 'खाली इतिहास विषयावरील बहुपर्यायी प्रश्न आहेत (उत्तरांसह). कृपया पायरी
पायरीने विचार करा आणि आपले उत्तर "उत्तर आहे (X)" असे संपवा, जिथे X हे योग्य पर्यायाचे
अक्षर आहे.
'
include: _mr_lite_template_yaml
task: mmlu_prox_lite_mr_history
task_alias: history
process_docs: !function utils.process_history
description: 'खाली कायदा विषयावरील बहुपर्यायी प्रश्न आहेत (उत्तरांसह). कृपया पायरी
पायरीने विचार करा आणि आपले उत्तर "उत्तर आहे (X)" असे संपवा, जिथे X हे योग्य पर्यायाचे
अक्षर आहे.
'
include: _mr_lite_template_yaml
task: mmlu_prox_lite_mr_law
task_alias: law
process_docs: !function utils.process_law
description: 'खाली गणित विषयावरील बहुपर्यायी प्रश्न आहेत (उत्तरांसह). कृपया पायरी
पायरीने विचार करा आणि आपले उत्तर "उत्तर आहे (X)" असे संपवा, जिथे X हे योग्य पर्यायाचे
अक्षर आहे.
'
include: _mr_lite_template_yaml
task: mmlu_prox_lite_mr_math
task_alias: math
process_docs: !function utils.process_math
description: 'खाली इतर विषयावरील बहुपर्यायी प्रश्न आहेत (उत्तरांसह). कृपया पायरी पायरीने
विचार करा आणि आपले उत्तर "उत्तर आहे (X)" असे संपवा, जिथे X हे योग्य पर्यायाचे अक्षर
आहे.
'
include: _mr_lite_template_yaml
task: mmlu_prox_lite_mr_other
task_alias: other
process_docs: !function utils.process_other
description: 'खाली तत्त्वज्ञान विषयावरील बहुपर्यायी प्रश्न आहेत (उत्तरांसह). कृपया
पायरी पायरीने विचार करा आणि आपले उत्तर "उत्तर आहे (X)" असे संपवा, जिथे X हे योग्य
पर्यायाचे अक्षर आहे.
'
include: _mr_lite_template_yaml
task: mmlu_prox_lite_mr_philosophy
task_alias: philosophy
process_docs: !function utils.process_philosophy
description: 'खाली भौतिकशास्त्र विषयावरील बहुपर्यायी प्रश्न आहेत (उत्तरांसह). कृपया
पायरी पायरीने विचार करा आणि आपले उत्तर "उत्तर आहे (X)" असे संपवा, जिथे X हे योग्य
पर्यायाचे अक्षर आहे.
'
include: _mr_lite_template_yaml
task: mmlu_prox_lite_mr_physics
task_alias: physics
process_docs: !function utils.process_physics
description: 'खाली मानसशास्त्र विषयावरील बहुपर्यायी प्रश्न आहेत (उत्तरांसह). कृपया
पायरी पायरीने विचार करा आणि आपले उत्तर "उत्तर आहे (X)" असे संपवा, जिथे X हे योग्य
पर्यायाचे अक्षर आहे.
'
include: _mr_lite_template_yaml
task: mmlu_prox_lite_mr_psychology
task_alias: psychology
process_docs: !function utils.process_psychology
description: 'खाली जीवशास्त्र विषयावरील बहुपर्यायी प्रश्न आहेत (उत्तरांसह). कृपया
पायरी पायरीने विचार करा आणि आपले उत्तर "उत्तर आहे (X)" असे संपवा, जिथे X हे योग्य
पर्यायाचे अक्षर आहे.
'
include: _mr_template_yaml
task: mmlu_prox_mr_biology
task_alias: biology
process_docs: !function utils.process_biology
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment