Home

Awesome

PdfPig SVM Region Classifier

Proof of concept of a simple Support Vector Machine Region Classifier using PdfPig and Accord.Net. The model was trained on a subset of the PubLayNet dataset. See their license here.

The objective is to classify each text block using machine learning in a pdf document page as either title, text, list, table and image.

The annotions from the dataset (see sample here) were converted to the PAGE xml format. See the PageXmlConverter to convert the json file into PAGE xml files. Images from the dataset were not used. You will need to download the pdf documents separately as we leverage the pdf documents features directly instead.

Labels

Following the PubLayNet methodology, the following categories are available:

Labelid (svm)
title0
text1
list2
table3
image4

Features

Text

Paths

Images

Code

See the GenerateData class to generate a csv file with the features, using the pdf documents, and their respective PageXml ground truth (one xml document per page). See the FeatureHelper class to easily generate the features vector from a block.

Results (in sample)

Accuracy

Model accuracy = 90.898

Normalised confusion matrix

Normalised confusion matrix

Confusion matrix

titletextlisttableimage
title93121592193135
text11663713698882032
list013200
table016410923
image0000154

Precision, Recall and F1 score

PrecisionRecallF1 score
title0.8420.8890.865
text0.9250.9580.941
list0.9700.0310.059
table0.9790.5700.721
image1.0000.4750.644

Code

See the Trainer class to train and evaluate the model. After training, the SVM model will be saved as a Gzip.

Usage

Once the training is finished, you can test the classification on a new pdf document by using either DocstrumBoundingBoxes or RecursiveXYCut to generate the text blocks, and then classify each block. See SvmZoneClassifier for a demo implementation. The SVM trained model is available here.

References