Skip to main content

Profile-based text curation pipelines for Hugging Face Datasets

Project description

text-curation

Profile-based text curation pipelines for Hugging Face Datasets

PyPI version PyPI downloads License GitHub release Python versions


Overview

text-curation is a Python library for building structured, profile-driven text curation pipelines designed to integrate naturally with Hugging Face Datasets.

The library focuses on deterministic, inspectable text transformations for preparing large-scale corpora used in NLP and LLM training workflows.

Rather than providing ad-hoc cleaning scripts, text-curation encourages explicit curation profiles that describe what transformations are applied and why.


Design Principles

  • Profile-driven pipelines
    Reusable, declarative profiles define how text is curated for a given domain (e.g. web, wiki, news).

  • Composable blocks
    Each transformation is implemented as an isolated block that can be enabled, disabled, or reordered.

  • Deterministic and non-destructive
    Transformations are conservative by default and designed to preserve semantic content.

  • Structure-aware
    Text is treated as structured data (paragraphs, lists, headers), not just strings.

  • Dataset-scale friendly
    Built to operate efficiently with Hugging Face Datasets.


Current Scope (v0.1.x)

text-curation currently provides foundational, structure-aware text curation for real-world, messy text data.

The focus is on deterministic preprocessing rather than semantic classification or ML-based filtering.

Implemented Blocks

  • Normalization

    • Unicode normalization (NFKC)
    • Quote, dash, and ellipsis normalization
    • Control character and zero-width cleanup
  • Formatting

    • Whitespace normalization
    • Paragraph reconstruction
    • Punctuation spacing fixes
    • Code and indentation preservation
  • Redaction

    • Email redaction
    • API token and credential masking
    • URL credential stripping
  • Structure

    • Header, bullet, and numbered list detection
    • Paragraph and line-level signals
    • Repetition and boilerplate indicators
  • Filtering

    • Empty document removal
    • Boilerplate paragraph filtering
    • List block suppression (configurable)
  • Deduplication

    • Paragraph-level exact deduplication
    • Conservative, non-destructive defaults

More aggressive semantic filtering and fuzzy deduplication are intentionally out of scope for v0.1.x and will be introduced behind explicit opt-in mechanisms in later releases.


Installation

text-curation supports Python ≥ 3.9.

Install from PyPI:

pip install text-curation

Or install from source for development:

git clone https://github.com/Dhiraj309/text-curation.git
cd text-curation
pip install -e .

Quickstart

Curating a Hugging Face Dataset

from datasets import load_dataset
from text_curation import TextCurator

dataset = load_dataset(
    "allenai/c4",
    "en.noclean",
    split="train",
)

curator = TextCurator.from_profiles(profile_name="web_common_v1")

cleaned = dataset.map(
    curator,
    batched=True,
    num_proc=4,
)

The curator is a pure function that takes a batch dictionary and returns a dictionary with the same schema.


Profiles

Profiles define which blocks are applied and in what order.

Example (conceptual, simplified):

web_common_v1 = [
    NormalizationBlock(),
    FormattingBlock(),
    RedactionBlock(),
    StructureBlock(),
    FilteringBlock(),
    DeduplicationBlock(),
]

Profiles are versioned to ensure reproducibility and auditability.


Designed For

  • Web-scale datasets (C4-like, Common Crawl, scraped corpora)
  • OCR and PDF-derived text
  • Forums, blogs, and user-generated content
  • Dataset preprocessing prior to LLM training or evaluation

The library is intentionally model-agnostic and does not depend on tokenizers, embeddings, or classifiers.


Why text-curation?

  • Cleaning text is not just normalization — structure and repetition matter
  • Ad-hoc scripts do not scale or reproduce
  • Dataset curation deserves the same rigor as model training
  • Explicit pipelines make data decisions inspectable

text-curation is designed to be the data-side analogue of model-definition libraries in the Hugging Face ecosystem.


When should you not use text-curation?

  • If you only need a one-off regex cleanup
  • If your data is already fully curated
  • If you require ML-based content classification (not in scope)

Versioning & Stability

This project follows semantic versioning.

  • 0.x releases may introduce breaking changes
  • Profiles are versioned explicitly (e.g. web_common_v1)
  • Stable APIs will be formalized before 1.0.0

Contributing

Contributions are welcome.

If you plan to add new blocks or profiles, please:

  • Keep transformations deterministic
  • Avoid destructive defaults
  • Include before/after examples

See CONTRIBUTING.md for details.


License

Apache 2.0. See LICENSE.


Acknowledgements

Inspired by large-scale dataset curation practices in the Hugging Face ecosystem.

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

text_curation-0.2.0.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

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

text_curation-0.2.0-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

Details for the file text_curation-0.2.0.tar.gz.

File metadata

  • Download URL: text_curation-0.2.0.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for text_curation-0.2.0.tar.gz
Algorithm Hash digest
SHA256 77d71202f22660d468716b5155d181f8019e68c22bccd0ce3586f094f135b88a
MD5 4f266e8cd3139d177167975423c55c33
BLAKE2b-256 92cce061b86a918e236f9d9b9fa31e9d5da0682b3f29034a99b6ad4bb9f066b2

See more details on using hashes here.

File details

Details for the file text_curation-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: text_curation-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for text_curation-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c820d257b64f67ae5d06ee702175ab4906625fb2ea7ac01a29f05763a11aaa72
MD5 cbaa5a21fb2ea4cd8975a479ee7dd941
BLAKE2b-256 ee811417155d6faf22d35ce54e931dac54c7904740345c74e34e233bfaf9d18f

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