cblearn: Comparison-based Machine Learning in Python

David-Elias Künstle, Ulrike von LuxburgJ. Open Source Softw 2024 · DBLP

Abstract

Comparison-based machine learning focuses on learning from relative similarities—such as "object A is more similar to B than to C"—rather than explicit feature vectors or absolute similarity scores. Historically, this field has been hindered by fragmented research code and a lack of standardized tools. cblearn is a new open-source Python library that addresses these challenges by providing a unified, scikit-learn-compatible API for ordinal embedding and clustering. By supporting both CPU and GPU backends, cblearn enables researchers and practitioners to scale comparison-based algorithms to modern, large-scale datasets.

Introduction

Traditional machine learning typically relies on numeric features (e.g., height, weight, or pixel intensity) or explicit similarity metrics. However, in domains like psychology, cognitive science, and marketing, obtaining precise numeric scores is often impractical. Humans are notoriously inconsistent when asked to provide absolute similarity ratings (e.g., "this apple is 0.8 similar to this pear"), but they are highly reliable when making relative comparisons (e.g., "a pear is more similar to an apple than to a banana").

Despite the power of this "comparison-based" data, working with it has historically been difficult. Implementations of key algorithms were often scattered across one-off research scripts, lacking a central hub for datasets or a standardized way to benchmark different methods. cblearn fills this gap, transforming a fragmented research landscape into a production-ready ecosystem integrated with the modern scientific computing stack.

Methods and Technical Architecture

The core functionality of cblearn centers on Ordinal Embedding. These algorithms take a set of relative comparisons (triplets or quadruplets) and estimate a metric representation—essentially a map—where the Euclidean distances between points reflect the provided comparisons.

Scikit-learn Integration

To ensure ease of use, the library adopts the standard scikit-learn convention of .fit(), .transform(), and .predict() methods. This allows cblearn estimators to be plugged directly into existing pipelines for cross-validation, hyperparameter tuning, and model selection.

Dual Backends

cblearn is designed for both accessibility and performance:

  • CPU Backend: Most algorithms are implemented using scipy for lightweight execution on standard hardware.
  • GPU Backend: For large-scale problems, the library leverages torch (PyTorch). This enables the use of GPU acceleration and automated differentiation, facilitating stochastic optimization on massive datasets that were previously computationally prohibitive.

Datasets and Benchmarking

A significant contribution of cblearn is the standardization of datasets within the comparison-based learning community. The library provides built-in interfaces to download and load several real-world human-response datasets, ranging from image similarity to domain-specific categories like food, materials, and fashion.

Comparison of dataset sizes in terms of objects and triplets.

As shown in the figure above, cblearn supports a wide variety of datasets. These range from smaller sets like vogue and nature to massive collections like imagenet-v2, which contains millions of triplets. The library also includes routines to generate synthetic comparison data, which is essential for benchmarking new algorithms against known ground truths.

Key Insights

  • Standardization: By providing a common framework, researchers can finally perform side-by-side comparisons of different embedding methods, such as Stochastic Triplet Embedding versus Crowd Kernel.
  • The Quadruplet Unit: The authors define the "quadruplet"—the assertion that the similarity between $(i, j)$ is greater than $(k, l)$—as the fundamental unit of data. They demonstrate that the more common "triplet" is simply a special case of a quadruplet where $i = k$.
  • Sparse Representation: To handle the potentially explosive number of triplets in large datasets, cblearn utilizes a 3D sparse array format. This allows for intuitive indexing and efficient memory usage.

Results and Adoption

The library currently implements eight major algorithms, including Stochastic Triplet Embedding, Generalized Non-metric MDS, and Comparison-based Hierarchical Clustering (ComparisonHC). While full benchmarks are detailed in the supplementary materials of the original paper, the authors highlight that the GPU-accelerated implementations allow the library to scale to datasets of unprecedented size in this field. cblearn has already seen adoption in published studies across vision science and conceptual scaling, proving its utility as a robust research tool.

Limitations and Future Work

While the current version (0.3.0) provides a comprehensive suite for embedding and clustering, comparison-based tasks like regression and classification remain active areas of research. Future iterations of cblearn aim to integrate these tasks more deeply. As an open-source project, its continued growth relies on community contributions to expand its library of modular algorithms and supported datasets.

Summary updated

BibTeX
@article{kunstle2024cblearn,
  author = {David-Elias Künstle and Ulrike von Luxburg},
  title = {{cblearn: Comparison-based Machine Learning in Python}},
  journal = {J. Open Source Softw.},
  year = {2024},
  doi = {10.21105/joss.06139},
}
Figure