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

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: mauve_gpu-0.3.8.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.8.tar.gz
Algorithm Hash digest
SHA256 f4371e8125a76bc881aa376ecafeebdf9dac55aee905035a64ba79011318fcf5
MD5 1c7ca609ac923beb3b01194e4aafc2b2
BLAKE2b-256 841a42bfc607e6b64f1cf601694b68007d1abdae3f9aa6ed2319d9933ae99731

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mauve_gpu-0.3.8-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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 fd86e7c2291449d79badb19c4b88ae2896d49621c5a07b3e1fbc505dcdb22f0a
MD5 aaded7d5a793e9e081361df4eabb32be
BLAKE2b-256 605f1021c51c7e21c8a42647320948b54f9aa63f2ae72d52ca1c7fd990704534

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