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.3.tar.gz (59.5 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.3-py3-none-any.whl (51.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hyped_crane-0.1.3.tar.gz
  • Upload date:
  • Size: 59.5 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.3.tar.gz
Algorithm Hash digest
SHA256 0164fde1188047a5aaee6708bf9ce42b494729996bb89de9fa81dd2c05fc7fbb
MD5 369ae73b0d9554ad5df0f25ea6d4e6d6
BLAKE2b-256 175db529c45ce481f4e0cd8dd1a128f95f55d8d0c94e896e68c7b32f15fb7f45

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyped_crane-0.1.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: hyped_crane-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 51.6 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b71aab38ab77283a8aa998c65a6205b29e8ebbd6682744c7e193141871098f3b
MD5 e104a480a409a21ea8fe710f2f8d9c77
BLAKE2b-256 2fe056ef957bbc8bc0541dca093ec567d1d34965f1a3458d8cc5cadb3961fcc8

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyped_crane-0.1.3-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