Skip to main content

A GPU-accelerated (cuML) implementation of the MAUVE score for comparing distributions.

Project description

mauve-gpu

A GPU-accelerated implementation of the MAUVE score for comparing distributions, leveraging RAPIDS.ai cuML.

MAUVE is a metric for evaluating the quality of generated text by comparing the distribution of generated text to reference text in an embedding space. This library provides a fast and robust implementation using GPU acceleration for PCA and K-Means clustering.

Features

  • GPU Acceleration: Uses cupy and cuml for high-performance computation.
  • Robustness: Implements multiple K-Means runs to select the best clustering, improving score stability.
  • Easy Integration: Compatible with NumPy and CuPy arrays.
  • Configurable: Allows tuning of PCA components, K-Means clusters, and other parameters.

Installation

Prerequisites

  • Python >= 3.8
  • NVIDIA GPU with CUDA support
  • CUDA Toolkit (compatible with the installed RAPIDS version)

Installing Dependencies

This library relies on RAPIDS libraries (cuml, cupy), which are best installed via Conda or from the NVIDIA PyPI index.

Using Pip:

You need to point pip to the NVIDIA package index to install cuml and cupy.

pip install --extra-index-url https://pypi.nvidia.com cuml-cu12 cupy-cuda12x
pip install mauve-cuml

Using Conda:

conda create -n mauve-env -c rapidsai -c conda-forge -c nvidia \
    cuml=23.10 python=3.10 cupy
conda activate mauve-env
pip install mauve-gpu

Installing from Source

git clone https://github.com/danielwolber-wood/mauve-gpu.git
cd mauve-gpu
pip install --extra-index-url https://pypi.nvidia.com -e .

Usage

Here is a simple example of how to use MauveScorer.

import numpy as np
from mauve_gpu import MauveScorer

# Generate dummy embeddings (replace with your actual embeddings)
# P: Reference distribution (e.g., human text embeddings)
# Q: Generated distribution (e.g., model text embeddings)
p_features = np.random.rand(1000, 768).astype(np.float32)
q_features = np.random.rand(1000, 768).astype(np.float32)

# Initialize the scorer
scorer = MauveScorer(
    pca_components=50,
    kmeans_clusters=100,
    num_kmeans_runs=5,
    verbose=True
)

# Compute the score
score = scorer.compute(p_features, q_features)
print(f"MAUVE Score: {score:.4f}")

Parameters

  • pca_components (int): Number of components for PCA reduction (default: 50).
  • kmeans_clusters (int): Number of clusters for quantization (default: 500).
  • num_kmeans_runs (int): Number of K-Means runs to perform to find the best clustering (default: 10).
  • scaling_factor (float): The 'c' parameter in the MAUVE paper (default: 5.0).
  • divergence_curve_points (int): Number of points for the divergence curve (default: 100).
  • random_state (int): Seed for reproducibility (default: 42).
  • verbose (bool): If True, prints progress logs (default: False).

Examples

See the examples/ directory for more detailed usage, including an example using sentence-transformers to compute MAUVE scores for text datasets.

To run the demo:

  1. Install example dependencies:
    pip install .[examples]
    
  2. Run the script:
    python examples/demo.py
    

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

Acknowledgments

  • Based on the original MAUVE paper: "MAUVE: Measuring the Gap Between Neural Text and Human Text using Divergence Frontiers".
  • Built with RAPIDS.ai for GPU acceleration.

AI Disclosure

The first draft of this README was written with AI assistance. Several of the tests in tests/test_core.py were drafted by AI, but were manually checked for correctness.

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

mauve_gpu-0.3.7.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

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

mauve_gpu-0.3.7-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file mauve_gpu-0.3.7.tar.gz.

File metadata

  • Download URL: mauve_gpu-0.3.7.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mauve_gpu-0.3.7.tar.gz
Algorithm Hash digest
SHA256 b9cf6105fca78f192221b535391e1961047f4b97765309e0d41ba90a1ac8d982
MD5 7a4587b04342083cbd7585ae387e6f2a
BLAKE2b-256 5db41ccf60d53e260073d1adabc5e5927ab914c84d1ccd8ac31933f8b30c42b8

See more details on using hashes here.

File details

Details for the file mauve_gpu-0.3.7-py3-none-any.whl.

File metadata

  • Download URL: mauve_gpu-0.3.7-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mauve_gpu-0.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 a2b14e25c080c6f229704d5c788279f6625e4968d3c66881ecffd282e03a4406
MD5 23a34e4af04bc13329e6a9efcd6c6beb
BLAKE2b-256 783078d7b3a9107d2b2921c8c7aa792355032cf40433597d972387a5dec8f7f1

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