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
5f4c7c50
Commit
5f4c7c50
authored
Feb 03, 2021
by
Leo Gao
Browse files
Implement gpt3 greedy_until
parent
38e8858f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
5 deletions
+21
-5
lm_eval/models/gpt3.py
lm_eval/models/gpt3.py
+21
-5
No files found.
lm_eval/models/gpt3.py
View file @
5f4c7c50
...
...
@@ -25,6 +25,7 @@ class GPT3LM(LM):
MAX_LENGTH
=
2048
REQ_CHUNK_SIZE
=
64
MAX_GEN_TOKS
=
256
def
__init__
(
self
,
engine
,
truncate
=
False
):
"""
...
...
@@ -48,9 +49,6 @@ class GPT3LM(LM):
return
cls
(
engine
=
args
.
get
(
"engine"
,
"davinci"
))
def
loglikelihood
(
self
,
requests
):
import
openai
res
=
[]
for
chunk
in
tqdm
(
utils
.
chunks
(
requests
,
self
.
REQ_CHUNK_SIZE
)):
inps
=
[]
ctxlens
=
[]
...
...
@@ -78,5 +76,23 @@ class GPT3LM(LM):
return
res
def
greedy_until
(
self
,
requests
):
# TODO: implement
pass
\ No newline at end of file
import
openai
res
=
[]
for
context
,
until
in
tqdm
(
requests
):
context_enc
=
self
.
tokenizer
.
encode
(
context
)
inp
=
context_enc
[
-
(
self
.
MAX_LENGTH
-
self
.
MAX_GEN_TOKS
):]
ctxlen
=
len
(
context_enc
)
-
max
(
0
,
len
(
context_enc
)
-
(
self
.
MAX_LENGTH
-
self
.
MAX_GEN_TOKS
))
response
=
openai
.
Completion
.
create
(
engine
=
self
.
engine
,
prompt
=
[
inp
],
max_tokens
=
self
.
MAX_GEN_TOKS
,
temperature
=
0.
,
logprobs
=
10
,
)
res
.
append
(
response
.
choices
[
0
][
'text'
])
return
res
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