Skip to main content

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

Project description

Mauve-cuML

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

Note: Adjust cu12 and cuda12x based on your CUDA version (e.g., cu11 for CUDA 11).

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

Installing from Source

git clone https://github.com/danielwolber-wood/mauve-cuml.git
cd mauve-cuml
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_cuml 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.3.tar.gz (2.5 MB 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.3-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mauve_gpu-0.3.3.tar.gz
  • Upload date:
  • Size: 2.5 MB
  • 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.3.tar.gz
Algorithm Hash digest
SHA256 1fb451cce19bae639677cb91007d5cad3db03e5a97496a2c16ca7b3a3b6ffe0a
MD5 83ebf7b266afdf62f7da34e1f2abf5ec
BLAKE2b-256 e1795eb4dc01bb429ce57e787be3cd30f4cdc82a26cb85718d3345f46f4bef09

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mauve_gpu-0.3.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 71a8f13a6a62bb2c7ac1d93d2a680f3ccfab27502ad4888dad9adfdfda713eab
MD5 f1fb0542395aa030a994641abb56e103
BLAKE2b-256 e41ccddf7b7a5e92c6d739732117ec91de645044a43db043632d6204224af071

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