Unverified Commit 18297993 authored by Jess's avatar Jess Committed by GitHub
Browse files

AfroBench: How Good are Large Language Models on African Languages? (#2825)



* add afrixnli to task

* add chat completion

* remove chat completion -untested

* afrimmlu added

* afrimmlu folder update

* afrimmlu folder update

* updated prompt

* remove print

* add afrimgsm -direct

* add squad metric

* fix bash script

* remove direct util, update common yaml

* remove print

* add few show. metric fixes

* fix direct path, add bash script for gpt models

* added transate test

* update afrixnli tasks

* update afrixnli tasks

* update metrics for afrixnli

* prompt translations fix

* prompt translations fix

* filter and metric fix -mgsm

* remove squad metric

* remove squad metric

* add f1 score to mgsm

* add f1 score to mgsm

* update native-direct with lin

* change f1 function

* add lin to utils

* add utils

* remove test limit

* remove test configs

* add swahili to mmlu

* change eng to ewe in ewe yaml mmlu

* add squad metric to mgsm, remove whitespace filter

* added translate test

* added afrixnli_translate

* fix exact match valueError

* fix exact match valueError

* restructure mmlu folder

* spacing

* remove afrimmlu_translate folder

* add utility

* format task name, clean ups

* modefied mgsm

* update on afrimgsm

* update on afrimgsm

* removed utils

* other mgsm varieties

* other mgsm varieties

* adding trasnslate direct

* Update translate_direct_yaml

* add manual xnli prompt, add multichoice for openai models, and adapt multichoice metric for openai model

* edit for open models

* Update translate_direct_yaml

* add verbalizer for xnli

* change xnli from multiple choice to generate

* add manual accuracy scores

* revert xnli to multiple choice

* change afrimgsm utils

* revert xnli to multiple_choice

* cleanups and readmes

* remove openai fixes and unused regex

* pr review changes

* revert metrics.py, task.py and extraction.py to main version

* add afrisenti

* utilities

* pulled from main

* add afrixnli

* add afrimmlu

* update afrixnli prompts

* mising senti language

* fix afrisenti prompt 2

* fix afrisenti prompts

* fix afrisenti prompts

* configure task grouping

* add multiple prompts to afrixnli for irokobench

* add multiple prompts to afrimmlu for irokobench

* Update afrixnli_yaml

* fixes and moves

* fixes and moves

* afrimmlu multiple prompts configs

* remove validation set from afrimmlu

* remove eng from afrimmlu translate test

* correct dataset path

* multiple prompts for mgsm

* file restructure

* afribench grouping

* repo restructuring

* repo restructuring

* update exact match to hugging face exact match and add new mgsm language

* remove decontamination

* update generation kwargs

* update generation kwargs for all mgsm prompts

* remove lang

* update generation kwargs for afrimgsm translatetest

* add afrimgsm cot for direct and translate

* remove eng from translate-cot

* add masakhaPOS tasks

* remove changes from task script

* add masakhanews tasks

* add uhura arc easy

* add afriqa and belebele files

* add tags for easier run. add naija rc

* add new metrics and transformation scripts

* fix afriqa swa fewshot split

* add naijarc

* add afrobench lite tasks

* update afrobench

* update afrobench

* remove unverified files to avoid bugs

* remove files not needed

* add afrobench tasks

* add afrobench tasks

* change to version 1

* change to version 1

* update afrobench

* update afrobench

* restore metric to original script

* update readme instructions

* add individual dataset readmes

* add link to collections

* correct run script

* align with main

* align with main

* align with main

* align with main

* align with main

* align with main

* align with main

* align with main

* failed run fixes

* failed run fixes

* add afrimgsm cot

* Apply precommit fixes

* update mafand dataset name

* pull request fixes

* remove afrihate due to availability

---------
Co-authored-by: default avatarIsrael Abebe Azime <azime@cg.uni-saarland.de>
Co-authored-by: default avatarIsrael Abebe Azime <se.israel.abebe@gmail.com>
Co-authored-by: default avatarDavid Adelani <davlanade@gmail.com>
Co-authored-by: default avatartheyorubayesian <akin.o.oladipo@gmail.com>
parent cf51e699
# Generated by utils.py
dataset_name: twi
doc_to_text: "Based on the given statement, is the following claim 'true', 'false',\
\ or 'inconclusive'. \nStatement: {{premise}} \nClaim: {{hypothesis}}"
include: afrixnli_yaml
task: afrixnli_twi_prompt_5
# Generated by utils.py
dataset_name: wol
doc_to_text: "Based on the given statement, is the following claim 'true', 'false',\
\ or 'inconclusive'. \nStatement: {{premise}} \nClaim: {{hypothesis}}"
include: afrixnli_yaml
task: afrixnli_wol_prompt_5
# Generated by utils.py
dataset_name: xho
doc_to_text: "Based on the given statement, is the following claim 'true', 'false',\
\ or 'inconclusive'. \nStatement: {{premise}} \nClaim: {{hypothesis}}"
include: afrixnli_yaml
task: afrixnli_xho_prompt_5
tag:
- afrixnli_tasks
- afrixnli_tasks_prompt_5
dataset_path: masakhane/afrixnli
dataset_name: null
output_type: multiple_choice
validation_split: validation
test_split: test
fewshot_split: validation
doc_to_target: !function utils.doc_to_target
doc_to_choice:
- "true"
- "inconclusive"
- "false"
should_decontaminate: true
doc_to_decontamination_query: premise
metric_list:
- metric: f1
aggregation: !function utils.weighted_f1_score
average: weighted
higher_is_better: True
ignore_case: true
ignore_punctuation: true
- metric: acc
aggregation: mean
higher_is_better: true
ignore_case: true
ignore_punctuation: true
metadata:
version: 1.0
# Generated by utils.py
dataset_name: yor
doc_to_text: "Based on the given statement, is the following claim 'true', 'false',\
\ or 'inconclusive'. \nStatement: {{premise}} \nClaim: {{hypothesis}}"
include: afrixnli_yaml
task: afrixnli_yor_prompt_5
# Generated by utils.py
dataset_name: zul
doc_to_text: "Based on the given statement, is the following claim 'true', 'false',\
\ or 'inconclusive'. \nStatement: {{premise}} \nClaim: {{hypothesis}}"
include: afrixnli_yaml
task: afrixnli_zul_prompt_5
from lm_eval.utils import weighted_f1_score
def doc_to_target(doc):
replacements = {0: "true", 1: "false", 2: "inconclusive"}
return replacements[doc["label"]]
import argparse
import os
import yaml
class FunctionTag:
def __init__(self, value):
self.value = value
def prompt_func(mode, lang):
prompt_map = {
"prompt_1": "Please identify whether the premise entails or contradicts the hypothesis in the following premise "
"and hypothesis. The answer should be exact entailment, contradiction, or neutral.\n\nPremise: {premise}\nHypothesis: {hypothesis}\n\n"
"Is it entailment, contradiction, or neutral?",
"prompt_3": f"Given the following premise and hypothesis in {lang}, identify if the premise entails, contradicts, "
f"or is neutral towards the hypothesis. Please respond with exact 'entailment', 'contradiction', or 'neutral'. \n\n"
"Premise: {{premise}} \nHypothesis: {{hypothesis}}",
"prompt_4": f"You are an expert in Natural Language Inference (NLI) specializing in the {lang} language.\n"
f"Analyze the premise and hypothesis given in {lang}, and determine the relationship between them.\n "
f"Respond with one of the following options: 'entailment', 'contradiction', or 'neutral'. \n\n"
"Premise: {{premise}} \nHypothesis: {{hypothesis}}",
"prompt_5": "Based on the given statement, is the following claim 'true', 'false', or 'inconclusive'. \n"
"Statement: {{premise}} \nClaim: {{hypothesis}}",
}
return prompt_map[mode]
def gen_lang_yamls(output_dir: str, overwrite: bool, mode: str) -> None:
"""
Generate a yaml file for each language.
:param output_dir: The directory to output the files to.
:param overwrite: Whether to overwrite files if they already exist.
"""
err = []
languages = {
"eng": "English",
"amh": "Amharic",
"ibo": "Igbo",
"fra": "French",
"sna": "chiShona",
"wol": "Wolof",
"ewe": "Ewe",
"lin": "Lingala",
"lug": "Luganda",
"xho": "isiXhosa",
"kin": "Kinyarwanda",
"twi": "Twi",
"zul": "Zulu",
"orm": "Oromo",
"yor": "Yoruba",
"hau": "Hausa",
"sot": "Sesotho",
"swa": "Swahili",
}
for lang in languages.keys():
try:
file_name = f"afrixnli_{lang}.yaml"
task_name = f"afrixnli_{lang}_{mode}"
yaml_template = "afrixnli_yaml"
if output_dir.split("/")[-1] == "translate":
file_name = f"afrixnli_translate_{lang}.yaml"
task_name = f"afrixnli_translate_{lang}_{mode}"
yaml_template = "afrixnli_translate_yaml"
if int(mode.split("_")[-1]) == 1 or int(mode.split("_")[-1]) > 2:
yaml_details = {
"include": yaml_template,
"task": task_name,
"dataset_name": lang,
"doc_to_text": prompt_func(mode, languages[lang]),
}
else:
yaml_details = {
"include": yaml_template,
"task": task_name,
"dataset_name": lang,
}
os.makedirs(f"{output_dir}/{mode}", exist_ok=True)
with open(
f"{output_dir}/{mode}/{file_name}",
"w" if overwrite else "x",
encoding="utf8",
) as f:
f.write("# Generated by utils.py\n")
yaml.dump(
yaml_details,
f,
allow_unicode=True,
)
except FileExistsError:
err.append(file_name)
if len(err) > 0:
raise FileExistsError(
"Files were not created because they already exist (use --overwrite flag):"
f" {', '.join(err)}"
)
def main() -> None:
"""Parse CLI args and generate language-specific yaml files."""
parser = argparse.ArgumentParser()
parser.add_argument(
"--overwrite",
default=True,
action="store_true",
help="Overwrite files if they already exist",
)
parser.add_argument(
"--output-dir",
default="./translate",
help="Directory to write yaml files to",
)
parser.add_argument(
"--mode",
default="prompt_5",
choices=["prompt_1", "prompt_2", "prompt_3", "prompt_4", "prompt_5"],
help="Prompt number",
)
args = parser.parse_args()
gen_lang_yamls(output_dir=args.output_dir, overwrite=args.overwrite, mode=args.mode)
if __name__ == "__main__":
main()
group: afrixnli_tt-irokobench
task:
- afrixnli_tt_tasks
aggregate_metric_list:
- metric: acc
aggregation: mean
weight_by_size: true
metadata:
version: 2
# Generated by utils.py
dataset_name: amh
doc_to_text: 'Please identify whether the premise entails or contradicts the hypothesis
in the following premise and hypothesis. The answer should be exact entailment,
contradiction, or neutral.
Premise: {premise}
Hypothesis: {hypothesis}
Is it entailment, contradiction, or neutral?'
include: afrixnli_translate_yaml
task: afrixnli_translate_amh_prompt_1
# Generated by utils.py
dataset_name: ewe
doc_to_text: 'Please identify whether the premise entails or contradicts the hypothesis
in the following premise and hypothesis. The answer should be exact entailment,
contradiction, or neutral.
Premise: {premise}
Hypothesis: {hypothesis}
Is it entailment, contradiction, or neutral?'
include: afrixnli_translate_yaml
task: afrixnli_translate_ewe_prompt_1
# Generated by utils.py
dataset_name: fra
doc_to_text: 'Please identify whether the premise entails or contradicts the hypothesis
in the following premise and hypothesis. The answer should be exact entailment,
contradiction, or neutral.
Premise: {premise}
Hypothesis: {hypothesis}
Is it entailment, contradiction, or neutral?'
include: afrixnli_translate_yaml
task: afrixnli_translate_fra_prompt_1
# Generated by utils.py
dataset_name: hau
doc_to_text: 'Please identify whether the premise entails or contradicts the hypothesis
in the following premise and hypothesis. The answer should be exact entailment,
contradiction, or neutral.
Premise: {premise}
Hypothesis: {hypothesis}
Is it entailment, contradiction, or neutral?'
include: afrixnli_translate_yaml
task: afrixnli_translate_hau_prompt_1
# Generated by utils.py
dataset_name: ibo
doc_to_text: 'Please identify whether the premise entails or contradicts the hypothesis
in the following premise and hypothesis. The answer should be exact entailment,
contradiction, or neutral.
Premise: {premise}
Hypothesis: {hypothesis}
Is it entailment, contradiction, or neutral?'
include: afrixnli_translate_yaml
task: afrixnli_translate_ibo_prompt_1
# Generated by utils.py
dataset_name: kin
doc_to_text: 'Please identify whether the premise entails or contradicts the hypothesis
in the following premise and hypothesis. The answer should be exact entailment,
contradiction, or neutral.
Premise: {premise}
Hypothesis: {hypothesis}
Is it entailment, contradiction, or neutral?'
include: afrixnli_translate_yaml
task: afrixnli_translate_kin_prompt_1
# Generated by utils.py
dataset_name: lin
doc_to_text: 'Please identify whether the premise entails or contradicts the hypothesis
in the following premise and hypothesis. The answer should be exact entailment,
contradiction, or neutral.
Premise: {premise}
Hypothesis: {hypothesis}
Is it entailment, contradiction, or neutral?'
include: afrixnli_translate_yaml
task: afrixnli_translate_lin_prompt_1
# Generated by utils.py
dataset_name: lug
doc_to_text: 'Please identify whether the premise entails or contradicts the hypothesis
in the following premise and hypothesis. The answer should be exact entailment,
contradiction, or neutral.
Premise: {premise}
Hypothesis: {hypothesis}
Is it entailment, contradiction, or neutral?'
include: afrixnli_translate_yaml
task: afrixnli_translate_lug_prompt_1
# Generated by utils.py
dataset_name: orm
doc_to_text: 'Please identify whether the premise entails or contradicts the hypothesis
in the following premise and hypothesis. The answer should be exact entailment,
contradiction, or neutral.
Premise: {premise}
Hypothesis: {hypothesis}
Is it entailment, contradiction, or neutral?'
include: afrixnli_translate_yaml
task: afrixnli_translate_orm_prompt_1
# Generated by utils.py
dataset_name: sna
doc_to_text: 'Please identify whether the premise entails or contradicts the hypothesis
in the following premise and hypothesis. The answer should be exact entailment,
contradiction, or neutral.
Premise: {premise}
Hypothesis: {hypothesis}
Is it entailment, contradiction, or neutral?'
include: afrixnli_translate_yaml
task: afrixnli_translate_sna_prompt_1
# Generated by utils.py
dataset_name: sot
doc_to_text: 'Please identify whether the premise entails or contradicts the hypothesis
in the following premise and hypothesis. The answer should be exact entailment,
contradiction, or neutral.
Premise: {premise}
Hypothesis: {hypothesis}
Is it entailment, contradiction, or neutral?'
include: afrixnli_translate_yaml
task: afrixnli_translate_sot_prompt_1
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