Skip to main content

Lift (process) and place (write) data streams, seamlessly and in parallel.

Project description

🏗️ Hyped Crane

Tests Linting Coverage Status PyPi version PyPi license

Lift (process) and place (write) data streams, seamlessly and in parallel.

Hyped Crane is a Python library designed to simplify working with HuggingFace datasets' iterable datasets. It provides powerful tools for applying transformations to data streams, handling parallel processing, and writing data in varios formats.

Features

  • Streaming-Friendly Transformations: Apply lazy, streaming-friendly transformations to iterable datasets without preloading data into memory.
  • Seamless Multiprocessing: Effortlessly process and write datasets using multiple processes, improving performance on large datasets.
  • Easily Extendable: Provides a straightforward interface to implement support for custom data formats.
  • Interoperability with Hugging Face Datasets: Write datasets in formats directly loadable using HuggingFace’s load_from_disk function.

Installation

To install the library from PyPI, run:

pip install hyped-crane

To install the library from source, clone run:

git clone https://github.com/open-hyped/crane.git
cd crane
pip install .

Getting Started

Here’s a quick example to illustrate how Hyped Crane works

Step 1: "Load" the Dataset

crane is designed to work seamlessly with HuggingFace’s iterable datasets. Let’s start by creating one:

import datasets

# Create a dummy iterable dataset
dummy_data = [
    {"a": 0, "b": [1, 2, 3, 4]},
    {"a": 1, "b": [5, 6]},
    {"a": 1, "b": [7, 8, 9, 10]}
]
ds = datasets.Dataset.from_list(dummy_data)
ds = ds.to_iterable_dataset()

Step 2: Apply a Lazy Transformation

Transformations on iterable datasets are applied lazily. That means the data isn’t processed until it’s actually read:

# Apply a transformation to compute the maximum of list "b"
features = datasets.Features(ds.features | {"max(b)": ds.features["b"].feature})
ds = ds.map(lambda x: {"max(b)": max(x["b"])}, features=features)

Note: Some writers, including the ArrowDatasetWriter, require the dataset features to be well defined.

Step 3: Write the Dataset to Disk

Use crane’s ArrowDatasetWriter to save the transformed dataset to disk. You can enable multiprocessing to speed up the transformation and writing processes:

from crane import ArrowDatasetWriter

# Write the transformed dataset to disk with multiprocessing
writer = ArrowDatasetWriter("data", overwrite=True, num_proc=3)
writer.write(ds)

Key Benefits:

  • Data-Parallel Transformations: The transformations defined by map operations are moved into the workers, allowing transformation workload to be evenly distributed.
  • Efficient Writing: Each worker writes its own shard to disk in parallel, reducing bottlenecks in I/O operations.

crane handles worker communication, task distribution, and writing operations, so you can focus on defining your transformation logic without worrying about parallelization details.

Note: Datasets saved with the ArrowDatasetWriter are fully compatible with HuggingFace’s load_from_disk function. You can reload the dataset and continue working with it:

# Reload the dataset from disk
ds = datasets.load_from_disk("data")

Contributions

Contributions are welcome! Feel free to submit a pull request or open an issue to discuss your ideas.

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

hyped_crane-0.1.2.tar.gz (58.7 kB view details)

Uploaded Source

Built Distribution

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

hyped_crane-0.1.2-py3-none-any.whl (51.0 kB view details)

Uploaded Python 3

File details

Details for the file hyped_crane-0.1.2.tar.gz.

File metadata

  • Download URL: hyped_crane-0.1.2.tar.gz
  • Upload date:
  • Size: 58.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hyped_crane-0.1.2.tar.gz
Algorithm Hash digest
SHA256 220fd5f96a671ef06cd1924d36cff2da1f6b8c987ed8c256e9ffea5c444851c7
MD5 475f5526d48db0cd78d12cd1b2b1a28d
BLAKE2b-256 f63c60b24d43a4a4aada08e73e4cc6b8a8582d09a9288d2abc522e1f9e4ea75f

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyped_crane-0.1.2.tar.gz:

Publisher: publish.yml on open-hyped/crane

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hyped_crane-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: hyped_crane-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 51.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hyped_crane-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4d0ce852370aba388e66d318a33c13bdd6574df63867805d9f67f32e2329ae2b
MD5 ed2a18469bf9d964dfda02f45d40ca1b
BLAKE2b-256 d581a9cb58b00c09e6e6497cc087a31e6e8aabd42678b0ebcdcecd849c3d3870

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyped_crane-0.1.2-py3-none-any.whl:

Publisher: publish.yml on open-hyped/crane

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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