Skip to main content

Supervised Multi-Dimensional Scaling

Arxiv License Python Versions CI

This is a stand-alone implementation of Supervised Multi-Dimensional Scaling (SMDS) from the paper "Shape Happens: Automatic Feature Manifold Discovery in LLMs". It contains a plug-and-play class written with the familiar scikit-learn interface. SMDS supports several template shapes to discover manifolds of various forms.

Contact person: Federico Tiblias

UKP Lab | TU Darmstadt

Don't hesitate to report an issue if you have further questions or spot a bug.

Getting started

With uv (recommended):

uv add supervised-multidimensional-scaling

With pip:

pip install supervised-multidimensional-scaling

Usage

The SupervisedMDS class provides a scikit-learn style interface that is straightforward to use. Unlike standard MDS, it requires a target manifold shape (e.g., ClusterShape, CircularShape) to define the ideal geometry.

Fit & Transform

You can instantiate the model, fit it to data (X, y), and transform your input into a low-dimensional embedding:

import numpy as np
from smds import SupervisedMDS
from smds.shapes import ClusterShape

# Example data
X = np.random.randn(100, 20)   # 100 samples, 20 features
y = np.random.randint(0, 5, size=100)  # Discrete labels (clusters)

# Instantiate and fit
# manifold can be any class inheriting from BaseShape
smds = SupervisedMDS(n_components=2, manifold=ClusterShape(), alpha=0.1)
smds.fit(X, y)

# Transform to low-dimensional space
X_proj = smds.transform(X)
print(X_proj.shape)  # (100, 2)

Manifold Discovery

The library provided a high level pipeline to automatically discover the intrinsic manifold of your data. The discover_manifolds utility evaluates a set of hypothesis shapes (for example: clusters, circles, hierarchies) and ranks them based on how well they explain the data structure using cross validation.

from smds.pipeline.discovery_pipeline import discover_manifolds
from smds.pipeline import open_dashboard

# Run discovery pipeline
# Evaluates default shapes (Cluster, Circular, Hierarchical, etc.)
# Returns a DataFrame sorted by best fit (lowest stress / highest score)
df_results, save_path = discover_manifolds(
    X, 
    y, 
    smds_components=2,           # Target dimensionality
    n_folds=5,                   # Cross-validation folds
    experiment_name="My_Exp",    # Name for saved results
    n_jobs=-1                    # Use all available cores
)

print(f"Best matching shape: {df_results.iloc[0]['shape']}")
print(df_results.head())

# Launch the interactive Streamlit dashboard to explore results and plots
open_dashboard.main(save_path)

The discovery pipeline handles:

  • Hypothesis Testing: Iterates through a default or custom list of manifold shapes.
  • Cross-Validation: Uses k-fold CV to ensure robust scoring.
  • Caching: Caches intermediate results to resume interrupted experiments.
  • Visualization: Generates interactive plots for the dashboard.

Development

This seciton is especially usefull if you consider contributing to the library!

Documentation

To build and serve the documentation locally:

mkdocs serve

[!NOTE] The dev dependency group includes heavy libraries such as torch and transformers.

Testing

Run the test suite using pytest:

make test

Cite

Please use the following citation:

@misc{tiblias2025shapehappensautomaticfeature,
      title={Shape Happens: Automatic Feature Manifold Discovery in LLMs via Supervised Multi-Dimensional Scaling}, 
      author={Federico Tiblias and Irina Bigoulaeva and Jingcheng Niu and Simone Balloccu and Iryna Gurevych},
      year={2025},
      eprint={2510.01025},
      archivePrefix={arXiv},
      primaryClass={cs.AI},
      url={https://arxiv.org/abs/2510.01025}, 
}

Metadata

Release files for supervised-multidimensional-scaling 0.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for supervised-multidimensional-scaling 0.9.1
File Size Uploaded
supervised_multidimensional_scaling-0.9.1.tar.gz 377.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for supervised-multidimensional-scaling 0.9.1
File Interpreter ABI Platform
supervised_multidimensional_scaling-0.9.1-py3-none-any.whl Python 3 none any Details

Total release size: 430.7 kB

Release files / supervised_multidimensional_scaling-0.9.1.tar.gz

Download URL supervised_multidimensional_scaling-0.9.1.tar.gz
Size 377.1 kB
Tags Source
SHA-256 checksum
How to use checksums
79c118f7211da34eaf3a7e696d55b65854b44358ded0f284ee39dc416ef1a939
BLAKE2b-256 checksum
How to use checksums
e127a0c6d1fcf458d201c5466692fc36ef99875cfae7afd2f078ae939ff7e363
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.12

Release files / supervised_multidimensional_scaling-0.9.1-py3-none-any.whl

Download URL supervised_multidimensional_scaling-0.9.1-py3-none-any.whl
Size 53.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
81e11566a56de42f58fac19f88769a166606a2a4cdb2dc1956605e9ca9e3de3b
BLAKE2b-256 checksum
How to use checksums
4ce92a1d74b77549f4452957cc729b553a38c51baae9e1c1272d8bfdc3a10158
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.12

Release history Release notifications | RSS feed

This release

0.9.1 This release

2 release files

0.8.0

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.4.9

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page