Skip to main content

Tokenization-free PDF segmentation using OCR and spaCy span-aware chunking

Project description

📄 pdf2seg

Tokenizer-free PDF segmentation using OCR and span-aware text chunking.

pdf2seg processes scanned or embedded-text PDFs using EasyOCR and spaCy, segmenting raw text into semantically relevant spans—no tokenizers, sentence splitters, or fixed rules required.


🚀 Features

  • Tokenizer-Free Chunking – no subword vocabularies or fragile heuristics
  • OCR-Agnostic – supports scanned PDFs with diagrams, math, or multilingual text
  • Span-Aware Segmentation – uses spaCy syntax and entropy-minimized sampling
  • Checkpointing & Resume Support – deterministic processing saved to hash.json
  • Rich Console UI – interactive UV-style bars powered by rich

📦 Installation

Install from PyPI:

pip install pdf2seg

Or with UV:

uv pip install pdf2seg

🧪 Quick Usage

pdf2seg -i paper.pdf -o data/

📁 Output:

data/
|── <hash>/
|   |── <hash>-p000.png  ← rendered page
|   |── <hash>-p000.txt  ← OCR result
|   |── <hash>.json      ← processing manifest
|── <hash>.csv           ← segmented spans

🧬 Internals

Under the hood, pdf2seg performs:

  1. PDF-to-image conversion (pdf2image)
  2. OCR with easyocr
  3. Sentence splitting + span grouping with spacy
  4. Filtering + export to CSV
  5. Manifest updates for resumability

You can inspect the span cutoff logic, filters, or tweak the entropy mode in __init__.py.


🧩 Future Plans

  • Modality tagging (code vs prose vs formulae)
  • Math-aware OCR fallback (e.g. Im2LaTeX)
  • Stream-aware recomposition
  • Standalone hash-viewer web demo

🔖 License

MIT License © 2025 Rawson, Kara
Project: p3nGu1nZz/pdf2seg


If you use or reference this software in an academic publication or project, please consider citing it using the following BibTeX entry:

@software{rawson2025pdf2seg,
  author       = {Rawson, Kara},
  title        = {pdf2seg: Tokenizer-Free PDF Segmentation with OCR and Span-Aware Chunking},
  year         = {2025},
  version      = {1.0.1},
  url          = {https://github.com/p3nGu1nZz/pdf2seg},
  note         = {Python package available at PyPI: https://pypi.org/project/pdf2seg/}
}

👁 See Also

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

pdf2seg-1.0.2.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

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

pdf2seg-1.0.2-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file pdf2seg-1.0.2.tar.gz.

File metadata

  • Download URL: pdf2seg-1.0.2.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for pdf2seg-1.0.2.tar.gz
Algorithm Hash digest
SHA256 786a345acb52bcdc697ace69c46a24409478f43cc1cb70ead7e26106569b2759
MD5 dd8c74acebb346c7a39486902652a531
BLAKE2b-256 3cf354be42c164aba03573e3e1526f7bafdb0d346cae9e9743dae53e77be30b1

See more details on using hashes here.

File details

Details for the file pdf2seg-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: pdf2seg-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for pdf2seg-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7cd911182ce507326596879015c5a2fddf8269be1a304992350e139de24ab713
MD5 f7f4f6c573cad1ce14bcc2e302994494
BLAKE2b-256 737765cd1637926f7e07dc17a222f5ee80a527aa6c14141e0690256f6d9911b8

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