Skip to content

Commit

Permalink
add mgsm datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
Yggdrasill7D6 committed Apr 24, 2024
1 parent 41196c4 commit 61c477a
Show file tree
Hide file tree
Showing 5 changed files with 409 additions and 0 deletions.
59 changes: 59 additions & 0 deletions configs/datasets/mgsm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# MGSM
## Introduction
The following introduction comes from the abstract in [Language models are multilingual chain-of-thought reasoners](https://arxiv.org/abs/2210.03057)

```
We introduce the Multilingual Grade School Math (MGSM) benchmark, by manually translating 250 grade-school math problems from the GSM8K dataset into ten typologically diverse languages.
```

## Official link

### Paper

[Language models are multilingual chain-of-thought reasoners](https://arxiv.org/abs/2210.03057)

### Repository

[MGSM](https://github.com/google-research/url-nlp)

## Examples
Input example I:
```
Solve this math problem. Give the reasoning steps before giving the final answer on the last line by itself in the format of "Answer:". Do not add anything other than the integer answer after "Answer:".
Janet’s ducks lay 16 eggs per day. She eats three for breakfast every morning and bakes muffins for her friends every day with four. She sells the remainder at the farmers' market daily for $2 per fresh duck egg. How much in dollars does she make every day at the farmers' market?
```

Output example I (from GPT-4):
```
Answer:18
```


## Evaluation results

```
dataset version metric mode internlm2-chat
--------- --------- -------- ------ ----------------
mgsm_en 5ddc62 Acc gen 0
mgsm_zh 5ddc62 Acc gen 0
mgsm_bn 5ddc62 Acc gen 0
mgsm_de 5ddc62 Acc gen 10
mgsm_es 5ddc62 Acc gen 10
mgsm_fr 5ddc62 Acc gen 0
mgsm_ja 5ddc62 Acc gen 0
mgsm_ru 5ddc62 Acc gen 10
mgsm_sw 5ddc62 Acc gen 10
mgsm_te 5ddc62 Acc gen 0
mgsm_th 5ddc62 Acc gen 0
```

## Reference
```
@article{shi2022language,
title={Language models are multilingual chain-of-thought reasoners},
author={Shi, Freda and Suzgun, Mirac and Freitag, Markus and Wang, Xuezhi and Srivats, Suraj and Vosoughi, Soroush and Chung, Hyung Won and Tay, Yi and Ruder, Sebastian and Zhou, Denny and others},
journal={arXiv preprint arXiv:2210.03057},
year={2022}
}
```
213 changes: 213 additions & 0 deletions configs/datasets/mgsm/mgsm_gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
from opencompass.openicl.icl_prompt_template import PromptTemplate
from opencompass.openicl.icl_retriever import ZeroRetriever
from opencompass.openicl.icl_inferencer import GenInferencer
from opencompass.openicl.icl_evaluator import JiebaRougeEvaluator
from opencompass.datasets import (
MGSMSDataset, MGSM_Evaluator,
mgsm_zh_postprocess, mgsm_en_postprocess,
mgsm_bn_postprocess, mgsm_de_postprocess,
mgsm_es_postprocess, mgsm_fr_postprocess,
mgsm_ja_postprocess, mgsm_ru_postprocess,
mgsm_sw_postprocess, mgsm_te_postprocess,
mgsm_th_postprocess
)

mgsm_reader_cfg = dict(input_columns=['question'], output_column='answer')

# LANG_TO_INSTRUCTIONS = {
# "en": """Solve this math problem. Give the reasoning steps before giving the final answer on the last line by itself in the format of "Answer:". Do not add anything other than the integer answer after "Answer:".

# {question}""",
# "bn": """এই গণিতের সমস্যাটি সমাধান করুন। চূড়ান্ত উত্তর দেওয়ার আগে যুক্তিসম্পন্ন পদক্ষেপ প্রদান করুন। চূড়ান্ত উত্তরটি একক সংখ্যা হিসাবে "উত্তর:" এর পরে শেষ লাইনে দিন। "উত্তর:" এর পরে অন্য কিছু যুক্ত করবেন না।.

# {question}""",
# "de": """Löse dieses Mathematikproblem. Gib die Schritte zur Begründung an, bevor du die endgültige Antwort in der letzten Zeile alleine im Format "Antwort:" gibst. Füge nichts anderes als die ganzzahlige Antwort nach "Antwort:" hinzu.

# {question}""",
# "es": """Resuelve este problema matemático. Proporciona los pasos de razonamiento antes de dar la respuesta final en la última línea por sí misma en el formato de "Respuesta:". No añadas nada más que la respuesta entera después de "Respuesta:".

# {question}""",
# "fr": """Résolvez ce problème de mathématiques. Donnez les étapes de raisonnement avant de fournir la réponse finale sur la dernière ligne elle-même dans le format de "Réponse:". N'ajoutez rien d'autre que la réponse entière après "Réponse:".

# {question}""",
# "ja": """の数学の問題を解いてください。最終的な答えを出す前に、解答の推論過程を記述してください。そして最後の行には "答え:" の形式で答えを記述し、その後には整数の答え以外何も追加しないでください。

# {question}""",
# "ru": """Решите эту математическую задачу. Объясните шаги рассуждения перед тем, как дать окончательный ответ в последней строке сам по себе в формате "Ответ:". Не добавляйте ничего, кроме целочисленного ответа после "Ответ:".

# {question}""",
# "sw": """Suluhisha tatizo hili la hesabu. Toa hatua za mantiki kabla ya kutoa jibu la mwisho kwenye mstari wa mwisho peke yake katika muundo wa "Jibu:". Usiongeze chochote kingine isipokuwa jibu la integer baada ya "Jibu:".

# {question}""",
# "te": """ఈ గణిత సమస్యను పరిష్కరించండి. చివరి సమాధానాన్ని ఇవ్వదానికి ముందు తర్కాత్మక అదుగులను ఇవ్వండి. చివరి పంక్తిలో మాత్రమే 'సమాధానం:' అనే ఆకారంలో చివరి సమాధానాద్ని ఇవ్వండి సమాధానం: తర్వాత పూర్ణాంక సమాధానానికి తప్పించి ఎదేనా చేర్చవద్దు.

# {question}""",
# "th": """แก้ปัญหาคณิตศาสตร์นี้ ให้ให้ขั้นตอนการใช้เหตุผลก่อนที่จะให้คำตอบสุดท้ายในบรรทัดสุดท้ายโดยอยู่ในรูปแบบ "คำตอบ:" ไม่ควรเพิ่มอะไรนอกจากคำตอบที่เป็นจำนวนเต็มหลังจาก "คำตอบ:"

# {question}""",
# "zh": """解决这个数学问题。在最后一行给出答案前,请提供推理步骤。最后一行应该以 "答案: " 的形式独立给出答案。在 "答案:" 后不要添加除整数答案之外的任何内容。

# {question}""",
# }

# each instance in datafile
mgsm_infer_cfg = dict(
prompt_template=dict(
type=PromptTemplate,
template=dict(round=[
dict(role='HUMAN', prompt='{question}'),
])),
retriever=dict(type=ZeroRetriever),
inferencer=dict(type=GenInferencer))

mgsm_eval_en_cfg = dict(
evaluator=dict(type=MGSM_Evaluator),
pred_role='BOT',
pred_postprocessor=dict(type=mgsm_en_postprocess),
)

mgsm_eval_bn_cfg = dict(
evaluator=dict(type=MGSM_Evaluator),
pred_role='BOT',
pred_postprocessor=dict(type=mgsm_bn_postprocess),
)

mgsm_eval_de_cfg = dict(
evaluator=dict(type=MGSM_Evaluator),
pred_role='BOT',
pred_postprocessor=dict(type=mgsm_de_postprocess),
)

mgsm_eval_es_cfg = dict(
evaluator=dict(type=MGSM_Evaluator),
pred_role='BOT',
pred_postprocessor=dict(type=mgsm_es_postprocess),
)

mgsm_eval_fr_cfg = dict(
evaluator=dict(type=MGSM_Evaluator),
pred_role='BOT',
pred_postprocessor=dict(type=mgsm_fr_postprocess),
)

mgsm_eval_ja_cfg = dict(
evaluator=dict(type=MGSM_Evaluator),
pred_role='BOT',
pred_postprocessor=dict(type=mgsm_ja_postprocess),
)

mgsm_eval_ru_cfg = dict(
evaluator=dict(type=MGSM_Evaluator),
pred_role='BOT',
pred_postprocessor=dict(type=mgsm_ru_postprocess),
)

mgsm_eval_sw_cfg = dict(
evaluator=dict(type=MGSM_Evaluator),
pred_role='BOT',
pred_postprocessor=dict(type=mgsm_sw_postprocess),
)

mgsm_eval_te_cfg = dict(
evaluator=dict(type=MGSM_Evaluator),
pred_role='BOT',
pred_postprocessor=dict(type=mgsm_te_postprocess),
)

mgsm_eval_th_cfg = dict(
evaluator=dict(type=MGSM_Evaluator),
pred_role='BOT',
pred_postprocessor=dict(type=mgsm_th_postprocess),
)

mgsm_eval_zh_cfg = dict(
evaluator=dict(type=MGSM_Evaluator),
pred_role='BOT',
pred_postprocessor=dict(type=mgsm_zh_postprocess),
)


#all datasets
mgsm_datasets = [
dict(
type=MGSMSDataset,
abbr='mgsm_en',
path='./data/mgsm/mgsm_en.tsv',
reader_cfg=mgsm_reader_cfg,
infer_cfg=mgsm_infer_cfg,
eval_cfg=mgsm_eval_en_cfg),
dict(
type=MGSMSDataset,
abbr='mgsm_zh',
path='./data/mgsm/mgsm_zh.tsv',
reader_cfg=mgsm_reader_cfg,
infer_cfg=mgsm_infer_cfg,
eval_cfg=mgsm_eval_zh_cfg),
dict(
type=MGSMSDataset,
abbr='mgsm_bn',
path='./data/mgsm/mgsm_bn.tsv',
reader_cfg=mgsm_reader_cfg,
infer_cfg=mgsm_infer_cfg,
eval_cfg=mgsm_eval_bn_cfg),
dict(
type=MGSMSDataset,
abbr='mgsm_de',
path='./data/mgsm/mgsm_de.tsv',
reader_cfg=mgsm_reader_cfg,
infer_cfg=mgsm_infer_cfg,
eval_cfg=mgsm_eval_de_cfg),
dict(
type=MGSMSDataset,
abbr='mgsm_es',
path='./data/mgsm/mgsm_es.tsv',
reader_cfg=mgsm_reader_cfg,
infer_cfg=mgsm_infer_cfg,
eval_cfg=mgsm_eval_es_cfg),
dict(
type=MGSMSDataset,
abbr='mgsm_fr',
path='./data/mgsm/mgsm_fr.tsv',
reader_cfg=mgsm_reader_cfg,
infer_cfg=mgsm_infer_cfg,
eval_cfg=mgsm_eval_fr_cfg),
dict(
type=MGSMSDataset,
abbr='mgsm_ja',
path='./data/mgsm/mgsm_ja.tsv',
reader_cfg=mgsm_reader_cfg,
infer_cfg=mgsm_infer_cfg,
eval_cfg=mgsm_eval_ja_cfg),
dict(
type=MGSMSDataset,
abbr='mgsm_ru',
path='./data/mgsm/mgsm_ru.tsv',
reader_cfg=mgsm_reader_cfg,
infer_cfg=mgsm_infer_cfg,
eval_cfg=mgsm_eval_ru_cfg),
dict(
type=MGSMSDataset,
abbr='mgsm_sw',
path='./data/mgsm/mgsm_sw.tsv',
reader_cfg=mgsm_reader_cfg,
infer_cfg=mgsm_infer_cfg,
eval_cfg=mgsm_eval_sw_cfg),
dict(
type=MGSMSDataset,
abbr='mgsm_te',
path='./data/mgsm/mgsm_te.tsv',
reader_cfg=mgsm_reader_cfg,
infer_cfg=mgsm_infer_cfg,
eval_cfg=mgsm_eval_te_cfg),
dict(
type=MGSMSDataset,
abbr='mgsm_th',
path='./data/mgsm/mgsm_th.tsv',
reader_cfg=mgsm_reader_cfg,
infer_cfg=mgsm_infer_cfg,
eval_cfg=mgsm_eval_th_cfg),
]




15 changes: 15 additions & 0 deletions configs/eval_internlm_mgsm_chat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from mmengine.config import read_base
from opencompass.models.huggingface import HuggingFaceCausalLM
from opencompass.partitioners import NaivePartitioner
from opencompass.partitioners.sub_naive import SubjectiveNaivePartitioner
from opencompass.runners import SlurmSequentialRunner
from opencompass.tasks import OpenICLInferTask, OpenICLEvalTask

with read_base():
from .datasets.mgsm.mgsm_gen import mgsm_datasets




# Eval MSGM_datasets
datasets = [*mgsm_datasets]
1 change: 1 addition & 0 deletions opencompass/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,4 @@
from .xiezhi import XiezhiDataset, XiezhiRetriever # noqa: F401, F403
from .xlsum import * # noqa: F401, F403
from .xsum import * # noqa: F401, F403
from .mgsm import * # noqa: F401, F403
Loading

0 comments on commit 61c477a

Please sign in to comment.