Skip to main content

PDF → OCR → sliding-window chunking → multi-question generation via LLM → JSONL dataset for fine-tuning

Project description

pdf2qa

End-to-end pipeline: PDF → OCR → sliding-window chunking → multi-question generation → JSONL dataset for LLM fine-tuning.

pip install pdf2qa
pdf2qa book.pdf --api-key sk-...

Features

  • OCR — Scanned PDFs via PyMuPDF + Tesseract (optimised for Bengali/Arabic)
  • Sliding window — Configurable chunk size/stride ensures no content is missed
  • Multi-question — Generates 2–3 distinct questions per chunk, each saved as a separate JSONL object
  • Language-agnostic — Default English prompt, override for any language with --system-prompt
  • Checkpoint/resume — Survives interruptions and rate-limits
  • Retry logic — Primary → fallback API with exponential backoff

Quickstart

# With a PDF (auto-OCR)
pdf2qa book.pdf --api-key sk-... --output ./dataset

# With pre-extracted text
pdf2qa book.txt --skip-ocr --api-key sk-... --output ./dataset

# Custom chunking
pdf2qa book.pdf --window 4 --stride 2 --api-key sk-...

Environment variable

Set PDF_QA_API_KEY instead of passing --api-key every time.

Output format

JSONL (one object per line) in OpenAI fine-tuning format:

{"messages": [{"role": "user", "content": "প্রশ্ন?"}, {"role": "assistant", "content": "উত্তর..."}]}
{"messages": [{"role": "user", "content": "অন্য প্রশ্ন?"}, {"role": "assistant", "content": "উত্তর..."}]}

Options

Argument Default Description
--lang ben+ara Tesseract languages
--dpi 400 OCR render DPI
--window 3 Pages per chunk
--stride 1 Sliding stride
--output ./output Output directory
--skip-ocr Input is already .txt
--model qwen-code-35b LLM model ID
--api-key API key (or $PDF_QA_API_KEY)
--primary-url http://... Primary API URL
--fallback-url https://... Fallback API URL
--system-prompt (built-in) Custom system prompt ({num_questions} placeholder)
--user-prompt (built-in) Custom user prompt ({chunk}, {num_questions})
--question-keywords What Why How ... Keywords to identify a question line

Development

git clone https://github.com/yourusername/pdf2qa
cd pdf2qa
pip install -e ".[dev]"
pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdf2qa-0.1.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdf2qa-0.1.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file pdf2qa-0.1.0.tar.gz.

File metadata

  • Download URL: pdf2qa-0.1.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for pdf2qa-0.1.0.tar.gz
Algorithm Hash digest
SHA256 23093ef6c021cab63c8b2ea98a8dae788f3fa905b6e946a25075b617bfd56dc0
MD5 e2731687c587bf9dd71ea8738feab57e
BLAKE2b-256 211b66ecab25f0d74cdbadba83e157aeaea0879f0b6874de28e8e1dfeb1c053d

See more details on using hashes here.

File details

Details for the file pdf2qa-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pdf2qa-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for pdf2qa-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c366561c90ef93f6c0199c7c08f1220d97b2fdd7c40f5c6f2e92ac35669a558a
MD5 296b340c4df24b8183f43bf1178bf996
BLAKE2b-256 65b4d8dace3d29e67f3b789de6009145a568914d12c76f96efbd7c668151c5d7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page