Swanimadhoop/GLiNER

Python

1

9 commits

updated Mar 15, 2026

See the code

README

End-to-end pipeline that takes a visiting card image and outputs structured contact fields:

PaddleOCR  →  GLiNER (spaCy pipeline)  →  Regex post-processing  →  Structured entities

Extracted labels: PERSON, ORGANISATION, DESIGNATION, PHONE NUMBER, ADDRESS, EMAIL, URL

Emails and URLs are handled via regex override (GLiNER misclassifies these on noisy OCR text). Consecutive ADDRESS spans are merged into a single entity.


Files

FilePurpose
PaddleOCR.pyOCR stage — extracts text from card images
sample.pyInference with pretrained medium model (baseline)
visiting_card.pyInference with fine-tuned small model
final.pyProduction script — lower threshold, address consolidation
finetune.pyFine-tuning entry point using GlinerTrainer
train.pyConfig-driven training loop with scheduler + checkpointing
trainer.pyGlinerTrainer class (Accelerate, DDP, WandB support)
Sample_Data.json67 annotated visiting card samples
gliner_sample_data.json260 samples — visiting cards + invoices

Dataset Format

{
  "tokenized_text": ["Jose", "Sebastian", "CTO", "Muthoottu", ...],
  "ner": [
    [0, 1, "PERSON"],
    [2, 2, "DESIGNATION"],
    [3, 3, "ORGANISATION"]
  ]
}

Usage

# Install dependencies
pip install -r requirements.pred.txt       # inference only
pip install -r requirements.train.txt      # training + annotation tools

# Step 1: OCR (edit img_path in PaddleOCR.py first)
python PaddleOCR.py

# Step 2: Run NER
python final.py                            # fine-tuned model (recommended)
python sample.py                           # pretrained medium model (baseline)

# Step 3: Fine-tune on your own data
python finetune.py
# or config-driven:
python train.py --config config.yaml --log_dir ./logs

Example Output

Jose Sebastian E     => PERSON
CTO                  => DESIGNATION
Muthoottu Infotech   => ORGANISATION
65/623 K, Kaloor, Kochi, Kerala - 682 017  => ADDRESS
98468 70514          => PHONE NUMBER
[email protected]  => EMAIL
www.mmsofttech.com   => URL

Stack

GLiNER · spaCy · PaddleOCR · PyTorch · HuggingFace Transformers · Accelerate


Author: Swani Madhoop — CUSAT, AI & DS

Swanimadhoop/GLiNER

Python

1

9 commits

updated Mar 15, 2026

See the code

README

End-to-end pipeline that takes a visiting card image and outputs structured contact fields:

PaddleOCR  →  GLiNER (spaCy pipeline)  →  Regex post-processing  →  Structured entities

Extracted labels: PERSON, ORGANISATION, DESIGNATION, PHONE NUMBER, ADDRESS, EMAIL, URL

Emails and URLs are handled via regex override (GLiNER misclassifies these on noisy OCR text). Consecutive ADDRESS spans are merged into a single entity.


Files

FilePurpose
PaddleOCR.pyOCR stage — extracts text from card images
sample.pyInference with pretrained medium model (baseline)
visiting_card.pyInference with fine-tuned small model
final.pyProduction script — lower threshold, address consolidation
finetune.pyFine-tuning entry point using GlinerTrainer
train.pyConfig-driven training loop with scheduler + checkpointing
trainer.pyGlinerTrainer class (Accelerate, DDP, WandB support)
Sample_Data.json67 annotated visiting card samples
gliner_sample_data.json260 samples — visiting cards + invoices

Dataset Format

{
  "tokenized_text": ["Jose", "Sebastian", "CTO", "Muthoottu", ...],
  "ner": [
    [0, 1, "PERSON"],
    [2, 2, "DESIGNATION"],
    [3, 3, "ORGANISATION"]
  ]
}

Usage

# Install dependencies
pip install -r requirements.pred.txt       # inference only
pip install -r requirements.train.txt      # training + annotation tools

# Step 1: OCR (edit img_path in PaddleOCR.py first)
python PaddleOCR.py

# Step 2: Run NER
python final.py                            # fine-tuned model (recommended)
python sample.py                           # pretrained medium model (baseline)

# Step 3: Fine-tune on your own data
python finetune.py
# or config-driven:
python train.py --config config.yaml --log_dir ./logs

Example Output

Jose Sebastian E     => PERSON
CTO                  => DESIGNATION
Muthoottu Infotech   => ORGANISATION
65/623 K, Kaloor, Kochi, Kerala - 682 017  => ADDRESS
98468 70514          => PHONE NUMBER
[email protected]  => EMAIL
www.mmsofttech.com   => URL

Stack

GLiNER · spaCy · PaddleOCR · PyTorch · HuggingFace Transformers · Accelerate


Author: Swani Madhoop — CUSAT, AI & DS