forked from EleutherAI/lm-evaluation-harness
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Implemented EU22/EU5 translations #105
Open
jjbuschhoff
wants to merge
13
commits into
master
Choose a base branch
from
eu22_translations
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
69e1cac
initial integration of tasks
jjbuschhoff 82e4169
fixed language selections
jjbuschhoff 55434ff
linting
jjbuschhoff f17928f
initial integration of tasks
jjbuschhoff 330681c
fixed language selections
jjbuschhoff b4291a8
linting
jjbuschhoff 456c5dc
Merge branch 'eu22_translations' of https://github.com/OpenGPTX/lm-ev…
jjbuschhoff 26b7be9
fixed dataset paths and added newly translated languages
jjbuschhoff 7f5ac40
added translated prompts
jjbuschhoff 1293862
linting
jjbuschhoff f7380e7
removed duplicate line
jjbuschhoff 35fb949
removed unused classes
jjbuschhoff e032a50
fixed newline at EOF
jjbuschhoff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
""" | ||
Think you have Solved Question Answering? Try ARC, the AI2 Reasoning Challenge | ||
https://arxiv.org/pdf/1803.05457.pdf | ||
|
||
The ARC dataset consists of 7,787 science exam questions drawn from a variety | ||
of sources, including science questions provided under license by a research | ||
partner affiliated with AI2. These are text-only, English language exam questions | ||
that span several grade levels as indicated in the files. Each question has a | ||
multiple choice structure (typically 4 answer options). The questions are sorted | ||
into a Challenge Set of 2,590 “hard” questions (those that both a retrieval and | ||
a co-occurrence method fail to answer correctly) and an Easy Set of 5,197 questions. | ||
|
||
Homepage: https://allenai.org/data/arc | ||
""" | ||
from lm_eval.base import MultipleChoiceTask | ||
|
||
|
||
_CITATION = """ | ||
@article{Clark2018ThinkYH, | ||
title={Think you have Solved Question Answering? Try ARC, the AI2 Reasoning Challenge}, | ||
author={Peter Clark and Isaac Cowhey and Oren Etzioni and Tushar Khot and Ashish Sabharwal and Carissa Schoenick and Oyvind Tafjord}, | ||
journal={ArXiv}, | ||
year={2018}, | ||
volume={abs/1803.05457} | ||
} | ||
""" | ||
LANGS = [ | ||
"BG", | ||
"DA", | ||
"DE", | ||
"ET", | ||
"FI", | ||
"FR", | ||
"EL", | ||
"IT", | ||
"LV", | ||
"LT", | ||
"NL", | ||
"PL", | ||
"PT-PT", | ||
"RO", | ||
"SV", | ||
"SK", | ||
"SL", | ||
"ES", | ||
"CS", | ||
"HU", | ||
] | ||
|
||
PROMPT_WORDS = { | ||
"BG": ("Въпрос", "Отговор"), | ||
"DA": ("Spørgsmål", "Svar"), | ||
"DE": ("Frage", "Antwort"), | ||
"ET": ("Küsimus", "Vastus"), | ||
"FI": ("Kysymys", "Vastaa"), | ||
"FR": ("Question", "Réponse"), | ||
"EL": ("Ερώτηση", "Απάντηση"), | ||
"IT": ("Domanda", "Risposta"), | ||
"LV": ("Jautājums", "Atbilde"), | ||
"LT": ("Klausimas", "Atsakymas"), | ||
"NL": ("Vraag", "Antwoord"), | ||
"PL": ("Pytanie", "Odpowiedź"), | ||
"PT-PT": ("Questão", "Resposta"), | ||
"RO": ("Întrebare", "Răspuns"), | ||
"SV": ("Fråga", "Svar"), | ||
"SK": ("Otázka", "Odpoveď"), | ||
"SL": ("Vprašanje", "Odgovor"), | ||
"ES": ("Pregunta", "Respuesta"), | ||
"CS": ("Otázka", "Odpověď"), | ||
"HU": ("Kérdés", "Válasz"), | ||
} | ||
|
||
|
||
def construct_task(lang: str, split: str): | ||
class ARC(ARCBase): | ||
QWORD, RWORD = PROMPT_WORDS.get(lang, ("Question", "Answer")) | ||
DATASET_NAME = f"{split}_{lang}" | ||
|
||
return ARC | ||
|
||
|
||
def construct_all_tasks(): | ||
return { | ||
f"arcx_{s}_{l.lower()}": construct_task(l, s) | ||
for l in LANGS | ||
for s in ["easy", "challenge"] | ||
} | ||
|
||
|
||
class ARCBase(MultipleChoiceTask): | ||
VERSION = 0 | ||
DATASET_PATH = "openGPT-X/arcx" | ||
DATASET_NAME = None | ||
NUM_FEW_SHOT = 25 | ||
jjbuschhoff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
QWORD, RWORD = None, None | ||
|
||
def has_training_docs(self): | ||
return True | ||
|
||
def has_validation_docs(self): | ||
return True | ||
|
||
def has_test_docs(self): | ||
return True | ||
|
||
def training_docs(self): | ||
if self._training_docs is None: | ||
self._training_docs = list(map(self._process_doc, self.dataset["train"])) | ||
return self._training_docs | ||
|
||
def validation_docs(self): | ||
return map(self._process_doc, self.dataset["validation"]) | ||
|
||
def test_docs(self): | ||
return map(self._process_doc, self.dataset["test"]) | ||
|
||
def _process_doc(self, doc): | ||
# NOTE: Some `doc["answerKey"]`s are in numeric string format being one | ||
# of {'1', '2', '3', '4', '5'}. We map them back to letters. | ||
num_to_letter = {"1": "A", "2": "B", "3": "C", "4": "D", "5": "E"} | ||
doc["answerKey"] = num_to_letter.get(doc["answerKey"], doc["answerKey"]) | ||
out_doc = { | ||
"id": doc["id"], | ||
"query": self.QWORD + ": " + doc["question"] + f"\n{self.RWORD}:", | ||
"choices": doc["choices"]["text"], | ||
"gold": ["A", "B", "C", "D", "E"].index(doc["answerKey"]), | ||
} | ||
return out_doc | ||
|
||
def doc_to_text(self, doc): | ||
return doc["query"] | ||
|
||
def should_decontaminate(self): | ||
return True | ||
|
||
def doc_to_decontamination_query(self, doc): | ||
return doc["query"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
""" | ||
"Training Verifiers to Solve Math Word Problems" | ||
https://arxiv.org/abs/2110.14168 | ||
|
||
State-of-the-art language models can match human performance on many tasks, but | ||
they still struggle to robustly perform multi-step mathematical reasoning. To | ||
diagnose the failures of current models and support research, we introduce GSM8K, | ||
a dataset of 8.5K high quality linguistically diverse grade school math word problems. | ||
We find that even the largest transformer models fail to achieve high test performance, | ||
despite the conceptual simplicity of this problem distribution. | ||
|
||
NOTE: See the official implementation of the task: | ||
https://github.com/openai/grade-school-math/blob/master/grade_school_math/calculator.py | ||
for how to make use of the dataset's calculator annotations in your language | ||
model's sample/generation function. | ||
|
||
Homepage: https://github.com/openai/grade-school-math | ||
""" | ||
import re | ||
from lm_eval.base import Task, rf | ||
from lm_eval.metrics import mean | ||
|
||
|
||
_CITATION = """ | ||
@misc{cobbe2021training, | ||
title={Training Verifiers to Solve Math Word Problems}, | ||
author={Karl Cobbe and Vineet Kosaraju and Mohammad Bavarian and Jacob Hilton and Reiichiro Nakano and Christopher Hesse and John Schulman}, | ||
year={2021}, | ||
eprint={2110.14168}, | ||
archivePrefix={arXiv}, | ||
primaryClass={cs.LG} | ||
} | ||
""" | ||
|
||
LANGS = [ | ||
"BG", | ||
"DA", | ||
"DE", | ||
"ET", | ||
"FI", | ||
"FR", | ||
"EL", | ||
"IT", | ||
"LV", | ||
"LT", | ||
"NL", | ||
"PL", | ||
"PT-PT", | ||
"RO", | ||
"SV", | ||
"SK", | ||
"SL", | ||
"ES", | ||
"CS", | ||
"HU", | ||
] | ||
|
||
PROMPT_WORDS = { | ||
"BG": ("Въпрос", "Отговор"), | ||
"DA": ("Spørgsmål", "Svar"), | ||
"DE": ("Frage", "Antwort"), | ||
"ET": ("Küsimus", "Vastus"), | ||
"FI": ("Kysymys", "Vastaa"), | ||
"FR": ("Question", "Réponse"), | ||
"EL": ("Ερώτηση", "Απάντηση"), | ||
"IT": ("Domanda", "Risposta"), | ||
"LV": ("Jautājums", "Atbilde"), | ||
"LT": ("Klausimas", "Atsakymas"), | ||
"NL": ("Vraag", "Antwoord"), | ||
"PL": ("Pytanie", "Odpowiedź"), | ||
"PT-PT": ("Questão", "Resposta"), | ||
"RO": ("Întrebare", "Răspuns"), | ||
"SV": ("Fråga", "Svar"), | ||
"SK": ("Otázka", "Odpoveď"), | ||
"SL": ("Vprašanje", "Odgovor"), | ||
"ES": ("Pregunta", "Respuesta"), | ||
"CS": ("Otázka", "Odpověď"), | ||
"HU": ("Kérdés", "Válasz"), | ||
} | ||
|
||
|
||
def construct_all_tasks(): | ||
return {f"gsm8kx_{lang.lower()}": construct_task(lang) for lang in LANGS} | ||
|
||
|
||
def construct_task(lang): | ||
class task(GradeSchoolMath8K): | ||
DATASET_NAME = lang | ||
QWORD, RWORD = PROMPT_WORDS.get(lang, ("Question", "Answer")) | ||
|
||
return task | ||
|
||
|
||
ANS_RE = re.compile(r"#### (\-?[0-9\.\,]+)") | ||
INVALID_ANS = "[invalid]" | ||
|
||
|
||
class GradeSchoolMath8K(Task): | ||
VERSION = 0 | ||
DATASET_PATH = "openGPT-X/gsm8kx" | ||
QWORD, RWORD = None, None | ||
|
||
def has_training_docs(self): | ||
return True | ||
|
||
def has_validation_docs(self): | ||
return False | ||
|
||
def has_test_docs(self): | ||
return True | ||
|
||
def training_docs(self): | ||
return self.dataset["train"] | ||
|
||
def validation_docs(self): | ||
raise NotImplementedError | ||
|
||
def test_docs(self): | ||
return self.dataset["test"] | ||
|
||
def doc_to_text(self, doc): | ||
return self.QWORD + ": " + doc["question"] + f"\n{self.RWORD}:" | ||
|
||
def doc_to_target(self, doc): | ||
return " " + doc["answer"] | ||
|
||
def construct_requests(self, doc, ctx): | ||
"""Uses RequestFactory to construct Requests and returns an iterable of | ||
Requests which will be sent to the LM. | ||
|
||
:param doc: | ||
The document as returned from training_docs, validation_docs, or test_docs. | ||
:param ctx: str | ||
The context string, generated by fewshot_context. This includes the natural | ||
language description, as well as the few shot examples, and the question | ||
part of the document for `doc`. | ||
""" | ||
# NOTE: The paper implements "verifiers" that assign a score to multiple | ||
# solutions and output the highest ranked solution. | ||
completion = rf.greedy_until( | ||
ctx, {"until": [":", f"{self.QWORD}:", f"{self.QWORD}"]} | ||
) | ||
return completion | ||
|
||
def _extract_answer(self, completion): | ||
match = ANS_RE.search(completion) | ||
if match: | ||
match_str = match.group(1).strip() | ||
match_str = match_str.replace(",", "") | ||
return match_str | ||
else: | ||
return INVALID_ANS | ||
|
||
def _is_correct(self, completion, answer): | ||
gold = self._extract_answer(answer) | ||
assert gold != INVALID_ANS, "No ground truth answer found in the document." | ||
return self._extract_answer(completion) == gold | ||
|
||
def process_results(self, doc, results): | ||
"""Take a single document and the LM results and evaluates, returning a | ||
dict where keys are the names of submetrics and values are the values of | ||
the metric for that one document | ||
|
||
:param doc: | ||
The document as returned from training_docs, validation_docs, or test_docs. | ||
:param results: | ||
The results of the requests created in construct_requests. | ||
""" | ||
completion = results[0] | ||
answer = doc["answer"] | ||
return {"acc": self._is_correct(completion, answer)} | ||
|
||
def aggregation(self): | ||
""" | ||
:returns: {str: [float] -> float} | ||
A dictionary where keys are the names of submetrics and values are | ||
functions that aggregate a list of metrics | ||
""" | ||
return {"acc": mean} | ||
|
||
def higher_is_better(self): | ||
""" | ||
:returns: {str: bool} | ||
A dictionary where keys are the names of submetrics and values are | ||
whether a higher value of the submetric is better | ||
""" | ||
return {"acc": True} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to include English here to ensure that all languages are evaluated the same way?