Skip to main content

Profile-based text curation pipelines for Hugging Face Datasets

Project description

text-curation

Profile-based, deterministic 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.

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

Rather than relying on ad-hoc cleanup scripts, text-curation promotes explicit, versioned curation profiles that make data decisions reproducible, auditable, and stable over time.


Design Principles

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

  • Composable blocks
    Each transformation is implemented as an isolated block with a single, explicit responsibility.

  • Deterministic and non-destructive
    All transformations are rule-based and conservative by default, prioritizing semantic preservation.

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

  • Dataset-scale friendly
    Designed to run efficiently on large Hugging Face Datasets using .map.


Scope & Stability (v1.0.0)

As of v1.0.0, text-curation provides a stable core for structure-aware text curation of real-world, messy data.

The default behavior and semantics of the core blocks and profiles are considered stable and will not change without a major version bump.

The library intentionally focuses on deterministic preprocessing rather than semantic classification or machine-learning-based filtering.


Core Blocks (Stable)

The following blocks are part of the stable core in v1.0.0.

  • Normalization
    Canonicalizes Unicode and typography (quotes, dashes, ellipses), removes control and zero-width characters, and normalizes whitespace.

  • Formatting
    Reconstructs paragraphs, normalizes whitespace and punctuation spacing, and preserves relative indentation for structured content such as code blocks.

  • Redaction
    Masks sensitive content such as emails, API tokens, and embedded credentials using explicit, non-destructive placeholders.

  • Structure
    Detects headers, lists, repetition, and boilerplate indicators, emitting inspectable signals without mutating text.

  • Filtering
    Applies conservative, signal-based removal of empty or low-value paragraphs.

  • Deduplication
    Performs exact, paragraph-level deduplication using normalization-safe keys.

More aggressive semantic filtering, fuzzy deduplication, or heuristic cleanup are intentionally not enabled by default and may be introduced only via explicit opt-in profiles in future releases.


Non-Goals

text-curation intentionally does not attempt to:

  • Perform semantic or topical classification
  • Use machine learning or probabilistic heuristics
  • Infer document quality or intent
  • Preserve exact visual formatting of source text
  • Aggressively remove all boilerplate or repetition by default

These constraints are by design and are critical to ensuring predictable, reproducible dataset preprocessing.


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: it 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):

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

Profiles are explicitly versioned to ensure reproducibility and long-term auditability of dataset preprocessing.


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 and debuggable

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 or scoring

Versioning & Compatibility

This project follows semantic versioning.

  • 1.x releases guarantee stable default behavior
  • Breaking changes require a major version bump
  • Profiles are versioned explicitly (e.g. web_common_v1) to preserve reproducibility across releases

Contributing

Contributions are welcome.

When adding new blocks or profiles:

  • Keep transformations deterministic
  • Avoid destructive defaults
  • Include clear 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-1.0.0.tar.gz (22.2 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-1.0.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for text_curation-1.0.0.tar.gz
Algorithm Hash digest
SHA256 79f5af09e973f5c6731811dbb86a3654122bb1721d03bc5d5a74014d73fa8900
MD5 9d668c3ccec6ee04abe11dfdcbed5fc0
BLAKE2b-256 972773bb3c65d3574b8addb0fd573e4e075fe5a02a8b9a98c169aed81fdda729

See more details on using hashes here.

File details

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

File metadata

  • Download URL: text_curation-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 21.9 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-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 892b4821d552ab748a2b6700b0e19f02ac68d2a80a00d4a20c0ff5a351105bdf
MD5 b254b73b0179389a129bfbeb6e1d8ada
BLAKE2b-256 c039bdb26aa65bf9ecbcfd147c4178514d00b4a71f5a35e62d101a98b820bc18

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