document-to-dataset-pipeline

Build labeled ML datasets from emailed PDF reports and spreadsheet labels, then validate a classifier.

Updated May 28, 2026
One-click install
npx skills add https://github.com/patty-chow/the-stable --skill document-to-dataset-pipeline-patty-chow
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: document-to-dataset-pipeline
Source: https://github.com/patty-chow/the-stable/tree/main/skills/data-science/document-to-dataset-pipeline
Command: npx skills add https://github.com/patty-chow/the-stable --skill document-to-dataset-pipeline-patty-chow

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch, torchvision, Pillow, pymupdf, openpyxl, pytesseract, open_clip, and includes scripts (resource) and references (resource) components.

What problem does it solve? Recurring semi-structured reports (emailed PDFs with photos plus an Excel/CSV carrying ground-truth labels) are painful to turn into a clean labeled dataset, and naive classifier attempts fail on imbalanced, noisy, sample-biased data. This Skill provides a re-runnable pipeline that joins PDF evidence to spreadsheet labels on an ID key and validates a vision/LLM classifier with imbalance-aware metrics before anything goes live. ## Core Features & Use Cases - Dataset assembly: Pull Gmail attachments via the REST API, parse Excel labels and PDF pages with PyMuPDF, join on a normalized ID key, and emit a manifest plus per-class image folders. - Label-scheme validation: Tabulate observable features against the verdict column at full scale to detect derivable rules, signal-vs-noise features, and labeler inconsistency before training. - Classifier training and evaluation: Fine-tune a pretrained ResNet18 with record-level train/val splits, class-weighted loss, and recall/precision/false-alarm reporting, plus threshold sweeps and Average Precision model selection. - Human-in-the-loop review: Generate a self-contained HTML reviewer with embedded photos, Grad-CAM explainability, and a prefilled mailto approval round-trip. - Use Case: A rail-car inspection workflow emails daily PDF reports with photos and an Excel verdict sheet; use this Skill to harvest all historical reports into a 10k-record labeled dataset, discover that the verdict is a derivable rule over observable features, and train a local image classifier that beats the vision-LLM baseline. ## Quick Start Ask the agent to pull all inspection report emails, parse the PDF pages and Excel labels, join them on the record ID, and build the labeled dataset manifest.

Frequently Asked Questions about document-to-dataset-pipeline

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build a labeled dataset from emailed PDF reports and Excel labels?▼

Download attachments via the Gmail REST API, parse the spreadsheet for labels with openpyxl, split the PDF into per-record pages with PyMuPDF, and join both sides on a normalized ID key. Emit a manifest plus per-class image folders so the pipeline is re-runnable when new reports arrive.

How do I train an image classifier on imbalanced data with PyTorch?▼

Fine-tune a pretrained ResNet18 with a class-weighted CrossEntropyLoss using inverse class frequencies, and split train/validation at the record level so photos of one record never leak across sides. Report recall, precision, and false-alarm rate per epoch instead of accuracy.

Why is accuracy a bad metric for theft or defect detection?▼

With low positive rates, an always-negative model scores high accuracy while catching zero events. Report recall on the positive class and false-positive rate separately, and rank models by Average Precision rather than metrics at a single 0.5 threshold.

How do I download Gmail attachments when the CLI only exposes message bodies?▼

Get an OAuth token from the bridge, then call the Gmail REST API directly: fetch the message with format=full, walk payload parts for attachment IDs, and download bytes from the attachments endpoint with urlsafe base64 decoding.

Why does my OCR match rate stay low on photo ID overlays?▼

A fixed crop fails when the overlay position varies; OCR a wide strip at 3x upscale with grayscale and autocontrast instead. Constrain Tesseract to the known ID character set, validate against the ID regex, and fuzzy-match against the batch's known ID list.

When should I not train a local model on a small labeled sample?▼

Avoid training when classes have only a handful of examples, since the model becomes confidently wrong. Validate the label scheme on the full corpus first, because rules fitted on a small sample can reverse at scale, and ship a human-in-the-loop API hybrid while labeled data accumulates.