Commit c75c66e4 authored by Baber's avatar Baber
Browse files

fix

parent c77ae9af
...@@ -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]]:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment