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
1f3b3988
Commit
1f3b3988
authored
Sep 06, 2020
by
Leo Gao
Browse files
Update boolq
parent
ba2b849c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
12 deletions
+4
-12
hf.py
hf.py
+4
-12
No files found.
hf.py
View file @
1f3b3988
import
base
import
base
import
nlp
import
nlp
def
yesno
(
x
):
def
yesno
(
x
):
if
x
:
return
'yes'
if
x
:
return
'yes'
else
:
return
'no'
else
:
return
'no'
...
@@ -24,15 +23,8 @@ class BoolQ(base.Dataset):
...
@@ -24,15 +23,8 @@ class BoolQ(base.Dataset):
def
test_docs
(
self
):
def
test_docs
(
self
):
return
[]
return
[]
def
fewshot_examples
(
self
,
k
):
traindocs
=
list
(
self
.
training_docs
())
random
.
seed
(
123
)
random
.
shuffle
(
traindocs
)
return
traindocs
[:
k
]
def
fewshot_description
(
self
):
def
fewshot_description
(
self
):
return
"Read the following passage and answer
the
question with a yes or a no."
return
"Read the following passage
s
and answer
each
question with a yes or a no."
def
doc_to_text
(
self
,
doc
,
include_target
=
True
):
def
doc_to_text
(
self
,
doc
,
include_target
=
True
):
return
f
"
{
doc
[
'passage'
]
}
\n
question:
{
doc
[
'question'
]
}
\n
answer: "
+
(
yesno
(
doc
[
'answer'
])
if
include_target
else
""
)
return
f
"
{
doc
[
'passage'
]
}
\n
question:
{
doc
[
'question'
]
}
\n
answer: "
+
(
yesno
(
doc
[
'answer'
])
if
include_target
else
""
)
...
@@ -40,9 +32,9 @@ class BoolQ(base.Dataset):
...
@@ -40,9 +32,9 @@ class BoolQ(base.Dataset):
def
evaluate
(
self
,
docs
,
lm
,
provide_description
,
num_fewshot
):
def
evaluate
(
self
,
docs
,
lm
,
provide_description
,
num_fewshot
):
acc
=
[]
acc
=
[]
for
doc
in
docs
:
for
doc
in
docs
:
ctx
=
'
\n\n
'
.
join
(
map
(
doc_to_text
,
self
.
fewshot_examples
()))
+
'
\n\n
'
ctx
=
'
\n\n
'
.
join
(
map
(
self
.
doc_to_text
,
self
.
fewshot_examples
(
k
=
num_fewshot
)))
+
'
\n\n
'
ctx
+=
doc_to_text
(
doc
,
include_target
=
False
)
ctx
+=
self
.
doc_to_text
(
doc
,
include_target
=
False
)
.
strip
()
ctx
=
((
self
.
fewshot_description
()
+
"
\n
"
)
if
provide_description
else
""
)
+
ctx
ctx
=
((
self
.
fewshot_description
()
+
"
\n
\n
"
)
if
provide_description
else
""
)
+
ctx
ans
=
lm
.
loglikelihood
(
ctx
,
'yes'
)
>
lm
.
loglikelihood
(
ctx
,
'no'
)
ans
=
lm
.
loglikelihood
(
ctx
,
'yes'
)
>
lm
.
loglikelihood
(
ctx
,
'no'
)
...
...
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