|
| 1 | +# XGBoost Classification |
| 2 | + |
| 3 | +To train the classification, the development package needs to be installed and MLflow tracking activated. |
| 4 | + |
| 5 | +The dataset used to train the provided model (`models/stable/model.joblib`) is internal and not publicly available. It is stored in a private S3 bucket (`stijnvermeeren-assets-data`) accessible only to the project team. The dataset is composed of 1011 labeled single-page PDF across 9 classes, with ground truth available under `data/gt_single_pages_2026.json`. The distribution of the pages is listed below. |
| 6 | + |
| 7 | +| Class | Number | Percentage | |
| 8 | +|-----------------|-------:|-----------:| |
| 9 | +| boreprofile | 115 | 13.4 | |
| 10 | +| diagram | 106 | 10.5 | |
| 11 | +| geo_profile | 74 | 7.3 | |
| 12 | +| map | 126 | 12.5 | |
| 13 | +| section_header | 93 | 9.2 | |
| 14 | +| table | 60 | 5.9 | |
| 15 | +| text | 202 | 20.0 | |
| 16 | +| title_page | 109 | 10.8 | |
| 17 | +| unknown | 126 | 12.5 | |
| 18 | + |
| 19 | + |
| 20 | +The classification results on the validation set are reported below. |
| 21 | + |
| 22 | +| Class | Precision | Recall | F1-score | |
| 23 | +|-----------------|----------:|-------:|---------:| |
| 24 | +| boreprofile | 96.7 | 87.9 | 92.1 | |
| 25 | +| diagram | 84.6 | 84.6 | 84.6 | |
| 26 | +| geo_profile | 55.6 | 71.4 | 62.5 | |
| 27 | +| map | 63.6 | 80.8 | 71.2 | |
| 28 | +| section_header | 64.7 | 73.3 | 68.8 | |
| 29 | +| table | 90.9 | 83.3 | 87.0 | |
| 30 | +| text | 84.4 | 88.4 | 86.4 | |
| 31 | +| title_page | 95.0 | 95.0 | 95.0 | |
| 32 | +| unknown | 57.9 | 39.3 | 46.8 | |
| 33 | +| Overall (macro) | 77.0 | 78.2 | 77.1 | |
| 34 | + |
| 35 | + |
| 36 | +## Train with your own data |
| 37 | + |
| 38 | +### 1. Prepare the folder structure |
| 39 | + |
| 40 | +Organize your labeled single-page images with one subfolder per class: |
| 41 | + |
| 42 | +``` |
| 43 | +data/single_pages/ |
| 44 | +├── boreprofile/ |
| 45 | +├── diagram/ |
| 46 | +├── geo_profile/ |
| 47 | +├── map/ |
| 48 | +├── section_header/ |
| 49 | +├── table/ |
| 50 | +├── text/ |
| 51 | +├── title_page/ |
| 52 | +└── unknown/ |
| 53 | +``` |
| 54 | + |
| 55 | +### 2. Prepare the ground truth |
| 56 | + |
| 57 | +The ground truth file is a JSON list of labeled documents. Follow the same format as `data/gt_single_pages.json`: |
| 58 | + |
| 59 | +```jsonc |
| 60 | +[ |
| 61 | + { |
| 62 | + "filename": "24911_1.pdf", // file name relative to train / validation folder |
| 63 | + "metadata": { |
| 64 | + "page_count": 1 // total number of pages in the document |
| 65 | + }, |
| 66 | + "pages": [ |
| 67 | + { |
| 68 | + "page": 1, // page number (1-indexed) |
| 69 | + "classification": { // one-hot encoding of the page class |
| 70 | + "text": 0, |
| 71 | + "boreprofile": 0, |
| 72 | + "map": 0, |
| 73 | + "geo_profile": 0, |
| 74 | + "title_page": 1, |
| 75 | + "diagram": 0, |
| 76 | + "table": 0, |
| 77 | + "unknown": 0, |
| 78 | + "section_header": 0 |
| 79 | + } |
| 80 | + } |
| 81 | + ] |
| 82 | + } |
| 83 | +] |
| 84 | +``` |
| 85 | + |
| 86 | +### 3. Split into train and validation sets |
| 87 | + |
| 88 | +Split the dataset using an 80-20% ratio based on filename: |
| 89 | + |
| 90 | +```bash |
| 91 | +python src/scripts/split_data.py \ |
| 92 | + -i data/single_pages \ |
| 93 | + -o data/single_pages_splits \ |
| 94 | + -rv 0.2 \ |
| 95 | + -rt 0.0 |
| 96 | +``` |
| 97 | + |
| 98 | +### 4. Update the config |
| 99 | + |
| 100 | +Edit `config/xgboost_config.yml` to point to your data: |
| 101 | + |
| 102 | +```yaml |
| 103 | +# Path to the training set |
| 104 | +train_folder_path: "data/single_pages_splits/train" |
| 105 | +# Path to the validation set |
| 106 | +val_folder_path: "data/single_pages_splits/validation" |
| 107 | +# Ground truth for model training and validation |
| 108 | +ground_truth_file_path: "data/gt_single_pages.json" |
| 109 | +``` |
| 110 | +
|
| 111 | +### 5. Train the model |
| 112 | +
|
| 113 | +```bash |
| 114 | +python -m src.models.treebased.train \ |
| 115 | + --config-file-path config/xgboost_config.yml \ |
| 116 | + --out-directory models/xgboost_model |
| 117 | +``` |
| 118 | + |
| 119 | +The trained model will be saved under `models/xgboost_model`. For macOS users, if you encounter OpenMP issues, install the library via Homebrew first: |
| 120 | + ```bash |
| 121 | + brew install libomp |
| 122 | +``` |
0 commit comments