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
c9a3fd3f
Commit
c9a3fd3f
authored
Nov 15, 2023
by
lintangsutawika
Browse files
update squad file
parent
5a4fc8fb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
1 deletion
+17
-1
lm_eval/tasks/__init__.py
lm_eval/tasks/__init__.py
+1
-1
lm_eval/tasks/squadv2/task.py
lm_eval/tasks/squadv2/task.py
+16
-0
No files found.
lm_eval/tasks/__init__.py
View file @
c9a3fd3f
...
...
@@ -16,7 +16,7 @@ from lm_eval.api.registry import (
import
logging
# import python tasks
from
.squad
import
SQuAD2
from
.squad
v2.task
import
SQuAD2
from
.scrolls.task
import
(
QuALITY
,
NarrativeQA
,
...
...
lm_eval/tasks/squad.py
→
lm_eval/tasks/squad
v2/task
.py
View file @
c9a3fd3f
...
...
@@ -14,6 +14,7 @@ also determine when no answer is supported by the paragraph and abstain from ans
Homepage: https://rajpurkar.github.io/SQuAD-explorer/
"""
import
datasets
from
evaluate
import
load
from
math
import
exp
from
functools
import
partial
...
...
@@ -36,6 +37,7 @@ _CITATION = """
def
_squad_metric
(
predictions
,
references
):
# squad_metric = load("squad_v2")
squad_metric
=
datasets
.
load_metric
(
"squad_v2"
)
return
squad_metric
.
compute
(
predictions
=
predictions
,
references
=
references
)
...
...
@@ -46,6 +48,20 @@ def _squad_agg(key, items):
return
_squad_metric
(
predictions
=
predictions
,
references
=
references
).
get
(
key
,
0
)
def
normalize_answer
(
s
):
"""Lower text and remove punctuation, articles and extra whitespace."""
def
remove_articles
(
text
):
regex
=
re
.
compile
(
r
'\b(a|an|the)\b'
,
re
.
UNICODE
)
return
re
.
sub
(
regex
,
' '
,
text
)
def
white_space_fix
(
text
):
return
' '
.
join
(
text
.
split
())
def
remove_punc
(
text
):
exclude
=
set
(
string
.
punctuation
)
return
''
.
join
(
ch
for
ch
in
text
if
ch
not
in
exclude
)
def
lower
(
text
):
return
text
.
lower
()
return
white_space_fix
(
remove_articles
(
remove_punc
(
lower
(
s
))))
@
register_task
(
"squadv2"
)
class
SQuAD2
(
Task
):
VERSION
=
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