|
| 1 | +# version-cv |
| 2 | + |
| 3 | +* **One Sentence Summary** |
| 4 | + |
| 5 | + This repository symbolic math classification using image-based, text-based, and classical learning models including EfficientNetB0, GPT2, Word2Vec, and XGBoost. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +* **Definition of the tasks / challenge** |
| 12 | + The project explores symbolic reasoning and multimodal classification using visual and textual inputs. A binary classification task was constructed using the Hugging Face version of the MathWriting dataset by shuffling LaTeX ID and image pairings to generate synthetic binary labels (0 or 1). |
| 13 | + |
| 14 | +* **Approach** |
| 15 | + Four models were developed and compared: |
| 16 | + - `EfficientNetB0` for visual symbol classification |
| 17 | + - `GPT2` fine-tuned on LaTeX token sequences |
| 18 | + - `Word2Vec` for symbolic embeddings |
| 19 | + - `XGBoost` applied to Word2Vec vectors |
| 20 | + |
| 21 | +* **Summary of the performance achieved** |
| 22 | + - EfficientNetB0: ~51% accuracy |
| 23 | + - GPT2: ~47% accuracy |
| 24 | + - Word2Vec: ~48% macro F1 score |
| 25 | + - XGBoost: ~49% macro F1 score |
| 26 | + - GPT2 prototype: ~76.1% accuracy, ROC AUC score .832 (83.2%) |
| 27 | + |
| 28 | +--- |
| 29 | + |
| 30 | +## Summary of Workdone |
| 31 | + |
| 32 | +### Data |
| 33 | + |
| 34 | +* **Data:** |
| 35 | + * **Type:** |
| 36 | + - Image: 224×224 LaTeX-rendered symbols (PNG) |
| 37 | + - Text: Tokenized LaTeX expressions |
| 38 | + - Output: Multi-class and binary labels |
| 39 | + * **Size:** |
| 40 | + - ~4,000 total samples (multi-class) |
| 41 | + - ~2,000 binary samples from MathWriting |
| 42 | + * **Split:** |
| 43 | + - Multi-class: 2800 train / 600 test / 600 val |
| 44 | + - Binary: 1600 train / 200 test / 200 val |
| 45 | + |
| 46 | +#### Preprocessing / Clean up |
| 47 | + |
| 48 | +* Image resizing and normalization |
| 49 | +* GPT2 tokenization of LaTeX strings |
| 50 | +* Shuffling LaTeX ID–image pairs to generate 0/1 binary labels |
| 51 | +* Oversampling used for class balancing |
| 52 | + |
| 53 | +#### Data Visualization |
| 54 | + |
| 55 | +* Token length distributions, symbol histograms |
| 56 | +* t-SNE clustering of Word2Vec vectors |
| 57 | +* Confusion matrices and ROC curves for binary task |
| 58 | + |
| 59 | +### Problem Formulation |
| 60 | + |
| 61 | +* **Input / Output:** |
| 62 | + - Input: math symbol image or LaTeX sequence |
| 63 | + - Output: categorical label or binary label |
| 64 | + |
| 65 | +* **Models:** |
| 66 | + - `EfficientNetB0` (image classifier) |
| 67 | + - `GPT2` (LaTeX sequence transformer) |
| 68 | + - `Word2Vec` + `XGBoost` (vectorized + classical) |
| 69 | + |
| 70 | +* **Loss, Optimizer, Hyperparameters:** |
| 71 | + - Loss: Categorical/Binary Crossentropy |
| 72 | + - Optimizers: Adam, AdamW |
| 73 | + - Batch Size: 32, Epochs: 30, Early stopping applied |
| 74 | + |
| 75 | +--- |
| 76 | + |
| 77 | +### Training |
| 78 | + |
| 79 | +* **Software & Hardware:** |
| 80 | + - Python 3.12.11 |
| 81 | + - TensorFlow 2.15, 2.18, and 2.19, HuggingFace Transformers, Gensim, XGBoost |
| 82 | + - Trained on: Dell Precision Workstation 5510, Lambda Cloud compute - NVIDIA RTX A6000, NVIDIA Quadro RTX 6000, NVIDIA GH200 Grace Hopper Superchip, NVIDIA A100 Tensor Core GPU, and NVIDIA A10 Tensor Core GPU |
| 83 | + |
| 84 | +* **Training time:** |
| 85 | + |
| 86 | + - Full training, tuning, and experimentation across all models took a couple of weeks 1-2. |
| 87 | + |
| 88 | +* **Training curves:** |
| 89 | + |
| 90 | + - Models converged within 10–20 epochs |
| 91 | + - Validation monitoring and checkpointing used |
| 92 | + - Binary classifier reached high AUC after 5–8 epochs |
| 93 | + |
| 94 | +* **Challenges:** |
| 95 | + |
| 96 | + - GPT2 token memory and batch size constraints |
| 97 | + - Symbol label imbalance and binary class noise |
| 98 | + - Feature drift during Word2Vec–XGBoost transfer |
| 99 | + - Scoping the work only to what is understood as data science today |
| 100 | + |
| 101 | + |
| 102 | +### Performance Comparison |
| 103 | + |
| 104 | +* **Metrics:** Accuracy, Macro F1, ROC AUC (binary) |
| 105 | + |
| 106 | +| Model | Accuracy | F1 Score (macro) | |
| 107 | +|-----------------------|----------|------------------| |
| 108 | +| EfficientNetB0 | 51% | NaN | |
| 109 | +| GPT2 | 47% | 0.34 | |
| 110 | +| Word2Vec | 48% | 0.32 | |
| 111 | +| XGBoost | 49% | 0.48 | |
| 112 | +| GPT2 Prototype | 76.1% | 0.76 | |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +* **Visualizations:** |
| 117 | +  |
| 118 | +  |
| 119 | +  |
| 120 | + |
| 121 | +--- |
| 122 | + |
| 123 | +### Conclusions |
| 124 | + |
| 125 | +* EfficientNetB0 was optimal for symbolic image classification |
| 126 | +* GPT2 achieved strong results for token sequence inputs |
| 127 | +* MathWriting binary label task showed robust generalization from shuffled samples |
| 128 | +* Word2Vec + XGBoost was lightweight and interpretable |
| 129 | +* GPT2 prototype outperformed all model builds (was not fully built) |
| 130 | + |
| 131 | +--- |
| 132 | + |
| 133 | +### Future Work |
| 134 | + |
| 135 | +* Integrate CROHME-style handwritten data |
| 136 | +* Explore layout-aware ViT + LSTM hybrids |
| 137 | +* Build MathOCR pipeline with MathPix-style parsing |
| 138 | +* Expand symbolic corpora beyond MathWriting |
| 139 | +* Explainable AI (XAI) |
| 140 | +* Secure ML/DL systems |
| 141 | +* Responsible data science |
| 142 | + |
| 143 | +--- |
| 144 | + |
| 145 | +## How to reproduce results |
| 146 | + |
| 147 | +```bash |
| 148 | +git clone https://github.com/rcghpge/version-cv.git |
| 149 | +cd version-cv |
| 150 | +pixi install # Or: pip install -r requirements.txt |
| 151 | +``` |
| 152 | + |
| 153 | +## Launch Jupyter Notebooks |
| 154 | + |
| 155 | +```bash |
| 156 | +jupyter notebook notebooks/ |
| 157 | +``` |
| 158 | + |
| 159 | +Notebook index: |
| 160 | + |
| 161 | + * `basemodel.ipynb`: basel model + EfficientNetB0 backbone model |
| 162 | + * `model2.ipynb`: GPT2 model |
| 163 | + * `model3.ipynb`: Word2Vec training + classical classifier |
| 164 | + * `model4.ipynb`: XGBoost integration |
| 165 | + * `mathwriting.ipynb`: prototyping builds |
| 166 | + * `comparemodels.ipynb`: side-by-side model analysis |
| 167 | + * `prototypes.ipynb`: GPT2 prototype (performed the best) |
| 168 | + |
| 169 | +--- |
| 170 | + |
| 171 | +## Overview of files in repository |
| 172 | + |
| 173 | +```bash |
| 174 | +. |
| 175 | +├── CITATION.cff # Citation metadata |
| 176 | +├── LICENSE # Open-source license |
| 177 | +├── README.md # Main project documentation |
| 178 | +├── assets/ # Diagrams, plots, confusion matrices, LaTeX images |
| 179 | +├── cloud/ # LambdaCloud configs and scripts |
| 180 | +├── data/ # MathWriting, DeepMind MATH, CSAI, and related corpora |
| 181 | +├── docs/ # Academic PDFs and source papers |
| 182 | +├── install_pixi.sh # Environment setup script |
| 183 | +├── logs/ # Training and evaluation logs |
| 184 | +├── models/ # Saved model files (.h5, .keras, .json) |
| 185 | +├── modules/ # DataLoader and utility code |
| 186 | +├── notebooks/ # All core modeling and evaluation notebooks |
| 187 | +├── pixi.lock # Pixi environment lock |
| 188 | +├── pixi.toml # Pixi environment definition |
| 189 | +└── sandbox/ # Experimental code (dev branch) |
| 190 | +``` |
| 191 | + |
| 192 | +--- |
| 193 | + |
| 194 | +## Software Setup |
| 195 | + |
| 196 | +```bash |
| 197 | +# Preferred |
| 198 | +pixi install |
| 199 | + |
| 200 | +# Or use pip |
| 201 | +pip install -r requirements.txt |
| 202 | +``` |
| 203 | + |
| 204 | +Dependencies: |
| 205 | + |
| 206 | + * `tensorflow`==2.15, 2.18, 2.19 |
| 207 | + * `transformers` |
| 208 | + * `gensim` |
| 209 | + * `xgboost` |
| 210 | + * `scikit-learn`, `matplotlib`, `numpy`, `pandas` |
| 211 | + * `pixi` |
| 212 | + * `python` >=3.12.11 |
| 213 | + |
| 214 | +--- |
| 215 | + |
| 216 | +## Data |
| 217 | + |
| 218 | +* Public data: |
| 219 | + * [MathWriting Dataset](https://huggingface.co/datasets/deepcopy/MathWriting-human) |
| 220 | + * DeepMind MATH (local generation) |
| 221 | +* Binary labels generated by shuffling MathWriting LaTeX IDs |
| 222 | + |
| 223 | +Run preprocessing via: |
| 224 | + |
| 225 | +```bash |
| 226 | +jupyter notebook notebooks/<notebooks>.ipynb |
| 227 | +``` |
| 228 | + |
| 229 | +--- |
| 230 | + |
| 231 | +## Training |
| 232 | + |
| 233 | +All model training is notebook-based. Start with: |
| 234 | + |
| 235 | + * basemodel.ipynb for image classification |
| 236 | + * model2.ipynb for text modeling |
| 237 | + * model3.ipynb and model4.ipynb for classical approaches |
| 238 | + * protopes.ipynb for GPT-based designs |
| 239 | + |
| 240 | +## Performance Evaluation |
| 241 | + |
| 242 | +Use: |
| 243 | +```bash |
| 244 | +jupyter notebook notebooks/comparemodels.ipynb |
| 245 | +``` |
| 246 | +To reproduce visualizations, metrics, and ROC plots. |
| 247 | + |
| 248 | +--- |
| 249 | + |
| 250 | +## Citations |
| 251 | + |
| 252 | +Tan & Le (2019). EfficientNet |
| 253 | +Vaswani et al. (2017). Attention Is All You Need |
| 254 | +Mikolov et al. (2013). Word2Vec |
| 255 | +Chen & Guestrin (2016). XGBoost |
| 256 | +Gervais et al. (2025). MathWriting Dataset |
| 257 | +Hendrycks et al. (2021). MATH Dataset |
| 258 | +Cocker, R. (2025). Version-Tab (Version 0.1.0) [Computer software]. https://github.com/rcghpge/version-tab |
| 259 | + |
| 260 | +--- |
0 commit comments