Home

Awesome

PdfPig ML.Net Block Classifier v2

Proof of concept of training a simple Region Classifier using PdfPig and ML.NET. The objective is to classify each text block in a pdf document page as either title, text, list, table and image.

AutoML model builder was used. The model was trained on a subset of the PubLayNet dataset. See their license here.

GenerationMicroAccuracyMacroAccuracy
v10.9370.748
v20.9520.801

For v1 model results, see here.

Results

Results are based on PubLayNet's validation dataset, where the page segmentation is known. For real life use, a page segmenter will be needed (see PdfPig's PageSegmenters). The quality of the page segmentation will impact the results.

Metrics for multi-class classification model

MicroAccuracy = 0.9523, a value between 0 and 1, the closer to 1, the better
MacroAccuracy = 0.8009, a value between 0 and 1, the closer to 1, the better
LogLoss = 3.5333, the closer to 0, the better

LogLoss for class 0 (title)         = 4.6289, the closer to 0, the better
LogLoss for class 1 (image)         = 1.849, the closer to 0, the better
LogLoss for class 2 (text)          = 2.5834, the closer to 0, the better
LogLoss for class 3 (list)          = 28.8412, the closer to 0, the better
LogLoss for class 4 (table)         = 2.8326, the closer to 0, the better

F1 Score for class 0 (title)       = 0.9305, a value between 0 and 1, the closer to 1, the better
F1 Score for class 1 (image)       = 0.9412, a value between 0 and 1, the closer to 1, the better
F1 Score for class 2 (text)        = 0.9691, a value between 0 and 1, the closer to 1, the better
F1 Score for class 3 (list)        = 0.2963, a value between 0 and 1, the closer to 1, the better
F1 Score for class 4 (table)       = 0.9611, a value between 0 and 1, the closer to 1, the better

Confusion table

          ||=======================================================
PREDICTED ||     0 |     1 |     2 |     3 |     4 | Total | Recall
TRUTH     ||=======================================================
(title) 0 || 1,848 |     0 |    89 |     1 |     0 | 1,938 | 0.9536
(image) 1 ||     0 |    72 |     3 |     0 |     1 | 76    | 0.9474
(text)  2 ||   185 |     1 | 8,837 |    16 |     9 | 9,048 | 0.9767
(list)  3 ||     1 |     0 |   225 |    52 |     2 | 280   | 0.1857
(table) 4 ||     0 |     4 |    35 |     2 |   654 | 695   | 0.9410
          ||=======================================================
Precision ||0.9086 |0.9351 |0.9617 |0.7324 |0.9820 |

Permutation Feature Importance

PFI works by taking a labeled dataset, choosing a feature, and permuting the values for that feature across all the examples, so that each example now has a random value for the feature and the original values for all other features. The evaluation metric (e.g. micro-accuracy) is then calculated for this modified dataset, and the change in the evaluation metric from the original dataset is computed. The larger the change in the evaluation metric, the more important the feature is to the model. PFI works by performing this permutation analysis across all the features of a model, one after another. - Source

Micro Accuracy

FeatureDescriptionChange in MicroAccuracy95% Confidence in the Mean Change in MicroAccuracy
wordsCountWords count-0.11440.0008237
charsCountCharacters count-0.098490.0009115
linesCountLines count-0.042550.0005726
blockAspectRatioRatio between the block's width and height-0.041590.0005134
bestNormEditDistanceMinimum edit distance between bookmark title and block text-0.040160.0006307
deltaToHeightAverage delta to average page glyph height-0.036890.0003823
pctNumericChars% of numeric characters-0.033750.0005174
pctSymbolicChars% of symbolic characters-0.010350.000358
pctAlphabeticalChars% of alphabetical characters-0.008590.0003075
pctBulletChars% of bullet characters-0.0040710.0002063
pathsCountPaths count-0.0036610.0001184
pctHorPaths% of horizontal paths-0.0034310.0001309
imageAvgProportionAverage area covered by images-0.0016844.68E-05
pctVertPaths% of vertical paths-0.0014488.139E-05
pctOblPaths% of oblique paths-0.00018831.734E-05
imagesCountImages count-9.692E-051.127E-05
pctBezierPaths% of Bezier curve paths6.212E-221.352E-05

Macro Accuracy

FeatureDescriptionChange in MacroAccuracy95% Confidence in the Mean Change in MacroAccuracy
charsCountCharacters count-0.13390.002263
linesCountLines count-0.083780.0009925
deltaToHeightAverage delta to average page glyph height-0.064610.001223
blockAspectRatioRatio between the block's width and height-0.058960.001163
bestNormEditDistanceMinimum edit distance between bookmark title and block text-0.050390.001419
pctNumericChars% of numeric characters-0.04750.001258
pathsCountPaths count-0.02520.000614
wordsCountWords count-0.016510.001655
pctSymbolicChars% of symbolic characters-0.011660.001505
pctHorPaths% of horizontal paths-0.009840.0003186
pctVertPaths% of vertical paths-0.0085580.0002925
pctAlphabeticalChars% of alphabetical characters-0.0068820.0009913
imageAvgProportionAverage area covered by images-0.0061480.0001146
pctBulletChars% of bullet characters-0.0053190.0008375
pctOblPaths% of oblique paths-0.0027476.657E-05
imagesCountImages count-0.002683.903E-05
pctBezierPaths% of Bezier curve paths-4.078E-055.263E-05

TO DO

Features