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 that 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 conservative
    All transformations are rule-based and non-destructive by default, prioritizing semantic preservation.

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

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


Scope & Stability (v1.1.0)

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

The default behavior and semantics of the core blocks and built-in 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.1.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_profile("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.

Profiles are:

  • Explicitly versioned
  • Registered at import time
  • Resolved via a global registry

Conceptual example:

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

Profiles are versioned explicitly (e.g. web_common:v1) to ensure reproducibility and auditability across releases.


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 independently of library versions to preserve long-term reproducibility

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.2.0.tar.gz (29.0 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.2.0-py3-none-any.whl (31.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: text_curation-1.2.0.tar.gz
  • Upload date:
  • Size: 29.0 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.2.0.tar.gz
Algorithm Hash digest
SHA256 0fc96ef0fb2f9787e2ce0b12f7c696040f9920c4b11656156d0ddea666d9f98c
MD5 49dec35a8d05c671068e5afd38710603
BLAKE2b-256 c40231912e6b6325699b7c8999596a95dcb4a10c19cce59770e208b6445d11f9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: text_curation-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 31.3 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c8b434706551ef8f6b759078e99db5a81f11d02cd1a0f20e46ed48404c628343
MD5 a73fcbcdf5dae13f78024f5a7eb83b1f
BLAKE2b-256 571ed2cf0f7f60578fd7b83b8aad36ea994fb2e9ac660b7de4a721c8df602d72

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