Spaces:
Running
Running
Remove leftover math.py to stop shadowing stdlib
Browse files
math.py
DELETED
|
@@ -1,49 +0,0 @@
|
|
| 1 |
-
# Copyright 2024 Bytedance Ltd. and/or its affiliates
|
| 2 |
-
#
|
| 3 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
-
# you may not use this file except in compliance with the License.
|
| 5 |
-
# You may obtain a copy of the License at
|
| 6 |
-
#
|
| 7 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
-
#
|
| 9 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
-
# See the License for the specific language governing permissions and
|
| 13 |
-
# limitations under the License.
|
| 14 |
-
|
| 15 |
-
import re
|
| 16 |
-
from typing import Dict, List
|
| 17 |
-
|
| 18 |
-
from mathruler.grader import extract_boxed_content, grade_answer
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
def format_reward(predict: str) -> float:
|
| 22 |
-
pattern = re.compile(r"<think>.*</think>.*\\boxed\{.*\}.*", re.DOTALL)
|
| 23 |
-
format_match = re.fullmatch(pattern, predict)
|
| 24 |
-
return 1.0 if format_match else 0.0
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
def accuracy_reward(predict: str, ground_truth: str) -> float:
|
| 28 |
-
answer = extract_boxed_content(predict)
|
| 29 |
-
try:
|
| 30 |
-
return 1.0 if grade_answer(answer, ground_truth) else 0.0
|
| 31 |
-
except:
|
| 32 |
-
return 0.0
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
def compute_score(predicts: List[str], ground_truths: List[str], format_weight: float = 0.1) -> List[Dict[str, float]]:
|
| 36 |
-
scores = []
|
| 37 |
-
for predict, ground_truth in zip(predicts, ground_truths):
|
| 38 |
-
predict = re.sub(r"\s*(<|>|/)\s*", r"\1", predict) # handle qwen2.5vl-32b format
|
| 39 |
-
format_score = format_reward(predict)
|
| 40 |
-
accuracy_score = accuracy_reward(predict, ground_truth)
|
| 41 |
-
scores.append(
|
| 42 |
-
{
|
| 43 |
-
"overall": (1 - format_weight) * accuracy_score + format_weight * format_score,
|
| 44 |
-
"format": format_score,
|
| 45 |
-
"accuracy": accuracy_score,
|
| 46 |
-
}
|
| 47 |
-
)
|
| 48 |
-
|
| 49 |
-
return scores
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|