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
b691c44f
Commit
b691c44f
authored
May 11, 2021
by
Leo Gao
Browse files
Count perplexity correctly
parent
9c4967bc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
5 deletions
+10
-5
lm_eval/base.py
lm_eval/base.py
+7
-5
lm_eval/metrics.py
lm_eval/metrics.py
+3
-0
No files found.
lm_eval/base.py
View file @
b691c44f
...
...
@@ -3,7 +3,7 @@ import random
import
numpy
as
np
import
re
from
lm_eval.metrics
import
mean
,
perplexity
,
weighted_mean
from
lm_eval.metrics
import
mean
,
perplexity
,
weighted_perplexity
,
weighted_mean
class
LM
(
abc
.
ABC
):
...
...
@@ -327,16 +327,18 @@ class PerplexityTask(Task, abc.ABC):
def
process_results
(
self
,
doc
,
results
):
loglikelihood
,
=
results
words
=
self
.
count_words
(
self
.
doc_to_text
(
doc
))
bytes
=
self
.
count_bytes
(
self
.
doc_to_text
(
doc
))
return
{
"word_perplexity"
:
loglikelihood
/
self
.
count_words
(
self
.
doc_to_text
(
doc
)
),
"byte_perplexity"
:
loglikelihood
/
self
.
count_bytes
(
self
.
doc_to_text
(
doc
)
),
"word_perplexity"
:
(
loglikelihood
,
words
),
"byte_perplexity"
:
(
loglikelihood
,
bytes
),
"bits_per_byte"
:
(
-
loglikelihood
,
self
.
count_bytes
(
self
.
doc_to_text
(
doc
)))
}
def
aggregation
(
self
):
return
{
"word_perplexity"
:
perplexity
,
"byte_perplexity"
:
perplexity
,
"word_perplexity"
:
weighted_
perplexity
,
"byte_perplexity"
:
weighted_
perplexity
,
"bits_per_byte"
:
weighted_mean
}
...
...
lm_eval/metrics.py
View file @
b691c44f
...
...
@@ -98,6 +98,9 @@ def weighted_mean(items):
a
,
b
=
zip
(
*
items
)
return
sum
(
a
)
/
sum
(
b
)
def
weighted_perplexity
(
items
):
return
math
.
exp
(
-
weighted_mean
(
items
))
def
bleu
(
items
):
"""The Bilingual Evaluation Understudy Score, or BLEU for short, is a metric
...
...
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