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
c75c66e4
Commit
c75c66e4
authored
Jul 30, 2025
by
Baber
Browse files
fix
parent
c77ae9af
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
5 deletions
+4
-5
lm_eval/tasks/mbpp/utils.py
lm_eval/tasks/mbpp/utils.py
+4
-5
No files found.
lm_eval/tasks/mbpp/utils.py
View file @
c75c66e4
...
@@ -32,13 +32,11 @@ def pass_at_1(
...
@@ -32,13 +32,11 @@ def pass_at_1(
def
pass_at_10
(
def
pass_at_10
(
references
:
Union
[
str
,
list
[
str
]],
predictions
:
Union
[
str
,
list
[
list
[
str
]]]
references
:
Union
[
str
,
list
[
str
]],
predictions
:
Union
[
str
,
list
[
list
[
str
]]]
)
->
float
:
)
->
float
:
global
pass_at_k
if
isinstance
(
references
,
str
):
if
isinstance
(
references
,
str
):
references
=
[
references
]
references
=
[
references
]
if
isinstance
(
predictions
[
0
],
str
):
if
isinstance
(
predictions
[
0
],
str
):
predictions
=
[[
p
]
for
p
in
predictions
]
predictions
=
[[
p
]
for
p
in
predictions
]
print
(
"references: "
,
references
)
print
(
"predictions: "
,
predictions
)
pass_at_k
=
hf_evaluate
.
load
(
"code_eval"
)
res
=
pass_at_k
.
compute
(
res
=
pass_at_k
.
compute
(
references
=
references
,
predictions
=
predictions
,
k
=
[
10
],
num_workers
=
20
references
=
references
,
predictions
=
predictions
,
k
=
[
10
],
num_workers
=
20
)
)
...
@@ -47,6 +45,7 @@ def pass_at_10(
...
@@ -47,6 +45,7 @@ def pass_at_10(
def
extract_code_blocks
(
text
:
str
)
->
str
:
def
extract_code_blocks
(
text
:
str
)
->
str
:
# Pattern to match ```...``` blocks
# Pattern to match ```...``` blocks
ignore_annotations
=
"from __future__ import annotations/n"
pattern
=
r
"```(?:\w+)?\n?(.*?)\n?```"
pattern
=
r
"```(?:\w+)?\n?(.*?)\n?```"
# (+ ```) as we add the opening "```python" to the gen_prefix
# (+ ```) as we add the opening "```python" to the gen_prefix
matches
=
re
.
findall
(
pattern
,
r
"```"
+
text
,
re
.
DOTALL
)
matches
=
re
.
findall
(
pattern
,
r
"```"
+
text
,
re
.
DOTALL
)
...
@@ -55,9 +54,9 @@ def extract_code_blocks(text: str) -> str:
...
@@ -55,9 +54,9 @@ def extract_code_blocks(text: str) -> str:
text_without_lang
=
re
.
sub
(
r
"```python"
,
"```"
,
text
)
text_without_lang
=
re
.
sub
(
r
"```python"
,
"```"
,
text
)
matches
=
re
.
findall
(
pattern
,
text_without_lang
,
re
.
DOTALL
)
matches
=
re
.
findall
(
pattern
,
text_without_lang
,
re
.
DOTALL
)
if
not
matches
:
if
not
matches
:
return
""
return
ignore_annotations
+
text
else
:
else
:
return
matches
[
0
]
return
ignore_annotations
+
matches
[
0
]
def
build_predictions
(
resps
:
list
[
list
[
str
]],
docs
:
list
[
dict
])
->
list
[
list
[
str
]]:
def
build_predictions
(
resps
:
list
[
list
[
str
]],
docs
:
list
[
dict
])
->
list
[
list
[
str
]]:
...
...
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