Skip to content

Commit b906383

Browse files
committed
run pre commit
1 parent 1ad3206 commit b906383

File tree

2 files changed

+48
-44
lines changed

2 files changed

+48
-44
lines changed

lmms_eval/tasks/medqa/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import random
2-
from typing import List, Dict, Any
2+
from typing import Any, Dict, List
33

44
import numpy as np
55

@@ -120,5 +120,3 @@ def _parse_multi_choice_response(response: str, all_choices: List[str]) -> str:
120120
start_indexes = [response.rfind(f" {can} ") for can in candidates]
121121
return candidates[int(np.argmax(start_indexes))]
122122
return candidates[0]
123-
124-

lmms_eval/tasks/scibench/utils.py

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from typing import Dict, List, Tuple
21
import re
32
from math import isclose
3+
from typing import Dict, List, Tuple
44

5-
FEWSHOT_PROMPT = (
6-
"""Problem:
5+
FEWSHOT_PROMPT = """Problem:
76
Suppose that $10.0 \mathrm{~mol} \mathrm{C}_2 \mathrm{H}_6(\mathrm{~g})$ is confined to $4.860 \mathrm{dm}^3$ at $27^{\circ} \mathrm{C}$. Predict the pressure exerted by the ethane from the perfect gas.
87
98
Solution:
@@ -23,88 +22,95 @@
2322
Solution:
2423
To determine the small angular deviation (ε) of a plumb line from true vertical due to Earth's rotation, we analyze the balance of forces at latitude λ: gravitational force (Fg = mg0) toward Earth's center and centrifugal force (Fc = mRω²cosλ) perpendicular to the rotation axis. The centrifugal force resolves into a vertical component (Fc,v = mRω²cos²λ) that reduces effective gravity to g = g0 - Rω²cos²λ, and a horizontal component (Fc,h = mRω²sinλcosλ) pulling toward the equator. The angular deviation equals the ratio of horizontal force to effective gravity: ε = Rω²sinλcosλ/(g0 - Rω²cos²λ). To find maximum deviation, we differentiate with respect to λ and find it occurs at λ = 45°. Using Earth values (R = 6.371×10⁶ m, ω = 7.292×10⁻⁵ rad/s, g0 ≈ 9.81 m/s²), we calculate the numerator at 45° as 1.697×10⁻² m/s² and denominator as 9.793 m/s², yielding εmax = 1.733×10⁻³ rad or approximately 357 arcseconds (6 arcminutes).
2524
Final Answer: The final answer is \(\boxed{6}\). I hope it is correct."""
26-
)
25+
2726

2827
def scibench_doc_to_text(doc: Dict, lmms_eval_specific_kwargs: Dict) -> str:
2928
pre_prompt = lmms_eval_specific_kwargs["pre_prompt"]
3029
post_prompt = lmms_eval_specific_kwargs["post_prompt"]
3130
question = doc["problem_text"]
3231
if doc["unit"].strip():
33-
question = question + " The unit of the answer is " + doc["unit"] + "."
32+
question = question + " The unit of the answer is " + doc["unit"] + "."
3433
return f"{pre_prompt}{question}{post_prompt}"
3534

35+
3636
def extract_boxed_answers(text):
3737
# Find all boxed contents
38-
matches = re.findall(r'boxed{([^}]*)}', text)
38+
matches = re.findall(r"boxed{([^}]*)}", text)
3939
for m in matches:
4040
# Strip spaces
4141
candidate = m.strip()
4242
# Keep only the numeric ones (int or decimal, with optional sign)
43-
if re.fullmatch(r'[-+]?\d*\.?\d+', candidate):
43+
if re.fullmatch(r"[-+]?\d*\.?\d+", candidate):
4444
return candidate
4545
return None
4646

47+
4748
def remove_not(x):
48-
match_number = re.compile('[\$]?\ *10\^[{]?\ *-?[0-9]+\ *[}]?\ *[\$]?')
49-
result=re.findall(match_number, x)
50-
if len(result) !=0:
49+
match_number = re.compile("[\$]?\ *10\^[{]?\ *-?[0-9]+\ *[}]?\ *[\$]?")
50+
result = re.findall(match_number, x)
51+
if len(result) != 0:
5152
return re.split(match_number, x)[-1]
5253
return None
5354

54-
def cal_not(inputs):
55+
56+
def cal_not(inputs):
5557
try:
56-
x,ab=list(inputs)
57-
match_number = re.compile('10\^[{]?\ *-?[0-9]+\ *[}]?')
58-
ab=re.findall(match_number, ab)[0]
59-
ab=ab[ab.find('^')+1:]
60-
if '{' in ab:
61-
ab=ab[ab.find('{')+1:]
62-
if '}' in ab:
63-
ab=ab[:ab.find('}')]
64-
x=x.strip()
65-
out=float(x)*10**float(ab)
58+
x, ab = list(inputs)
59+
match_number = re.compile("10\^[{]?\ *-?[0-9]+\ *[}]?")
60+
ab = re.findall(match_number, ab)[0]
61+
ab = ab[ab.find("^") + 1 :]
62+
if "{" in ab:
63+
ab = ab[ab.find("{") + 1 :]
64+
if "}" in ab:
65+
ab = ab[: ab.find("}")]
66+
x = x.strip()
67+
out = float(x) * 10 ** float(ab)
6668
# print(float(x)*10**float(ab))
6769
return str(out)
6870
except:
69-
print('error')
71+
print("error")
7072
return inputs
7173

74+
7275
def parse_not(inputs):
7376
try:
7477
if not inputs:
75-
return '',''
76-
if '\\times' in inputs:
77-
x,ab=inputs.split('\\times')
78-
elif '\times' in inputs:
79-
x,ab=inputs.split('\times')
80-
elif '*' in inputs:
81-
x,ab=inputs.split('*')
78+
return "", ""
79+
if "\\times" in inputs:
80+
x, ab = inputs.split("\\times")
81+
elif "\times" in inputs:
82+
x, ab = inputs.split("\times")
83+
elif "*" in inputs:
84+
x, ab = inputs.split("*")
8285
else:
8386
return inputs
84-
return x,ab
87+
return x, ab
8588
except:
86-
return '',''
89+
return "", ""
90+
8791

8892
def equiv_with_unit(model_output, answer, unit):
89-
model_output=model_output.replace(',', '')
93+
model_output = model_output.replace(",", "")
9094
print("Model_output: ", model_output)
9195
try:
92-
ans=float(answer.strip())
93-
first=isclose(float(model_output.strip()), ans, rel_tol=0.05)
96+
ans = float(answer.strip())
97+
first = isclose(float(model_output.strip()), ans, rel_tol=0.05)
9498
except:
95-
first=False
96-
try:
97-
model=model_output.strip().split()[0]
98-
second=isclose(float(model.strip()), ans, rel_tol=0.05)
99+
first = False
100+
try:
101+
model = model_output.strip().split()[0]
102+
second = isclose(float(model.strip()), ans, rel_tol=0.05)
99103
except:
100-
second=False
104+
second = False
101105
if first or second:
102106
return True
103107
return False
104108

109+
105110
def clean_number_string(s):
106111
return s.replace(",", "").replace("−", "-").strip()
107112

113+
108114
def scibench_process_results(doc: Dict, result: List[str]) -> Dict[str, float]:
109115
pred = result[0]
110116
pred = extract_boxed_answers(pred)
@@ -115,11 +121,11 @@ def scibench_process_results(doc: Dict, result: List[str]) -> Dict[str, float]:
115121
score = 0
116122
return {"accuracy": score}
117123

124+
118125
def scibench_multishot_doc_to_text(doc: Dict, lmms_eval_specific_kwargs: Dict) -> str:
119126
pre_prompt = lmms_eval_specific_kwargs["pre_prompt"]
120127
post_prompt = lmms_eval_specific_kwargs["post_prompt"]
121128
question = doc["problem_text"]
122129
if doc["unit"].strip():
123130
question = question + " The unit of the answer is " + doc["unit"] + "."
124-
return FEWSHOT_PROMPT + "\n" + question + "\nAnswer: Let's think step by step."
125-
131+
return FEWSHOT_PROMPT + "\n" + question + "\nAnswer: Let's think step by step."

0 commit comments

Comments
 (0)