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
b57d059a
Commit
b57d059a
authored
Feb 03, 2021
by
Leo Gao
Browse files
Fix lambada
parent
8eada53b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
4 deletions
+10
-4
lm_eval/base.py
lm_eval/base.py
+4
-0
lm_eval/tasks/lambada.py
lm_eval/tasks/lambada.py
+6
-4
No files found.
lm_eval/base.py
View file @
b57d059a
...
...
@@ -2,6 +2,7 @@ import abc
import
random
import
numpy
as
np
import
sklearn
import
math
class
LM
(
abc
.
ABC
):
...
...
@@ -229,6 +230,9 @@ def metric_max_over_ground_truths(metric_fn, prediction, ground_truths):
return
max
(
scores_for_ground_truths
)
def
perplexity
(
items
):
return
math
.
exp
(
-
mean
(
items
))
req_ret_lens
=
{
'loglikelihood'
:
2
}
...
...
lm_eval/tasks/lambada.py
View file @
b57d059a
from
lm_eval.base
import
Task
,
rf
,
mean
from
lm_eval.base
import
Task
,
rf
,
mean
,
perplexity
from
lm_eval.utils
import
sh
import
json
import
math
...
...
@@ -45,21 +45,23 @@ class LAMBADA(Task):
return
""
def
construct_requests
(
self
,
doc
,
ctx
):
ll
,
is_greedy
=
rf
.
loglikelihood
(
doc
,
self
.
doc_to_target
(
doc
))
ll
,
is_greedy
=
rf
.
loglikelihood
(
ctx
,
self
.
doc_to_target
(
doc
))
return
ll
,
is_greedy
def
process_results
(
self
,
doc
,
results
):
ll
,
is_greedy
=
results
print
(
ll
)
return
{
'perplexity'
:
math
.
exp
(
-
ll
)
,
'perplexity'
:
ll
,
'accuracy'
:
int
(
is_greedy
)
}
def
aggregation
(
self
):
return
{
'perplexity'
:
mean
,
'perplexity'
:
perplexity
,
'accuracy'
:
mean
}
...
...
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