How hammad-asif/tenderml works
1. Repository purpose
- This repo is an NLP extraction pipeline for German construction tender PDFs. Its job is to classify text segments, then extract structured fields from them in near real time.
- The codebase is centered on two phases: offline model preparation and online inference/extraction.
2. Core runtime boundary
- The main runtime path appears to start in main.py and use the reusable logic in model.py, tokenizer.py, tree.py, and DFS.py.
- The runtime consumes already-extracted PDF text or text lines, not raw PDFs directly; PDF parsing is likely upstream of this repo.
3. Text normalization and tokenization
- tokenizer.py is the preprocessing boundary for German text.
- Its role is to normalize raw text into model-ready tokens/features so the classifier and downstream extractors see consistent input across documents with different layouts.
4. Machine learning model layer
- model.py is the main ML abstraction layer.
- The persisted artifacts in models/ show the system uses trained classifiers and feature encoders: SVM.pk, SGDWarm89.7.pk, crf.pk, vectorizer.pk, and vectorizerModel.pk.
- This suggests a two-step approach: vectorization / feature extraction followed by classical ML classification, with a CRF-style sequence model likely used for structured label extraction.
5. Training and artifact generation
- createCSV.py and make_sequence_of_bullet.py look like offline preparation scripts for turning document text into training-ready tabular or sequence-labeled data.
- test.py likely evaluates model performance and validates extraction quality.
- The readme indicates a semi-supervised training approach and a dataset of 1000+ German documents, so the offline path is where labeling, feature engineering, and model fitting happen before artifacts are serialized.
6. Structured extraction via tree representation
- tree.py is the main hierarchical data structure used after classification.
- The tree represents document content in a structured way so that generic and context-aware data can be organized before final field extraction.
7. Traversal and field discovery
- DFS.py provides depth-first traversal over that tree.
- This is the main search mechanism for locating target values in the tree after classification and filtering, especially when relevant information may appear at varying positions in different tender layouts.
8. Additional tree/filter logic
- Tree_Extra_Code.py likely contains supporting logic for tree construction, cleanup, filtering, or correction of extracted nodes.
- Combined with DFS, this forms the post-classification refinement stage that turns noisy document text into structured output.
9. Data flow across the system
- The practical flow is: document text → tokenization/vectorization → ML classification → tree construction → DFS/filtering → extracted fields.
- The key architectural boundary is between statistical classification and rule/structure-based extraction; the first identifies what kind of content a text span is, and the second resolves where the final fields are.
10. Deployment and operational context
- The readme says the solution was deployed with FastAPI on a Ray cluster running on AWS EC2, with autoscaling for workload variability.
- That deployment layer is not visible in the file tree, so this repo appears to contain the core extraction engine rather than the full service wrapper.
11. What to show in an architecture diagram
- Show external inputs as German tender PDFs or their extracted text.
- Show a preprocessing/tokenization stage, a model inference stage backed by serialized artifacts in models/, a tree-based extraction stage, and a final structured output.
- Mark the offline training/artifact generation scripts as a separate lane from the live inference path.
Main entry points: model.py Model layer · test.py Train and eval · main.py Main flow · tokenizer.py Tokenizer
Components 16
Online inference
Live extraction path for already-parsed German tender text.
- Tender text · German tender PDFs after upstream text extraction or line splitting.
- Main flow · Coordinates the end-to-end inference pipeline.
main.py - Tokenizer · Normalizes tender text into model-ready tokens and features.
tokenizer.py - Model layer · Loads artifacts and runs classification / sequence prediction.
model.py - Tree model · Represents classified document content in a hierarchical form.
tree.py - DFS search · Traverses the tree to locate target fields and values.
DFS.py - Tree cleanup · Supporting logic for tree construction, filtering, and correction.
Tree_Extra_Code.py - Structured output · Final extracted tender fields and normalized records.
Offline training
Model preparation and artifact generation pipeline.
- CSV prep · Builds training-ready tabular data from document text.
createCSV.py - Sequence builder · Creates sequence-labeled examples for training.
make_sequence_of_bullet.py - Train and eval · Runs model fitting and quality checks on prepared data.
test.py
Model artifacts
Serialized classifiers and feature encoders loaded at runtime.
- SVM · Serialized classical classifier used during inference.
models/SVM.pk - SGD model · Serialized warm-start linear classifier artifact.
models/SGDWarm89.7.pk - CRF · Serialized sequence model for structured label extraction.
models/crf.pk - Vectorizer · Feature encoder used to transform text into model inputs.
models/vectorizer.pk - Vectorizer model · Additional persisted vectorization or embedding artifact.
models/vectorizerModel.pk
Connections 19
- Tender text → Main flow: feeds · Already extracted document text enters the runtime.
- Main flow → Tokenizer: normalizes · Main flow sends text into preprocessing.
- Tokenizer → Model layer: features · Normalized tokens are converted into model inputs.
- Model layer → SVM: loads · Runtime classifier artifact.
- Model layer → SGD model: loads · Alternative linear classifier artifact.
- Model layer → CRF: loads · Sequence labeling artifact.
- Model layer → Vectorizer: uses · Feature encoding artifact.
- Model layer → Vectorizer model: uses · Additional vectorization artifact.
- Model layer → Tree model: builds · Predictions are organized into a hierarchical document tree.
- Tree model → Tree cleanup: refines · Tree is cleaned and corrected before search.
- Tree cleanup → DFS search: prepares · Refined tree is traversed for target discovery.
- DFS search → Structured output: extracts · Traversal resolves final structured fields.
- CSV prep → Train and eval: prepares · Tabular training data flows into offline fitting.
- Sequence builder → Train and eval: prepares · Sequence examples feed training and evaluation.
- Train and eval → SVM: serializes · Offline training produces classifier artifacts.
- Train and eval → SGD model: serializes · Offline training produces classifier artifacts.
- Train and eval → CRF: serializes · Offline training produces sequence artifacts.
- Train and eval → Vectorizer: serializes · Offline training produces feature encoders.
- Train and eval → Vectorizer model: serializes · Offline training produces additional vectorization artifacts.