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"
ds = ds.map(lambda x: {"max(b)": max(x["b"])})

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.0.tar.gz (54.0 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.0-py3-none-any.whl (46.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hyped_crane-0.1.0.tar.gz
  • Upload date:
  • Size: 54.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for hyped_crane-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e0fe5d31ae531a676b52114bcfa4c756f8c8cfdf88de82443fa4a8e96c91d2a8
MD5 659d43b90a7d7c9548fae724ad44e300
BLAKE2b-256 de669d81aad2be04b4358c8f099ed1922cad82faa87942d0790d413c62808e92

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: hyped_crane-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 46.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for hyped_crane-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4071bf2c1c027983ea791c6e0f3f7a52bf1b34a533bff5185f1393315ac01b79
MD5 58d669deb2c0eb7f30278245e29bd001
BLAKE2b-256 dfbc8e1d59ea53413664675685fca9a1b304b132e3f1ebc49a3151a9bf0e2506

See more details on using hashes here.

Provenance

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