Skip to main content

A plug-and-play, scikit-learn compatible implementation of Supervised Multi-Dimensional Scaling (SMDS) for automatic feature manifold discovery in LLMs.

Project description

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}, 
}

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

supervised_multidimensional_scaling-0.9.1.tar.gz (377.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file supervised_multidimensional_scaling-0.9.1.tar.gz.

File metadata

File hashes

Hashes for supervised_multidimensional_scaling-0.9.1.tar.gz
Algorithm Hash digest
SHA256 79c118f7211da34eaf3a7e696d55b65854b44358ded0f284ee39dc416ef1a939
MD5 94570deea82bbfffc668f3772e44051c
BLAKE2b-256 e127a0c6d1fcf458d201c5466692fc36ef99875cfae7afd2f078ae939ff7e363

See more details on using hashes here.

File details

Details for the file supervised_multidimensional_scaling-0.9.1-py3-none-any.whl.

File metadata

File hashes

Hashes for supervised_multidimensional_scaling-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 81e11566a56de42f58fac19f88769a166606a2a4cdb2dc1956605e9ca9e3de3b
MD5 5ef6098490943d8230e4bce971887aef
BLAKE2b-256 4ce92a1d74b77549f4452957cc729b553a38c51baae9e1c1272d8bfdc3a10158

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