Spaces:
Sleeping
Sleeping
Update examples with real evaluation dataset questions
Browse files
app.py
CHANGED
|
@@ -57,13 +57,44 @@ def solve_math_problem(question, max_length=512, temperature=0.7, top_p=0.9):
|
|
| 57 |
# 解码输出
|
| 58 |
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 59 |
|
| 60 |
-
#
|
|
|
|
| 61 |
if "答案:" in generated_text:
|
| 62 |
answer = generated_text.split("答案:", 1)[1].strip()
|
| 63 |
else:
|
| 64 |
-
answer = generated_text
|
| 65 |
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
# 创建 Gradio 界面
|
|
@@ -116,9 +147,9 @@ demo = gr.Interface(
|
|
| 116 |
- 模型作者:zhman
|
| 117 |
""",
|
| 118 |
examples=[
|
| 119 |
-
["
|
| 120 |
-
["
|
| 121 |
-
["
|
| 122 |
],
|
| 123 |
cache_examples=False, # 禁用示例缓存,避免启动时卡住
|
| 124 |
theme=gr.themes.Soft()
|
|
|
|
| 57 |
# 解码输出
|
| 58 |
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 59 |
|
| 60 |
+
# 清理和提取答案
|
| 61 |
+
# 1. 移除输入的问题部分
|
| 62 |
if "答案:" in generated_text:
|
| 63 |
answer = generated_text.split("答案:", 1)[1].strip()
|
| 64 |
else:
|
| 65 |
+
answer = generated_text.replace(prompt, "").strip()
|
| 66 |
|
| 67 |
+
# 2. 清理训练格式文本
|
| 68 |
+
# 移除包含这些关键词的行(训练数据格式)
|
| 69 |
+
cleanup_keywords = [
|
| 70 |
+
"运算符", "运算方法", "运算公式", "运算步骤",
|
| 71 |
+
"左值", "右值", "中值", "结果值",
|
| 72 |
+
"Step", "步骤编号",
|
| 73 |
+
]
|
| 74 |
+
|
| 75 |
+
# 分行处理
|
| 76 |
+
lines = answer.split('\n')
|
| 77 |
+
cleaned_lines = []
|
| 78 |
+
|
| 79 |
+
for line in lines:
|
| 80 |
+
line = line.strip()
|
| 81 |
+
# 跳过空行
|
| 82 |
+
if not line:
|
| 83 |
+
continue
|
| 84 |
+
# 跳过包含训练格式关键词的行
|
| 85 |
+
if any(keyword in line for keyword in cleanup_keywords):
|
| 86 |
+
continue
|
| 87 |
+
# 保留这一行
|
| 88 |
+
cleaned_lines.append(line)
|
| 89 |
+
|
| 90 |
+
# 合并清理后的行,最多保留前 3 行
|
| 91 |
+
if cleaned_lines:
|
| 92 |
+
final_answer = '\n'.join(cleaned_lines[:3])
|
| 93 |
+
else:
|
| 94 |
+
# 如果全部被清理,返回原始答案的前 200 字符
|
| 95 |
+
final_answer = answer[:200]
|
| 96 |
+
|
| 97 |
+
return final_answer
|
| 98 |
|
| 99 |
|
| 100 |
# 创建 Gradio 界面
|
|
|
|
| 147 |
- 模型作者:zhman
|
| 148 |
""",
|
| 149 |
examples=[
|
| 150 |
+
["Find the positive integer $n$ such that $10^n$ cubic centimeters is the same as 1 cubic kilometer.", 256, 0.7, 0.9],
|
| 151 |
+
["Define an operation $\\Diamond$ as $ a \\Diamond b = 12a - 10b.$ Compute the value of $((((20 \\Diamond 22) \\Diamond 22) \\Diamond 22) \\Diamond22).$", 256, 0.7, 0.9],
|
| 152 |
+
["S1.1 Let $a, b, c$ and $d$ be the distinct roots of the equation $x^{4}-15 x^{2}+56=0$. If $R=a^{2}+b^{2}+c^{2}+d^{2}$, find the value of $R$.", 256, 0.7, 0.9]
|
| 153 |
],
|
| 154 |
cache_examples=False, # 禁用示例缓存,避免启动时卡住
|
| 155 |
theme=gr.themes.Soft()
|