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
432bd44c
Commit
432bd44c
authored
Feb 10, 2021
by
Leo Gao
Browse files
Fixes to make greedy_until work
# Conflicts: # lm_eval/models/gpt2.py # lm_eval/tasks/squad.py
parent
e8f9dc71
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
15 additions
and
5 deletions
+15
-5
lm_eval/base.py
lm_eval/base.py
+5
-0
lm_eval/evaluator.py
lm_eval/evaluator.py
+1
-0
lm_eval/models/dummy.py
lm_eval/models/dummy.py
+6
-2
lm_eval/models/gpt2.py
lm_eval/models/gpt2.py
+1
-1
lm_eval/tasks/arithmetic.py
lm_eval/tasks/arithmetic.py
+1
-1
lm_eval/tasks/squad.py
lm_eval/tasks/squad.py
+1
-1
No files found.
lm_eval/base.py
View file @
432bd44c
...
...
@@ -269,6 +269,7 @@ def perplexity(items):
req_ret_lens
=
{
'loglikelihood'
:
2
,
'greedy_until'
:
None
,
}
import
os
...
...
@@ -335,11 +336,15 @@ class Request:
self
.
index
=
index
def
__iter__
(
self
):
if
req_ret_lens
[
self
.
type
]
is
None
:
raise
IndexError
(
'This request type does not return multiple arguments!'
)
i
=
0
for
i
in
range
(
req_ret_lens
[
self
.
type
]):
yield
Request
(
self
.
type
,
self
.
args
,
i
)
def
__getitem__
(
self
,
i
):
if
req_ret_lens
[
self
.
type
]
is
None
:
raise
IndexError
(
'This request type does not return multiple arguments!'
)
return
Request
(
self
.
type
,
self
.
args
,
i
)
def
__eq__
(
self
,
other
):
...
...
lm_eval/evaluator.py
View file @
432bd44c
...
...
@@ -39,6 +39,7 @@ def evaluate(lm, task_dict, provide_description, num_fewshot, limit):
)
reqs
=
task
.
construct_requests
(
doc
,
ctx
)
if
not
isinstance
(
reqs
,
(
list
,
tuple
)):
reqs
=
[
reqs
]
for
i
,
req
in
enumerate
(
reqs
):
requests
[
req
.
type
].
append
(
req
)
...
...
lm_eval/models/dummy.py
View file @
432bd44c
...
...
@@ -19,5 +19,9 @@ class DummyLM(LM):
return
res
def
greedy_until
(
self
,
requests
):
# TODO: implement
pass
res
=
[]
for
_
in
requests
:
res
.
append
(
"lol"
)
return
res
lm_eval/models/gpt2.py
View file @
432bd44c
...
...
@@ -66,7 +66,7 @@ class GPT2LM(LM):
cont
=
self
.
gpt2
.
generate
(
context_enc
,
max_length
=
self
.
MAX_GEN_TOKS
,
max_length
=
context_enc
.
shape
[
1
]
+
self
.
MAX_GEN_TOKS
,
eos_token_id
=
primary_until
,
do_sample
=
False
)
...
...
lm_eval/tasks/arithmetic.py
View file @
432bd44c
...
...
@@ -66,7 +66,7 @@ class Arithmetic(Task):
return
is_prediction
def
process_results
(
self
,
doc
,
results
):
ll
,
is_prediction
=
results
is_prediction
,
=
results
return
{
"acc"
:
is_prediction
}
...
...
lm_eval/tasks/squad.py
View file @
432bd44c
...
...
@@ -30,7 +30,7 @@ class SQuAD(HFTask):
return
"Title: The_Title_of_It
\n\n
Background: A text passage as background to answer the question with.
\n\n
Q: Question about the passage.
\n\n
A: Answer."
def
doc_to_text
(
self
,
doc
):
return
'Title: '
+
doc
[
'title'
]
+
'
\n\n
'
+
'Background: '
+
doc
[
'context'
]
+
'
\n\n
'
+
'Q: '
+
doc
[
'question'
]
+
'
\n\n
'
+
'A:
'
return
'Title: '
+
doc
[
'title'
]
+
'
\n\n
'
+
'Background: '
+
doc
[
'context'
]
+
'
\n\n
'
+
'Q
uestion
: '
+
doc
[
'question'
]
+
'
\n\n
'
+
'A
nswer
:'
def
doc_to_target
(
self
,
doc
):
answer_list
=
doc
[
'answers'
][
'text'
]
...
...
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