Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc-multilingual tasks #339

Merged
merged 91 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
5c69eb0
add multilignaul dynamic generative metrics
hynky1999 Sep 5, 2024
39c4220
Merge branch 'main' into geneartive_dynamic_metrics
hynky1999 Sep 5, 2024
2a5cdca
Merge branch 'geneartive_dynamic_metrics' into config_templates
hynky1999 Sep 5, 2024
2df9a08
draft
hynky1999 Sep 6, 2024
95729ee
finish multichoice config
hynky1999 Sep 9, 2024
3aa0579
Merge branch 'main' into geneartive_dynamic_metrics
hynky1999 Sep 9, 2024
b8f90a9
update tokenizers + install nltk reqs
hynky1999 Sep 9, 2024
f5a8717
use punkt tab
hynky1999 Sep 9, 2024
227f572
Update src/lighteval/utils/imports.py
hynky1999 Sep 13, 2024
d80b3ba
Update src/lighteval/metrics/normalizations.py
hynky1999 Sep 13, 2024
532bdad
fix imports
Sep 13, 2024
75f7ac5
remove unused import
Sep 13, 2024
f99e330
Merge branch 'main' into geneartive_dynamic_metrics
NathanHB Sep 13, 2024
92daf90
Merge branch 'main' into geneartive_dynamic_metrics
clefourrier Sep 14, 2024
f2a801d
Merge branch 'main' into geneartive_dynamic_metrics
NathanHB Sep 17, 2024
91d9d4f
finish implementation of templates + move stuff around
Sep 23, 2024
9356cc6
resolve nits
Sep 23, 2024
0fbc731
when in rome do as romans do (handle error messages the same way)
Sep 23, 2024
fa1fa83
fix utils
hynky1999 Sep 23, 2024
db36e16
Merge branch 'geneartive_dynamic_metrics' into config_templates
hynky1999 Sep 23, 2024
44aeecf
nicers tests + fix them
hynky1999 Sep 23, 2024
2bff963
nicer todo
hynky1999 Sep 23, 2024
3c9eb21
add nice doscrings 📃
hynky1999 Sep 23, 2024
4216ae2
add even more docstring
hynky1999 Sep 23, 2024
d8f56b8
nit
hynky1999 Sep 23, 2024
f26e88c
fix test
hynky1999 Sep 23, 2024
111d615
add multilingual to dev group
hynky1999 Sep 24, 2024
7ca4239
merge nli, add languagees to literals
hynky1999 Sep 25, 2024
22eeddb
translation literals
hynky1999 Sep 25, 2024
7faaa8a
add nli
hynky1999 Sep 25, 2024
865bcbc
add copa tasks + fix tranlation literals
hynky1999 Sep 25, 2024
856e758
add hellaswag tasks
hynky1999 Sep 25, 2024
0c7987f
remove custom telgu hellaswag
hynky1999 Sep 25, 2024
4165fc2
remove hindi hellaswag
hynky1999 Sep 25, 2024
bc669e6
add rc tasks + small nits
hynky1999 Sep 26, 2024
ba44fe9
add rcb + chinese nli
hynky1999 Sep 26, 2024
2d09256
Merge branch 'geneartive_dynamic_metrics' into config_templates
hynky1999 Sep 26, 2024
7324e89
Merge branch 'config_templates' into multilnag_nli_tasks
hynky1999 Sep 26, 2024
01161b2
Merge branch 'multilnag_nli_tasks' into multilang_copa_task
hynky1999 Sep 26, 2024
680124e
Merge branch 'multilang_copa_task' into hellaswag_tasks
hynky1999 Sep 26, 2024
a84e368
Merge branch 'hellaswag_tasks' into rc_tasks
hynky1999 Sep 26, 2024
b10ff74
add mcq tasks
hynky1999 Sep 29, 2024
9a54806
add continuations + general qa tasks + missed tasks
hynky1999 Sep 30, 2024
ca865bd
Update src/lighteval/tasks/multilingual/tasks.py
hynky1999 Sep 30, 2024
1cc1187
Update src/lighteval/tasks/multilingual/tasks.py
hynky1999 Sep 30, 2024
d64251f
Update src/lighteval/tasks/multilingual/tasks.py
hynky1999 Sep 30, 2024
9806fab
Update src/lighteval/tasks/multilingual/tasks.py
hynky1999 Sep 30, 2024
35d7e6d
Update src/lighteval/tasks/multilingual/tasks.py
hynky1999 Sep 30, 2024
e560738
Update src/lighteval/tasks/multilingual/tasks.py
hynky1999 Sep 30, 2024
99524c5
Update src/lighteval/tasks/multilingual/tasks.py
hynky1999 Sep 30, 2024
150c76f
add two new tasks + docs
hynky1999 Sep 30, 2024
4e6100d
Merge branch 'multilnag_nli_tasks' of github.com:huggingface/lighteva…
hynky1999 Sep 30, 2024
7b561fe
Merge remote-tracking branch 'origin/main' into multilnag_nli_tasks
hynky1999 Sep 30, 2024
f9c7134
Merge branch 'multilnag_nli_tasks' into multilang_copa_task
hynky1999 Sep 30, 2024
b219e07
add nice docs
hynky1999 Sep 30, 2024
8899a1c
Merge branch 'multilang_copa_task' into hellaswag_tasks
hynky1999 Sep 30, 2024
fcad0e8
update hellaswag with docs
hynky1999 Sep 30, 2024
43809ab
move hellaswag to lighteval suite
hynky1999 Sep 30, 2024
a20a24e
add desc to tasks
hynky1999 Sep 30, 2024
a673d65
Update src/lighteval/tasks/multilingual/tasks.py
hynky1999 Sep 30, 2024
3c453f7
Merge remote-tracking branch 'origin/main' into hellaswag_tasks
hynky1999 Sep 30, 2024
815e897
enable returning none from templates + better typing
hynky1999 Sep 30, 2024
f9801c7
Merge branch 'hellaswag_tasks' into rc_tasks
hynky1999 Sep 30, 2024
843fe9a
Merge branch 'rc_tasks' into multilang_mqa_tasks
hynky1999 Sep 30, 2024
0d7b849
add nice docs
hynky1999 Sep 30, 2024
2a8ae3d
fix saving of partial fcs + better tasks doc
hynky1999 Oct 1, 2024
eec2444
change unoficial hellaswag names to have community_prefix + unify hel…
hynky1999 Oct 1, 2024
02c8122
community rename
hynky1999 Oct 1, 2024
6284fe5
let strip be optional in hellaswag
hynky1999 Oct 1, 2024
32c8a4e
nits
hynky1999 Oct 1, 2024
8b5a046
fix remaning tasks in mcq
hynky1999 Oct 1, 2024
8ead4de
fixes
hynky1999 Oct 1, 2024
d7b98c0
Merge branch 'hellaswag_tasks' into rc_tasks
hynky1999 Oct 1, 2024
03bd7ba
nits
hynky1999 Oct 1, 2024
ca9d190
fix up agieval + ceval
hynky1999 Oct 1, 2024
e12cc3b
add comment
hynky1999 Oct 1, 2024
6f3de8c
Merge remote-tracking branch 'origin/main' into rc_tasks
hynky1999 Oct 1, 2024
1f8c8e6
Merge branch 'rc_tasks' into multilang_mqa_tasks
hynky1999 Oct 1, 2024
70b6b93
Merge branch 'multilang_mqa_tasks' into misc_tasks
hynky1999 Oct 1, 2024
d3ba842
hellaswag fixes
hynky1999 Oct 1, 2024
f523bba
hellaswag hind + mlqa + hindi/swahili arc + mintaka + triviaqa french
hynky1999 Oct 1, 2024
db397b0
add openai mmlu, turkish mmlu, lumi and mgsm
hynky1999 Oct 2, 2024
6244ad1
improve qa readibility
hynky1999 Oct 2, 2024
0f62796
fix norms
hynky1999 Oct 2, 2024
4fcc87d
Merge remote-tracking branch 'origin/main' into misc_tasks
hynky1999 Oct 9, 2024
a4d8e20
fix few shot splits + add boolq tasks
hynky1999 Oct 9, 2024
81c6a29
rename boolqa to boolq
hynky1999 Oct 9, 2024
1008a1a
Merge branch 'main' into misc_tasks
NathanHB Oct 10, 2024
1a7fd13
Update src/lighteval/tasks/default_prompts.py
hynky1999 Oct 10, 2024
c299f89
Update src/lighteval/tasks/default_prompts.py
hynky1999 Oct 10, 2024
de16271
Merge branch 'main' into misc_tasks
hynky1999 Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/lighteval/tasks/default_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,13 +756,16 @@ def headqa(line, task_name: str = None):


def hellaswag_preprocess(
text: str, wikihow_artifacts: list[str] = [" [title]"], truncate_dots: bool = False, strip_text: bool = False
text: str,
wikihow_artifacts: list[str] = [" [title]"],
truncate_dots: bool = False,
strip_text: bool = False,
dot_replacement: str = ". ",
):
"""Comes from AiHarness"""
# text = text.strip()
"""Comes from LM Eval Harness"""
# NOTE: Brackets are artifacts of the WikiHow dataset portion of HellaSwag.
for dot_repl in wikihow_artifacts:
text = text.replace(dot_repl, ". ")
for wikihow_artifact in wikihow_artifacts:
text = text.replace(wikihow_artifact, dot_replacement)
text = re.sub("\\[.*?\\]", "", text)
text = text.replace(" ", " ")
if truncate_dots:
Expand Down
79 changes: 74 additions & 5 deletions src/lighteval/tasks/multilingual/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import os
import re

import numpy as np
from langcodes import standardize_tag

from lighteval.tasks.default_prompts import LETTER_INDICES
from lighteval.tasks.multilingual.utils.adapters_utils import (
extract_answers_from_string,
multichoice_join,
multichoice_to_single_choice,
)
from lighteval.tasks.templates.continuation import ContinuationInput
from lighteval.tasks.templates.multichoice import MCQInput
from lighteval.tasks.templates.qa import QAInput
from lighteval.tasks.templates.utils.formatting_utils import PUNCT
from lighteval.tasks.templates.utils.formulation import CFFormulation, Formulation
from lighteval.tasks.templates.utils.translation_literals import TranslationLiterals
Expand Down Expand Up @@ -60,14 +64,14 @@ def get_m3exam_adapter(lang: Language, line: dict) -> MCQInput | None:
def thai_exams_adapter(line: dict) -> MCQInput | None:
pos_letters = [letter.lower() for letter in LETTER_INDICES[:5]]

lettr_to_choices = {letter: line[letter] for letter in pos_letters if letter in line}
if any(opt.strip() == "" for opt in lettr_to_choices.values()):
letter_to_choices = {letter: line[letter] for letter in pos_letters if letter in line}
if any(opt.strip() == "" for opt in letter_to_choices.values()):
return None

gold_index = list(lettr_to_choices.keys()).index(line["answer"])
gold_index = list(letter_to_choices.keys()).index(line["answer"])
return {
"question": line["question"],
"choices": list(lettr_to_choices.values()),
"choices": list(letter_to_choices.values()),
"gold_idx": gold_index,
}

Expand Down Expand Up @@ -111,7 +115,7 @@ def ceval_adapter(lang: Language, formulation: Formulation, line: dict) -> MCQIn

parts = line["question"].rsplit("____", maxsplit=1)
cleaned_question = parts[0].rstrip(PUNCT).strip()
possible_answers_part = parts[1].lstrip(PUNCT)
possible_answers_part = parts[1].strip().lstrip(PUNCT)
gold_index = LETTER_INDICES.index(line["answer"])

# We only attempt to extract answers if the answers are a chinese numbers
Expand Down Expand Up @@ -207,3 +211,68 @@ def agieval_adapter(lang: Language, formulation: Formulation, line: dict) -> MCQ
"gold_idx": gold_index,
"context": context,
}


def xcodah_adapter(lang: Language, line: dict) -> MCQInput | None:
translation_literals = TranslationLiterals(lang)

gold_index = line["question"]["choices"]["label"].index(line["answerKey"])
# All the choices have already common prefix "baken in" so we have to remove to get clearer signal
# Extract common prefix from choices
choices = line["question"]["choices"]["text"]
common_prefix = os.path.commonprefix(choices)

# Backtract to first space to get good tokenization
first_word = common_prefix.rfind(translation_literals.word_space)

# If there is no word_space we shouldn't remove the common prefix
common_prefix = common_prefix[:first_word] if first_word != -1 else ""

# Remove common prefix from each choice
cleaned_choices = [choice[len(common_prefix) :] for choice in choices]

if any(len(c.strip()) == 0 for c in cleaned_choices):
return None

return {
"question": common_prefix,
"choices": cleaned_choices,
"gold_idx": gold_index,
}


def winogrand_adapter(lang: Language, line: dict) -> ContinuationInput | None:
translation_literals = TranslationLiterals(lang)
if line["sentence"].count("_") != 1:
return None

query, end_of_target = line["sentence"].split("_")
if len(query.strip()) == 0:
return None

options = [line["option1"], line["option2"]]
return {
"context": query,
"continuations": [f"{o}{translation_literals.word_space}{end_of_target}" for o in options],
"gold_idx": int(line["answer"]) - 1,
}


def get_mkqa_adapter(lang: Language, line: dict) -> QAInput | None:
lang_key = "zh_cn" if lang == Language.CHINESE else standardize_tag(lang.value)
text = line["answers"][lang_key][0]["text"]
if text is None:
return None

aliases = line["answers"][lang_key][0]["aliases"]
answers = list(filter(lambda x: len(x.strip()) > 0, [text] + aliases))
# Some samples are broken so this is heuristic
# e. g 'text': '七月 20, 1969',
# 'aliases': ['1', 'u', ',', '2', ' ', '6', 'l', 'y', '9', '0', 'j']}],
if len(answers) == 0 or len(answers) > 5:
return None

return {
"question": line["queries"][lang_key],
"choices": answers,
}
Loading
Loading