Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
lm-evaluation-harness
Commits
3839125a
Unverified
Commit
3839125a
authored
Sep 06, 2023
by
Lintang Sutawika
Committed by
GitHub
Sep 06, 2023
Browse files
Merge pull request #784 from EleutherAI/mgsm
[Refactor] mgsm
parents
784fe037
78522c94
Changes
27
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
269 additions
and
0 deletions
+269
-0
lm_eval/tasks/mgsm/native_cot/mgsm_cot_native_ja.yaml
lm_eval/tasks/mgsm/native_cot/mgsm_cot_native_ja.yaml
+14
-0
lm_eval/tasks/mgsm/native_cot/mgsm_cot_native_ru.yaml
lm_eval/tasks/mgsm/native_cot/mgsm_cot_native_ru.yaml
+14
-0
lm_eval/tasks/mgsm/native_cot/mgsm_cot_native_sw.yaml
lm_eval/tasks/mgsm/native_cot/mgsm_cot_native_sw.yaml
+14
-0
lm_eval/tasks/mgsm/native_cot/mgsm_cot_native_te.yaml
lm_eval/tasks/mgsm/native_cot/mgsm_cot_native_te.yaml
+14
-0
lm_eval/tasks/mgsm/native_cot/mgsm_cot_native_th.yaml
lm_eval/tasks/mgsm/native_cot/mgsm_cot_native_th.yaml
+14
-0
lm_eval/tasks/mgsm/native_cot/mgsm_cot_native_zh.yaml
lm_eval/tasks/mgsm/native_cot/mgsm_cot_native_zh.yaml
+14
-0
lm_eval/tasks/mgsm/utils.py
lm_eval/tasks/mgsm/utils.py
+185
-0
No files found.
lm_eval/tasks/mgsm/native_cot/mgsm_cot_native_ja.yaml
0 → 100644
View file @
3839125a
# Generated by utils.py
dataset_name
:
ja
doc_to_target
:
'
{%
if
answer
is
not
none
%}{{answer[10+1]}}{%
else
%}{{answer_number|string}}{%
endif
%}'
doc_to_text
:
'
{%
if
answer
is
not
none
%}{{question+"\nステップごとの答え:"}}{%
else
%}{{"問題:
"+question+"\nステップごとの答え:"}}{%
endif
%}'
filter
:
-
function
:
regex
regex_pattern
:
The answer is (\-?[0-9\.\,]+)
-
function
:
take_first
filter_list
:
-
name
:
get-answer
include
:
cot_yaml
task
:
mgsm_ja_direct
lm_eval/tasks/mgsm/native_cot/mgsm_cot_native_ru.yaml
0 → 100644
View file @
3839125a
# Generated by utils.py
dataset_name
:
ru
doc_to_target
:
'
{%
if
answer
is
not
none
%}{{answer[17+1]}}{%
else
%}{{answer_number|string}}{%
endif
%}'
doc_to_text
:
'
{%
if
answer
is
not
none
%}{{question+"\nПошаговоерешение:"}}{%
else
%}{{"Задача:
"+question+"\nПошаговоерешение:"}}{%
endif
%}'
filter
:
-
function
:
regex
regex_pattern
:
The answer is (\-?[0-9\.\,]+)
-
function
:
take_first
filter_list
:
-
name
:
get-answer
include
:
cot_yaml
task
:
mgsm_ru_direct
lm_eval/tasks/mgsm/native_cot/mgsm_cot_native_sw.yaml
0 → 100644
View file @
3839125a
# Generated by utils.py
dataset_name
:
sw
doc_to_target
:
'
{%
if
answer
is
not
none
%}{{answer[24+1]}}{%
else
%}{{answer_number|string}}{%
endif
%}'
doc_to_text
:
'
{%
if
answer
is
not
none
%}{{question+"\nJibu
la
Hatua
kwa
Hatua:"}}{%
else
%}{{"Swali:
"+question+"\nJibu
la
Hatua
kwa
Hatua:"}}{%
endif
%}'
filter
:
-
function
:
regex
regex_pattern
:
The answer is (\-?[0-9\.\,]+)
-
function
:
take_first
filter_list
:
-
name
:
get-answer
include
:
cot_yaml
task
:
mgsm_sw_direct
lm_eval/tasks/mgsm/native_cot/mgsm_cot_native_te.yaml
0 → 100644
View file @
3839125a
# Generated by utils.py
dataset_name
:
te
doc_to_target
:
'
{%
if
answer
is
not
none
%}{{answer[18+1]}}{%
else
%}{{answer_number|string}}{%
endif
%}'
doc_to_text
:
'
{%
if
answer
is
not
none
%}{{question+"\nదశలవారీగా
సమాధానం:"}}{%
else
%}{{"ప్రశ్న:
"+question+"\nదశలవారీగా
సమాధానం:"}}{%
endif
%}'
filter
:
-
function
:
regex
regex_pattern
:
The answer is (\-?[0-9\.\,]+)
-
function
:
take_first
filter_list
:
-
name
:
get-answer
include
:
cot_yaml
task
:
mgsm_te_direct
lm_eval/tasks/mgsm/native_cot/mgsm_cot_native_th.yaml
0 → 100644
View file @
3839125a
# Generated by utils.py
dataset_name
:
th
doc_to_target
:
'
{%
if
answer
is
not
none
%}{{answer[17+1]}}{%
else
%}{{answer_number|string}}{%
endif
%}'
doc_to_text
:
'
{%
if
answer
is
not
none
%}{{question+"\nคำตอบทีละขั้นตอน:"}}{%
else
%}{{"โจทย์:
"+question+"\nคำตอบทีละขั้นตอน:"}}{%
endif
%}'
filter
:
-
function
:
regex
regex_pattern
:
The answer is (\-?[0-9\.\,]+)
-
function
:
take_first
filter_list
:
-
name
:
get-answer
include
:
cot_yaml
task
:
mgsm_th_direct
lm_eval/tasks/mgsm/native_cot/mgsm_cot_native_zh.yaml
0 → 100644
View file @
3839125a
# Generated by utils.py
dataset_name
:
zh
doc_to_target
:
'
{%
if
answer
is
not
none
%}{{answer[5+1]}}{%
else
%}{{answer_number|string}}{%
endif
%}'
doc_to_text
:
'
{%
if
answer
is
not
none
%}{{question+"\n逐步解答:"}}{%
else
%}{{"问题:
"+question+"\n逐步解答:"}}{%
endif
%}'
filter
:
-
function
:
regex
regex_pattern
:
The answer is (\-?[0-9\.\,]+)
-
function
:
take_first
filter_list
:
-
name
:
get-answer
include
:
cot_yaml
task
:
mgsm_zh_direct
lm_eval/tasks/mgsm/utils.py
0 → 100644
View file @
3839125a
import
yaml
import
argparse
LANGUAGES
=
{
"bn"
:
{
# Bengali
"QUESTION"
:
"
\u09aa\u09cd\u09b0\u09b6\u09cd\u09a8
:"
,
"ANSWER"
:
"
\u09a7\u09be\u09aa\u09c7
\u09a7\u09be\u09aa\u09c7
\u0989\u09a4\u09cd\u09a4\u09b0
:"
,
"DIRECT"
:
"Answer:"
,
"REGEX"
:
"The answer is (
\\
-?[0-9
\\
.
\\
,]+)"
,
},
"de"
:
{
# German
"QUESTION"
:
"Frage:"
,
"ANSWER"
:
"Schritt-f
\u00fc
r-Schritt-Antwort:"
,
"DIRECT"
:
"Antwort:"
,
"REGEX"
:
"The answer is (
\\
-?[0-9
\\
.
\\
,]+)"
,
},
"en"
:
{
# English
"QUESTION"
:
"Question:"
,
"ANSWER"
:
"Step-by-Step Answer:"
,
"DIRECT"
:
"Answer:"
,
"REGEX"
:
"The answer is (
\\
-?[0-9
\\
.
\\
,]+)"
,
},
"es"
:
{
# Spanish
"QUESTION"
:
"Pregunta:"
,
"ANSWER"
:
"Respuesta paso a paso:"
,
"DIRECT"
:
"Answer:"
,
"REGEX"
:
"The answer is (
\\
-?[0-9
\\
.
\\
,]+)"
,
},
"fr"
:
{
# French
"QUESTION"
:
"Question :"
,
"ANSWER"
:
"R
\u00e9
ponse
\u00e9
tape par
\u00e9
tape :"
,
"DIRECT"
:
"Answer:"
,
"REGEX"
:
"The answer is (
\\
-?[0-9
\\
.
\\
,]+)"
,
},
"ru"
:
{
# Russian
"QUESTION"
:
"
\u0417\u0430\u0434\u0430\u0447\u0430
:"
,
"ANSWER"
:
"
\u041f\u043e\u0448\u0430\u0433\u043e\u0432\u043e\u0435\u0440\u0435\u0448\u0435\u043d\u0438\u0435
:"
,
"DIRECT"
:
"Answer:"
,
"REGEX"
:
"The answer is (
\\
-?[0-9
\\
.
\\
,]+)"
,
},
"sw"
:
{
# Swahili
"QUESTION"
:
"Swali:"
,
"ANSWER"
:
"Jibu la Hatua kwa Hatua:"
,
"DIRECT"
:
"Answer:"
,
"REGEX"
:
"The answer is (
\\
-?[0-9
\\
.
\\
,]+)"
,
},
"te"
:
{
# Telugu
"QUESTION"
:
"
\u0c2a\u0c4d\u0c30\u0c36\u0c4d\u0c28
:"
,
"ANSWER"
:
"
\u0c26\u0c36\u0c32\u0c35\u0c3e\u0c30\u0c40\u0c17\u0c3e
\u0c38\u0c2e\u0c3e\u0c27\u0c3e\u0c28\u0c02
:"
,
"DIRECT"
:
"Answer:"
,
"REGEX"
:
"The answer is (
\\
-?[0-9
\\
.
\\
,]+)"
,
},
"th"
:
{
# Thai
"QUESTION"
:
"
\u0e42\u0e08\u0e17\u0e22\u0e4c
:"
,
"ANSWER"
:
"
\u0e04\u0e33\u0e15\u0e2d\u0e1a\u0e17\u0e35\u0e25\u0e30\u0e02\u0e31\u0e49\u0e19\u0e15\u0e2d\u0e19
:"
,
"DIRECT"
:
"Answer:"
,
"REGEX"
:
"The answer is (
\\
-?[0-9
\\
.
\\
,]+)"
,
},
"ja"
:
{
# Japanese
"QUESTION"
:
"
\u554f\u984c
:"
,
"ANSWER"
:
"
\u30b9\u30c6\u30c3\u30d7\u3054\u3068\u306e\u7b54\u3048
:"
,
"DIRECT"
:
"Answer:"
,
"REGEX"
:
"The answer is (
\\
-?[0-9
\\
.
\\
,]+)"
,
},
"zh"
:
{
# Chinese
"QUESTION"
:
"
\u95ee\u9898
:"
,
"ANSWER"
:
"
\u9010\u6b65\u89e3\u7b54
:"
,
"DIRECT"
:
"Answer:"
,
"REGEX"
:
"The answer is (
\\
-?[0-9
\\
.
\\
,]+)"
,
},
}
def
add_regex_pattern
(
regex_pattern
):
if
regex_pattern
is
None
:
return
{}
return
{
"filter_list"
:
[
{
"name"
:
"get-answer"
,
},
],
"filter"
:
[
{
"function"
:
"regex"
,
"regex_pattern"
:
regex_pattern
,
},
{
"function"
:
"take_first"
,
},
],
}
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
=
[]
for
lang
in
LANGUAGES
.
keys
():
try
:
QUESTION
=
LANGUAGES
[
lang
][
"QUESTION"
]
yaml_template
=
"cot_yaml"
if
mode
==
"direct"
:
ANSWER
=
LANGUAGES
[
lang
][
"DIRECT"
]
REGEX
=
None
task_name
=
f
"mgsm_
{
lang
}
_direct"
yaml_template
=
"direct_yaml"
elif
mode
==
"native-cot"
:
ANSWER
=
LANGUAGES
[
lang
][
"ANSWER"
]
REGEX
=
LANGUAGES
[
lang
][
"REGEX"
]
task_name
=
f
"mgsm_
{
lang
}
_native-cot"
elif
mode
==
"en-cot"
:
ANSWER
=
LANGUAGES
[
"en"
][
"ANSWER"
]
REGEX
=
LANGUAGES
[
"en"
][
"REGEX"
]
task_name
=
f
"mgsm_
{
lang
}
_en-cot"
file_name
=
f
"
{
task_name
}
.yaml"
filter_list
=
add_regex_pattern
(
REGEX
)
with
open
(
f
"
{
output_dir
}
/
{
file_name
}
"
,
"w"
if
overwrite
else
"x"
,
encoding
=
"utf8"
)
as
f
:
f
.
write
(
"# Generated by utils.py
\n
"
)
yaml
.
dump
(
{
"include"
:
yaml_template
,
"dataset_name"
:
lang
,
"task"
:
f
"mgsm_
{
lang
}
_direct"
,
"doc_to_text"
:
f
"""{{% if answer is not none %}}"""
f
"""{{{{question+"
\\
n
{
ANSWER
}
"}}}}"""
f
"""{{% else %}}"""
f
"""{{{{"
{
QUESTION
}
"+question+"
\\
n
{
ANSWER
}
"}}}}"""
f
"""{{% endif %}}"""
,
"doc_to_target"
:
f
"""{{% if answer is not none %}}"""
f
"""{{{{answer[
{
len
(
ANSWER
)
}
+1]}}}}"""
f
"""{{% else %}}"""
f
"""{{{{answer_number|string}}}}"""
f
"""{{% endif %}}"""
,
**
filter_list
,
},
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
=
False
,
action
=
"store_true"
,
help
=
"Overwrite files if they already exist"
,
)
parser
.
add_argument
(
"--output-dir"
,
default
=
"."
,
help
=
"Directory to write yaml files to"
)
parser
.
add_argument
(
"--mode"
,
default
=
"native-cot"
,
choices
=
[
"direct"
,
"native-cot"
,
"en-cot"
],
help
=
"Mode of chain-of-thought"
,
)
args
=
parser
.
parse_args
()
gen_lang_yamls
(
output_dir
=
args
.
output_dir
,
overwrite
=
args
.
overwrite
,
mode
=
args
.
mode
)
if
__name__
==
"__main__"
:
main
()
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment