Files changed (1) hide show
  1. README.md +257 -1
README.md CHANGED
@@ -4,4 +4,260 @@ language:
4
  base_model:
5
  - Qwen/Qwen2.5-VL-7B-Instruct
6
  pipeline_tag: image-text-to-text
7
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  base_model:
5
  - Qwen/Qwen2.5-VL-7B-Instruct
6
  pipeline_tag: image-text-to-text
7
+ tags:
8
+ - vehme
9
+ - handwritten-mathematics
10
+ - mathematical-reasoning
11
+ - automated-grading
12
+ - error-detection
13
+ - error-localization
14
+ - qwen2.5-vl
15
+ - vision-language-model
16
+ - grpo
17
+ license: apache-2.0
18
+ ---
19
+
20
+ # VEHME: A Vision-Language Model for Evaluating Handwritten Mathematics Expressions
21
+
22
+ **VEHME** is a vision-language model for evaluating open-form handwritten mathematical solutions. Given a **math question**, a **reference solution**, and a **student's handwritten answer**, VEHME assesses whether the student's reasoning is correct and, when incorrect, describes where the error occurs.
23
+
24
+ **[📄 Paper](https://aclanthology.org/2025.emnlp-main.1619/) · [🌐 Project Website](https://vehme.github.io/) · [💻 Code](https://github.com/phuongnt197/VEHME)**
25
+
26
+ ## 🎯 Model Overview
27
+
28
+ VEHME addresses two complementary tasks:
29
+
30
+ - **Error Detection (ED):** Determine whether a handwritten student solution is correct or incorrect.
31
+ - **Error Localization (EL):** Identify and explain the erroneous expression or step in an incorrect solution.
32
+
33
+ Unlike answer-only grading, VEHME is designed for handwritten, multi-step student work containing varied mathematical notation and layouts. The training pipeline combines **supervised fine-tuning (SFT)** with **Group Relative Policy Optimization (GRPO)**. It also introduces an **Expression-Aware Visual Prompting Module (EVPM)** to improve localization of handwritten expressions in challenging layouts.
34
+
35
+ ### Key Features
36
+
37
+ - **Handwritten solution assessment:** Directly evaluates messy handwriting of student mathematical work rather than requiring clean text transcription.
38
+ - **Reasoning-oriented feedback:** Generates an explanation of its assessment together with an explicit correctness label.
39
+ - **Expression-level error localization:** Describes an erroneous step or expression when a mistake is detected.
40
+ - **Specialized training:** Uses distilled reasoning traces and reinforcement-learning rewards for correctness and localization.
41
+ - **Spatial grounding:** The training pipeline includes EVPM for expression-aware visual prompting.
42
+
43
+ ## 🏆 Performance Benchmarks
44
+
45
+ We evaluate **VEHME-Qwen2.5-VL-7B** against eight representative vision-language models, including four proprietary models and four open-source models, on two handwritten mathematics benchmarks: **AIHub** and **FERMAT**.
46
+
47
+ We consider two evaluation tasks:
48
+ - **Error Detection (ED):** Determine whether a student's handwritten mathematical solution is correct.
49
+ - **Error Localization (EL):** Identify the location of errors within an incorrect solution.
50
+
51
+ Performance is measured using **Accuracy (Acc)** and **F1 score (F1)**. All results are reported as percentages (%), with higher values indicating better performance.
52
+
53
+ ### AIHub Benchmark
54
+
55
+ | Model | ED Acc ↑ | ED F1 ↑ | EL Acc ↑ | EL F1 ↑ |
56
+ |---|---:|---:|---:|---:|
57
+ | **Proprietary Models** | | | | |
58
+ | GPT-4o | 73.00 | 48.67 | 62.88 | 61.01 |
59
+ | GPT-4o-mini | 57.15 | 32.97 | 38.98 | 49.18 |
60
+ | Gemini-2.0-Flash | **75.40** | **50.30** | **67.40** | **65.73** |
61
+ | Gemini-2.5-Flash-Preview | 71.01 | 46.91 | 63.00 | 65.68 |
62
+ | **Open-source Models** | | | | |
63
+ | Phi-4-multimodal-instruct | 38.57 | 29.39 | 35.93 | 21.33 |
64
+ | Qwen2.5-VL-7B-Instruct | 46.68 | 31.48 | 38.00 | 33.75 |
65
+ | Pixtral-12B | 52.67 | 31.69 | 32.20 | 38.35 |
66
+ | Llama-3.2-11B-Vision-Instruct | 19.49 | 18.58 | 44.78 | 5.62 |
67
+ | **VEHME-Qwen2.5-VL-7B (Ours)** | **73.01** | **49.22** | **61.13** | **58.18** |
68
+
69
+ ### FERMAT Benchmark
70
+
71
+ | Model | ED Acc ↑ | ED F1 ↑ | EL Acc ↑ | EL F1 ↑ |
72
+ |---|---:|---:|---:|---:|
73
+ | **Proprietary Models** | | | | |
74
+ | GPT-4o | 66.62 | **58.57** | 55.04 | 66.07 |
75
+ | GPT-4o-mini | **81.75** | 56.62 | 47.18 | 62.61 |
76
+ | Gemini-2.0-Flash | 75.22 | 43.13 | **64.24** | **75.13** |
77
+ | Gemini-2.5-Flash-Preview | 80.12 | 45.68 | 63.35 | 74.72 |
78
+ | **Open-source Models** | | | | |
79
+ | Phi-4-multimodal-instruct | 36.20 | 22.33 | 16.91 | 15.15 |
80
+ | Qwen2.5-VL-7B-Instruct | 44.81 | 26.04 | 24.33 | 32.18 |
81
+ | Pixtral-12B | 41.39 | 25.56 | 10.53 | 3.52 |
82
+ | Llama-3.2-11B-Vision-Instruct | 32.49 | 22.15 | 21.07 | 22.67 |
83
+ | **VEHME-Qwen2.5-VL-7B (Ours)** | **62.61** | **29.81** | **31.90** | **44.36** |
84
+
85
+ ### Key Findings
86
+
87
+ - **Best open-source performance:** VEHME outperforms all evaluated open-source baselines across both datasets and both tasks, on Accuracy and F1.
88
+ - **Substantial improvement over the base model:** On AIHub, VEHME improves Error Detection accuracy from 46.68% to 73.01% (+26.33 percentage points) and Error Localization accuracy from 38.00% to 61.13% (+23.13 percentage points).
89
+ - **Competitive with proprietary models on AIHub:** VEHME achieves 73.01% Error Detection accuracy, comparable to GPT-4o (73.00%) and close to Gemini-2.0-Flash (75.40%).
90
+ - **Generalization to FERMAT:** VEHME achieves 62.61% Error Detection accuracy and 31.90% Error Localization accuracy on FERMAT, exceeding all evaluated open-source baselines, although proprietary models retain stronger performance.
91
+
92
+ ## 🔍 Expected Inputs and Output
93
+
94
+ **Inputs**
95
+
96
+ 1. An image of the mathematics question.
97
+ 2. A reference answer (text).
98
+ 3. An image of the student's handwritten solution.
99
+
100
+ **Output format**
101
+
102
+ ```xml
103
+ <think>
104
+ Explanation of the student's reasoning and whether an error is present.
105
+ </think>
106
+ <correctness>
107
+ Incorrect
108
+ </correctness>
109
+ <localization>
110
+ Description of the incorrect mathematical expression or step.
111
+ </localization>
112
+ ```
113
+
114
+ For a correct solution, the `<correctness>` field should contain `Correct`, and the `<localization>` field should contain `None`.
115
+
116
+ ## 🚀 Getting Started
117
+
118
+ ### Installation
119
+
120
+ ```bash
121
+ pip install -U transformers accelerate torch pillow qwen-vl-utils
122
+ ```
123
+
124
+ ### Example Inference (Transformers)
125
+
126
+
127
+ ```python
128
+ import torch
129
+ from transformers import AutoProcessor, Qwen2_5_VLForConditionalGeneration
130
+ from qwen_vl_utils import process_vision_info
131
+
132
+ MODEL_ID = "phuongnt/VEHME"
133
+
134
+ model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
135
+ MODEL_ID,
136
+ torch_dtype="auto",
137
+ device_map="auto",
138
+ )
139
+ processor = AutoProcessor.from_pretrained(MODEL_ID)
140
+
141
+ prompt = """The following contains a math problem consisting of both a Question
142
+ and a Student Answer. Analyze the Student Answer to determine whether
143
+ there is any error. Explain your assessment, then follow this exact format:
144
+ <think>
145
+ Detailed reasoning explaining whether and where an error occurs.
146
+ </think>
147
+ <correctness>
148
+ Correct or Incorrect
149
+ </correctness>
150
+ <localization>
151
+ Identify the erroneous expression or step; write None if there is no error.
152
+ </localization>
153
+
154
+ Question: [first image]
155
+ Reference answer: The correct solution is ...
156
+ Student answer: [second image]"""
157
+
158
+ messages = [
159
+ {
160
+ "role": "user",
161
+ "content": [
162
+ {"type": "image", "image": "file:///path/to/question.png"},
163
+ {"type": "image", "image": "file:///path/to/student_solution.png"},
164
+ {"type": "text", "text": prompt},
165
+ ],
166
+ }
167
+ ]
168
+
169
+ text = processor.apply_chat_template(
170
+ messages, tokenize=False, add_generation_prompt=True
171
+ )
172
+ image_inputs, video_inputs = process_vision_info(messages)
173
+ inputs = processor(
174
+ text=[text], images=image_inputs, videos=video_inputs,
175
+ padding=True, return_tensors="pt"
176
+ ).to(model.device)
177
+
178
+ with torch.inference_mode():
179
+ output_ids = model.generate(**inputs, max_new_tokens=1024)
180
+
181
+ output_ids = output_ids[:, inputs.input_ids.shape[1]:]
182
+ print(processor.batch_decode(output_ids, skip_special_tokens=True)[0])
183
+ ```
184
+
185
+ **Note:** For exact reproduction of the paper, use the provided [inference scripts](https://github.com/phuongnt197/VEHME#inference), including the published prompt format and image processing.
186
+
187
+ ## 📊 Training Details
188
+
189
+ ### Base Model
190
+
191
+ VEHME is built on [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct), a 7-billion-parameter vision-language model.
192
+
193
+ ### Training Pipeline
194
+
195
+ The paper describes a two-stage training process:
196
+
197
+ 1. **Supervised fine-tuning:** Structured reasoning and grading examples are distilled from **[QwQ-32B](https://huggingface.co/Qwen/QwQ-32B-AWQ)** to teach the model the target response format and error analysis behavior.
198
+ 2. **Reinforcement learning (GRPO):** A composite reward encourages mathematical correctness, useful error localization, response formatting, and reasoning quality.
199
+
200
+ The full pipeline also uses **EVPM**, a YOLO-based module trained on synthesized multi-line handwritten mathematical expressions to predict expression bounding boxes. More information can be found in our [paper](https://aclanthology.org/2025.emnlp-main.1619/).
201
+
202
+ ### Training Data
203
+
204
+ - **[AIHub handwritten mathematics dataset](https://aihub.or.kr/aihubdata/data/view.do?currMenu=&topMenu=&aihubDataSe=data&dataSetSn=71716):** Handwritten mathematics problems and student responses.
205
+ - **[FERMAT](https://github.com/AI4Bharat/FERMAT):** A handwritten mathematical reasoning/error-analysis dataset.
206
+ - **Synthetic reasoning data:** Distilled QwQ-32B analyses used during supervised fine-tuning.
207
+ - **Synthetic expression canvases:** Used to train EVPM.
208
+
209
+ Public redistribution of the underlying AIHub dataset are not possible due to the provider's terms and geographic restrictions.
210
+
211
+ ### Training Configuration
212
+
213
+ | Setting | Value |
214
+ |---|---|
215
+ | Fine-tuning | LoRA on MLP layers |
216
+ | LoRA rank / alpha | 8 / 32 |
217
+ | Optimizer | AdamW |
218
+ | Learning rate | 5e-5 |
219
+ | Scheduler | Cosine decay |
220
+ | Warmup ratio | 0.05 |
221
+ | Global batch size | 192 |
222
+ | Weight decay | 0.1 |
223
+ | Training epochs | 1 |
224
+ | Training compute | Approximately 6 NVIDIA A100 GPU-days |
225
+ | Training framework | ms-swift |
226
+ | Inference framework | vLLM |
227
+
228
+ ## 🔗 Resources
229
+
230
+ - 📄 **Paper:** https://aclanthology.org/2025.emnlp-main.1619/
231
+ - 🌐 **Project website:** https://vehme.github.io/
232
+ - 💻 **Official GitHub repository:** https://github.com/phuongnt197/VEHME
233
+ - **Base model:** https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct
234
+ - **AIHub dataset:** https://aihub.or.kr/aihubdata/data/view.do?currMenu=&topMenu=&aihubDataSe=data&dataSetSn=71716
235
+ - **FERMAT dataset:** https://github.com/AI4Bharat/FERMAT
236
+ - 📧 **Contact:** [phuongnt@unist.ac.kr](phuongnt@unist.ac.kr) and [ducnm@postech.ac.kr](ducnm@postech.ac.kr)
237
+
238
+ ## 📜 License
239
+
240
+ This model is released under the Apache 2.0 License, consistent with the base [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct) model.
241
+
242
+ The model was trained using the 수학 과목 자동 풀이 데이터 dataset provided by [AIHub](https://aihub.or.kr). AIHub permits commercial and non-commercial use and distribution of trained models, subject to its applicable terms and source attribution requirements. The original AIHub dataset is not redistributed with VEHME.
243
+
244
+ ## 📝 Citation
245
+
246
+ If VEHME is useful for your research, please cite:
247
+
248
+ ```bibtex
249
+ @inproceedings{nguyen-etal-2025-vehme,
250
+ title = "{VEHME}: A Vision-Language Model For Evaluating Handwritten Mathematics Expressions",
251
+ author = "Nguyen, Thu Phuong and Nguyen, Duc M. and Jeon, Hyotaek and Lee, Hyunwook and Song, Hyunmin and Ko, Sungahn and Kim, Taehwan",
252
+ booktitle = "Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing",
253
+ year = "2025",
254
+ publisher = "Association for Computational Linguistics",
255
+ url = "https://aclanthology.org/2025.emnlp-main.1619/"
256
+ }
257
+ ```
258
+
259
+ ## 🙏 Acknowledgments
260
+
261
+ This work was conducted by researchers at **Ulsan National Institute of Science and Technology (UNIST)** and **Pohang University of Science and Technology (POSTECH)**. The paper acknowledges support from Korean NRF and IITP programs, and the use of data provided by the AIHub Open AI Dataset Project. See the publication for complete grant information.
262
+
263
+ This model is built upon Qwen2.5-VL-7B-Instruct by Alibaba Cloud. We thank the Qwen team for their excellent foundation model.