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-gpu

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

# 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.9.tar.gz (17.8 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.9-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mauve_gpu-0.3.9.tar.gz
  • Upload date:
  • Size: 17.8 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.9.tar.gz
Algorithm Hash digest
SHA256 ec43edd0ad4b31e3e97bedc77f2421ff33beb7c46f2d4d0af42ad3e0ac41dcfd
MD5 7f1d269ea7e3d0ad631c1022b565fd63
BLAKE2b-256 8d31b59238111d719ea9719027ed6412209a9b7a8722696fefb93b42e3aa4c79

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mauve_gpu-0.3.9-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.9-py3-none-any.whl
Algorithm Hash digest
SHA256 58838b31a753bfdc9a36a1b0472ba157eeb50da5570a943df0699ec599f560b3
MD5 92658e5ed7ec5303f1c73a9a2fe304da
BLAKE2b-256 c9be5f354d926a6a03b18ae9271ea05be654330f5daca2073de5eff4a5546ddc

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