AsyiraFitri commited on
Commit
ff07fce
·
1 Parent(s): 26033e1

CorrectedTabaccoDatasetwithOCR benchmark

Browse files
README.md CHANGED
@@ -3,9 +3,11 @@
3
  Benchmarks several vision encoder families as **frozen embedding extractors** for document image classification on the [Tobacco-3482](https://huggingface.co/datasets/maveriq/tobacco3482) dataset.
4
 
5
  ---
6
-
7
  ## Dataset
8
 
 
 
 
9
  | Property | Value |
10
  |---|---|
11
  | Dataset | `maveriq/tobacco3482` |
 
3
  Benchmarks several vision encoder families as **frozen embedding extractors** for document image classification on the [Tobacco-3482](https://huggingface.co/datasets/maveriq/tobacco3482) dataset.
4
 
5
  ---
 
6
  ## Dataset
7
 
8
+ ### Corrected Tabacco Dataset with OCR Benchmark
9
+ → [`README_tobacco3482_ocr.md`](tabacco3482_benchmarks/README_tobacco3482_ocr.md)
10
+
11
  | Property | Value |
12
  |---|---|
13
  | Dataset | `maveriq/tobacco3482` |
tabacco3482_benchmarks/README_tobacco3482_ocr.md ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Tobacco-3482 OCR Dataset — Embedding Benchmark Results
2
+
3
+ ## Overview
4
+
5
+ This benchmark evaluates three vision/text embedding models on the **Tobacco-3482 OCR dataset** for document image classification and retrieval. The dataset contains scanned document images across 10 real-world office document categories.
6
+
7
+ - **Gallery (train + val):** 2,458 images
8
+ - **Query (test):** 279 images
9
+ - **Classes:** ADVE, Email, Form, Letter, Memo, News, Note, Report, Resume, Scientific
10
+
11
+ ---
12
+
13
+ ## Dataset Split
14
+
15
+ | Class | Gallery | Test |
16
+ |------------|--------:|-----:|
17
+ | ADVE | 177 | 20 |
18
+ | Email | 508 | 57 |
19
+ | Form | 280 | 32 |
20
+ | Letter | 342 | 38 |
21
+ | Memo | 423 | 48 |
22
+ | News | 166 | 19 |
23
+ | Note | 148 | 17 |
24
+ | Report | 225 | 26 |
25
+ | Resume | 108 | 13 |
26
+ | Scientific | 81 | 9 |
27
+
28
+ ![Class Distribution](figures/ocr_class_distribution.png)
29
+
30
+ ---
31
+
32
+ ## Sample Images per Class
33
+
34
+ ![Sample Images per Class](figures/ocr_class_samples.png)
35
+
36
+ ---
37
+
38
+ ## Benchmark Results
39
+
40
+ | Model | Clf Acc | kNN@1 | kNN@5 | Time |
41
+ |-------------------------------|--------:|-------:|-------:|--------:|
42
+ | SigLIP2 Base (patch16-224) | 85.30% | 78.49% | 77.06% | 262.9s |
43
+ | SigLIP2 Large (patch16-256) | 90.68% | 86.38% | 87.46% | 351.8s |
44
+ | ModernVBERT Embed | **91.76%** | **86.38%** | 86.02% | 2698.2s |
45
+
46
+ - **Best Clf Accuracy:** ModernVBERT Embed (91.76%)
47
+ - **Best kNN@1:** SigLIP2 Large & ModernVBERT Embed (tied at 86.38%)
48
+ - **Best kNN@5:** SigLIP2 Large (87.46%)
49
+
50
+ ### Evaluation Protocol
51
+ - **Clf Accuracy / F1:** Logistic regression classifier trained on gallery embeddings, evaluated on query embeddings.
52
+ - **kNN@1 / kNN@5:** Cosine-similarity nearest-neighbour retrieval; majority-vote label from top-k gallery neighbours.
53
+
54
+ ![Results Bar Chart](figures/ocr_results_bar.png)
55
+
56
+ ---
57
+
58
+ ## Cross-Dataset Comparison (OCR vs. Raw Tobacco-3482)
59
+
60
+ | Model | Dataset | Clf Acc | kNN@1 | kNN@5 |
61
+ |-----------------------------|--------------|--------:|-------:|-------:|
62
+ | SigLIP2 Base (patch16-224) | OCR | 85.30% | 78.49% | 77.06% |
63
+ | | Tobacco-3482 | 82.07% | 74.32% | 74.75% |
64
+ | SigLIP2 Large (patch16-256) | OCR | 90.68% | 86.38% | 87.46% |
65
+ | | Tobacco-3482 | 86.80% | 79.91% | 82.35% |
66
+ | ModernVBERT Embed | OCR | 91.76% | 86.38% | 86.02% |
67
+ | | Tobacco-3482 | 83.79% | 80.06% | 80.20% |
68
+
69
+ > **Key observation:** All models improve on the OCR-processed version of the dataset. ModernVBERT Embed shows the largest OCR gain for Clf Accuracy (+7.97 pp). Per the notebook, ModernVBERT is a **multimodal encoder** (images processed via a visual tokeniser fed into a language-model backbone), so it can directly leverage OCR-readable text content in addition to visual features — explaining why it responds more strongly to text clarity than the vision-only SigLIP models. SigLIP2 Large gains most consistently across all three metrics.
70
+
71
+ ---
72
+
73
+ ## Per-Label Error Analysis (Top-1 kNN)
74
+
75
+ ![Per-Label Error Rate](figures/ocr_error_rate_bar.png)
76
+
77
+ ### Bad-Case Summary
78
+
79
+ #### SigLIP2 Base (patch16-224)
80
+ | Label | Bad / Total | Error | Top Confusion Targets |
81
+ |------------|------------:|-------:|------------------------------------|
82
+ | Report | 12 / 26 | 46.2% ⚠ | Memo ×4, Letter ×4, Email ×3 |
83
+ | ADVE | 7 / 20 | 35.0% ⚠ | News ×6, Report ×1 |
84
+ | Memo | 16 / 48 | 33.3% ⚠ | Letter ×12, Email ×4 |
85
+ | Note | 5 / 17 | 29.4% ⚠ | Report ×2, Email ×2, Memo ×1 |
86
+ | Letter | 11 / 38 | 28.9% ⚠ | Memo ×10, Report ×1 |
87
+ | News | 3 / 19 | 15.8% | Scientific ×2, Note ×1 |
88
+ | Form | 5 / 32 | 15.6% | Memo ×3, Note ×1, Resume ×1 |
89
+ | Resume | 1 / 13 | 7.7% | Report ×1 |
90
+ | Email | 0 / 57 | 0.0% | — |
91
+ | Scientific | 0 / 9 | 0.0% | — |
92
+
93
+ #### SigLIP2 Large (patch16-256)
94
+ | Label | Bad / Total | Error | Top Confusion Targets |
95
+ |------------|------------:|-------:|------------------------------------|
96
+ | Report | 8 / 26 | 30.8% ⚠ | Memo ×3, Letter ×2, Email ×2 |
97
+ | Note | 5 / 17 | 29.4% ⚠ | Email ×3, Report ×2 |
98
+ | Memo | 10 / 48 | 20.8% | Letter ×5, Email ×2, Report ×2 |
99
+ | Form | 5 / 32 | 15.6% | Report ×3, Letter ×1, Resume ×1 |
100
+ | Letter | 5 / 38 | 13.2% | Memo ×3, Report ×2 |
101
+ | News | 2 / 19 | 10.5% | Email ×1, Scientific ×1 |
102
+ | ADVE | 2 / 20 | 10.0% | News ×2 |
103
+ | Resume | 1 / 13 | 7.7% | Report ×1 |
104
+ | Email | 0 / 57 | 0.0% | — |
105
+ | Scientific | 0 / 9 | 0.0% | — |
106
+
107
+ #### ModernVBERT Embed
108
+ | Label | Bad / Total | Error | Top Confusion Targets |
109
+ |------------|------------:|-------:|------------------------------------|
110
+ | Report | 14 / 26 | 57.7% ‼ | Letter ×4, Form ×3, News ×3 |
111
+ | Memo | 8 / 48 | 16.7% | Letter ×6, Email ×1, Form ×1 |
112
+ | Form | 5 / 32 | 15.6% | Letter ×2, Note ×2, Memo ×1 |
113
+ | Note | 2 / 17 | 11.8% | Email ×1, Letter ×1 |
114
+ | News | 2 / 19 | 10.5% | Memo ×1, ADVE ×1 |
115
+ | Letter | 3 / 38 | 7.9% | Memo ×3 |
116
+ | ADVE | 1 / 20 | 5.0% | News ×1 |
117
+ | Email | 2 / 57 | 3.5% | Letter ×2 |
118
+ | Resume | 0 / 13 | 0.0% | — |
119
+ | Scientific | 0 / 9 | 0.0% | — |
120
+
121
+ > **Notable:** ModernVBERT Embed achieves the highest overall accuracy but has a severe **Report** error rate (14/26, 57.7%). ModernVBERT processes images through a visual tokeniser into a language-model backbone — the embedding for each image is mean-pooled over image token positions. For Report documents, which vary widely in layout and textual content, this approach appears to produce embeddings that overlap with Letter, Form, News, Memo, Note, and Scientific — a potential blind spot where visual layout cues matter more than token-level semantics.
122
+
123
+ ---
124
+
125
+ ## Confusion Heatmaps
126
+
127
+ ### SigLIP2 Base (patch16-224)
128
+ ![Confusion Matrix — SigLIP2 Base](figures/ocr_confusion_SigLIP2_Base__OCR.png)
129
+
130
+ ### SigLIP2 Large (patch16-256)
131
+ ![Confusion Matrix — SigLIP2 Large](figures/ocr_confusion_SigLIP2_Large__OCR.png)
132
+
133
+ ### ModernVBERT Embed
134
+ ![Confusion Matrix — ModernVBERT Embed](figures/ocr_confusion_ModernVBERT_Embed__OCR.png)
135
+
136
+ ---
137
+
138
+ ## t-SNE Embeddings
139
+
140
+ t-SNE projects the high-dimensional test query embeddings down to 2D for visual inspection of how well each model separates the 10 classes in embedding space. Tight, well-separated clusters indicate the model has learned discriminative representations; overlapping clusters explain where retrieval errors come from.
141
+
142
+ ### SigLIP2 Base (patch16-224)
143
+ ![t-SNE — SigLIP2 Base](figures/ocr_tsne_SigLIP2_Base__OCR.png)
144
+
145
+ The embedding space shows partial structure but with significant mixing in the centre. Email and ADVE/News form loosely separated peripheral clusters, consistent with their low error rates. However, Letter, Memo, Report, and Note points are heavily interleaved in the central region — directly explaining the high mutual confusion between these classes. Resume and Scientific are relatively isolated, matching their near-zero error rates.
146
+
147
+ ### SigLIP2 Large (patch16-256)
148
+ ![t-SNE — SigLIP2 Large](figures/ocr_tsne_SigLIP2_Large__OCR.png)
149
+
150
+ The larger model shows noticeably tighter and more separated clusters overall. Email forms a distinct dense cluster, and Scientific and Resume are cleanly isolated. Letter and Memo still overlap substantially, consistent with their remaining confusion, but the Report scatter is more contained compared to Base. The improved separation correlates directly with the jump in kNN@1 from 78.49% to 86.38%.
151
+
152
+ ### ModernVBERT Embed
153
+ ![t-SNE — ModernVBERT Embed](figures/ocr_tsne_ModernVBERT_Embed__OCR.png)
154
+
155
+ ModernVBERT shows a distinctly different embedding geometry. Email is tightly clustered and well-separated at the bottom, and Resume/Scientific form clean isolated groups — consistent with their 0% error rates. However, Report points (grey) are scattered broadly across the plot with no coherent cluster, mixing into Letter, Form, Memo, and News regions. This directly visualises why Report has a 57.7% retrieval error rate: the model has not learned a stable representation for this class, likely because Report documents span highly varied layouts and content that the image-token mean-pool does not capture consistently.
156
+
157
+ ---
158
+
159
+ ## Key Takeaways
160
+
161
+ 1. **OCR pre-processing consistently helps** — all three models score higher on the OCR split vs. raw Tobacco-3482.
162
+ 2. **SigLIP2 Large** is the most balanced model: best kNN@5 (87.46%), strong Clf Acc, and competitive speed vs. ModernVBERT.
163
+ 3. **ModernVBERT Embed** edges out on overall Clf Acc (91.76%) but is ~7.7× slower and struggles severely with **Report** retrieval (57.7% error). Unlike SigLIP, ModernVBERT uses a visual tokeniser feeding into a language-model backbone — per the notebook, the benchmark embeds image tokens only (no OCR text input), so the embedding depends entirely on patch-level visual token representations.
164
+ 4. **Persistent hard classes:** Report, Memo, and Letter confuse each other across all models, reflecting genuine visual and textual overlap in the dataset.
165
+ 5. **Easy classes:** Email, Scientific, and Resume are reliably classified by all models.
166
+
167
+ ---
168
+
169
+ Checkpointed results are saved to `results/results_checkpoint_tobacco3482ocr.json` after each model completes — safe to re-run after a crash.
170
+ Figures are saved to `figures/`.
tabacco3482_benchmarks/embeddings/test_emb_ModernVBERT_Embed_OCR.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:27f34fab425907c3d9fd04e4157c4fdad70c1fc091cc8c1ea8dd238547ce704b
3
+ size 857216
tabacco3482_benchmarks/embeddings/test_emb_SigLIP2_Base_patch16-224_OCR.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:107a005e2d7de90759c33b266408e5e05c70afc53283cc3ee0e4570bdab513d5
3
+ size 857216
tabacco3482_benchmarks/embeddings/test_emb_SigLIP2_Large_patch16-256_OCR.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:263b5b80fb2007f3f3e26bb1067bf93989876ce3696c16cf463a0465d397b084
3
+ size 1142912
tabacco3482_benchmarks/embeddings/train_emb_ModernVBERT_Embed_OCR.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b3b4ae6b25e4734a628719b647513b76ea7761fa22af5450282ffc926d4a3662
3
+ size 7551104
tabacco3482_benchmarks/embeddings/train_emb_SigLIP2_Base_patch16-224_OCR.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0d7d830cb3620853e325cf3b2e868fd3de86497a179e11aeb193bd74599d0798
3
+ size 7551104
tabacco3482_benchmarks/embeddings/train_emb_SigLIP2_Large_patch16-256_OCR.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4f37bb9e72327ab21238758885dfd70c618729b751269ad1caec46ca8b2cb7a7
3
+ size 10068096
tabacco3482_benchmarks/figures/ocr_class_distribution.png ADDED

Git LFS Details

  • SHA256: 78dfd2dd20cbd15f18a1b0da2866855b5ada8da9ad29f011fa926bf3cd4be1fc
  • Pointer size: 130 Bytes
  • Size of remote file: 69.9 kB
tabacco3482_benchmarks/figures/ocr_class_samples.png ADDED

Git LFS Details

  • SHA256: 288f46ae97858b371b3c662270ffea1dea206c43b383bb8cd132059efc345edb
  • Pointer size: 131 Bytes
  • Size of remote file: 779 kB
tabacco3482_benchmarks/figures/ocr_confusion_ModernVBERT_Embed__OCR.png ADDED

Git LFS Details

  • SHA256: 245bce8e6dfba417b8e3dfb64d2cf70814371fb238b45df35f4d6005041ec5ce
  • Pointer size: 130 Bytes
  • Size of remote file: 71.4 kB
tabacco3482_benchmarks/figures/ocr_confusion_SigLIP2_Base__OCR.png ADDED

Git LFS Details

  • SHA256: da9e59fe0b6ad9dd7403c3b4e5405c6c3df738e90acc7b5c78644b51ee622cee
  • Pointer size: 130 Bytes
  • Size of remote file: 72 kB
tabacco3482_benchmarks/figures/ocr_confusion_SigLIP2_Large__OCR.png ADDED

Git LFS Details

  • SHA256: fa39984e9c091d17d34d8c9d300a9c7c0626fefef180c8dccf54712578f89042
  • Pointer size: 130 Bytes
  • Size of remote file: 72.6 kB
tabacco3482_benchmarks/figures/ocr_error_rate_bar.png ADDED

Git LFS Details

  • SHA256: e44f7515665ca9b8b4ef6696caa027b535319395e6d602c37449d7e2b5a36624
  • Pointer size: 130 Bytes
  • Size of remote file: 91.1 kB
tabacco3482_benchmarks/figures/ocr_results_bar.png ADDED

Git LFS Details

  • SHA256: 333f02e565f8577054e39a7283c574e16637927f0b009f8fda8f99fe2d3b1b2a
  • Pointer size: 130 Bytes
  • Size of remote file: 56.3 kB
tabacco3482_benchmarks/figures/ocr_tsne_ModernVBERT_Embed__OCR.png ADDED

Git LFS Details

  • SHA256: 11d2d0aed813d894168189b0b4c8ad031eda593027dcd0d001dd683eba00fd19
  • Pointer size: 130 Bytes
  • Size of remote file: 88.2 kB
tabacco3482_benchmarks/figures/ocr_tsne_SigLIP2_Base__OCR.png ADDED

Git LFS Details

  • SHA256: 097a4d729f9412a33d04a5e6cd0075b015a79f5574d2cbb99616b1b1dec4d3c4
  • Pointer size: 130 Bytes
  • Size of remote file: 93.7 kB
tabacco3482_benchmarks/figures/ocr_tsne_SigLIP2_Large__OCR.png ADDED

Git LFS Details

  • SHA256: 700ed637e8e62fc5ae59d56a7ea0089a48e8302e69ea55f010b9ed0922b49fd3
  • Pointer size: 130 Bytes
  • Size of remote file: 90.6 kB
tabacco3482_benchmarks/results/results_checkpoint_tobacco3482ocr.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "SigLIP2 Base (patch16-224) \u2014 OCR": {
3
+ "family": "siglip",
4
+ "model_id": "google/siglip2-base-patch16-224",
5
+ "clf_acc": 0.8530465949820788,
6
+ "f1": 0.850913760997383,
7
+ "knn1": 0.7849462365591398,
8
+ "knn5": 0.7706093189964157,
9
+ "time": 262.86674404144287,
10
+ "postprocess": "none",
11
+ "embed_dim": 768,
12
+ "compressed_dim": null,
13
+ "num_params_M": 375.2,
14
+ "batch_size": 64
15
+ },
16
+ "SigLIP2 Large (patch16-256) \u2014 OCR": {
17
+ "family": "siglip",
18
+ "model_id": "google/siglip2-large-patch16-256",
19
+ "clf_acc": 0.9068100358422939,
20
+ "f1": 0.9053795569607039,
21
+ "knn1": 0.8637992831541219,
22
+ "knn5": 0.8745519713261649,
23
+ "time": 351.804461479187,
24
+ "postprocess": "none",
25
+ "embed_dim": 1024,
26
+ "compressed_dim": null,
27
+ "num_params_M": 881.5,
28
+ "batch_size": 32
29
+ },
30
+ "ModernVBERT Embed \u2014 OCR": {
31
+ "family": "modernvbert",
32
+ "model_id": "ModernVBERT/modernvbert-embed",
33
+ "clf_acc": 0.9175627240143369,
34
+ "f1": 0.9163334021627294,
35
+ "knn1": 0.8637992831541219,
36
+ "knn5": 0.8602150537634409,
37
+ "time": 2698.196870326996,
38
+ "postprocess": "none",
39
+ "embed_dim": 768,
40
+ "compressed_dim": null,
41
+ "num_params_M": 252.0,
42
+ "batch_size": 8
43
+ }
44
+ }