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
dd317a75
Commit
dd317a75
authored
Jul 04, 2023
by
ingyuseong
Browse files
Update KLUE-MRC metric (F1 and EM)
parent
e8f38aee
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
16 deletions
+17
-16
lm_eval/tasks/klue.py
lm_eval/tasks/klue.py
+16
-15
setup.py
setup.py
+1
-1
No files found.
lm_eval/tasks/klue.py
View file @
dd317a75
...
...
@@ -13,6 +13,7 @@ https://arxiv.org/abs/2105.09680
"""
import
datasets
import
evaluate
from
math
import
exp
import
numpy
as
np
from
lm_eval.base
import
Task
,
MultipleChoiceTask
,
rf
...
...
@@ -32,16 +33,16 @@ _CITATION = """
"""
def
_
squad
_metric
(
predictions
,
references
):
squad
_metric
=
datasets
.
load_metric
(
"squad_v2
"
)
def
_
klue_mrc
_metric
(
predictions
,
references
):
klue_mrc
_metric
=
evaluate
.
load
(
"ingyu/klue_mrc
"
)
return
squad
_metric
.
compute
(
predictions
=
predictions
,
references
=
references
)
return
klue_mrc
_metric
.
compute
(
predictions
=
predictions
,
references
=
references
)
def
_
squad
_agg
(
key
,
items
):
def
_
klue_mrc
_agg
(
key
,
items
):
predictions
,
references
=
zip
(
*
items
)
return
_
squad
_metric
(
predictions
=
predictions
,
references
=
references
)[
key
]
return
_
klue_mrc
_metric
(
predictions
=
predictions
,
references
=
references
)[
key
]
class
STS
(
Task
):
...
...
@@ -231,7 +232,7 @@ class MRC(Task):
return
self
.
dataset
[
"validation"
]
def
doc_to_text
(
self
,
doc
):
return
'
제목:
'
+
doc
[
'
title
'
]
+
'
\n\n
'
+
'
본문:
'
+
doc
[
'
context
'
]
+
'
\n\n
'
+
'
질문:
'
+
doc
[
'
question
'
]
+
'
\n\n
'
+
'
답:
'
return
"
제목:
"
+
doc
[
"
title
"
]
+
"
\n\n
"
+
"
본문:
"
+
doc
[
"
context
"
]
+
"
\n\n
"
+
"
질문:
"
+
doc
[
"
question
"
]
+
"
\n\n
"
+
"
답:
"
def
doc_to_target
(
self
,
doc
):
answer
=
doc
[
"answers"
][
"text"
][
0
]
...
...
@@ -250,7 +251,7 @@ class MRC(Task):
language description, as well as the few shot examples, and the question
part of the document for `doc`.
"""
continuation
=
rf
.
greedy_until
(
ctx
,
[
'
\n
'
]
)
continuation
=
rf
.
greedy_until
(
ctx
,
{
"until"
:
[
"
\n
"
]}
)
is_unanswerable
=
rf
.
loglikelihood
(
ctx
,
" "
+
"대답 불가"
)
return
continuation
,
is_unanswerable
...
...
@@ -320,28 +321,28 @@ class MRC(Task):
"""
return
{
"exact"
:
partial
(
_
squad
_agg
,
"exact"
_
klue_mrc
_agg
,
"exact"
),
# Exact match (the normalized answer exactly match the gold answer)
"f1"
:
partial
(
_
squad
_agg
,
"f1"
_
klue_mrc
_agg
,
"f1"
),
# The F-score of predicted tokens versus the gold answer
"HasAns_exact"
:
partial
(
_
squad
_agg
,
"HasAns_exact"
_
klue_mrc
_agg
,
"HasAns_exact"
),
# Exact match (the normalized answer exactly match the gold answer)
"HasAns_f1"
:
partial
(
_
squad
_agg
,
"HasAns_f1"
_
klue_mrc
_agg
,
"HasAns_f1"
),
# The F-score of predicted tokens versus the gold answer
"NoAns_exact"
:
partial
(
_
squad
_agg
,
"NoAns_exact"
_
klue_mrc
_agg
,
"NoAns_exact"
),
# Exact match (the normalized answer exactly match the gold answer)
"NoAns_f1"
:
partial
(
_
squad
_agg
,
"NoAns_f1"
_
klue_mrc
_agg
,
"NoAns_f1"
),
# The F-score of predicted tokens versus the gold answer
"best_exact"
:
partial
(
_
squad
_agg
,
"best_exact"
_
klue_mrc
_agg
,
"best_exact"
),
# Best exact match (with varying threshold)
"best_f1"
:
partial
(
_
squad
_agg
,
"best_f1"
_
klue_mrc
_agg
,
"best_f1"
),
# Best F1 (with varying threshold)
}
...
...
setup.py
View file @
dd317a75
...
...
@@ -42,7 +42,7 @@ setuptools.setup(
],
extras_require
=
{
"dev"
:
[
"black"
,
"flake8"
,
"pre-commit"
,
"pytest"
,
"pytest-cov"
],
"multilingual"
:
[
"nagisa>=0.2.7"
,
"jieba>=0.42.1"
],
"multilingual"
:
[
"nagisa>=0.2.7"
,
"jieba>=0.42.1"
,
"evaluate>=0.4.0"
],
"sentencepiece"
:
[
"sentencepiece>=0.1.98"
,
"protobuf>=4.22.1"
],
},
)
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