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

smds-1.0.0.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.

smds-1.0.0-py3-none-any.whl (53.3 kB view details)

Uploaded Python 3

File details

Details for the file smds-1.0.0.tar.gz.

File metadata

  • Download URL: smds-1.0.0.tar.gz
  • Upload date:
  • Size: 377.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.12

File hashes

Hashes for smds-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ff7f229a9743f09461eab2fa3c5016223125cc1be19bbb2d1d97536f9819c814
MD5 1098c9eabbb60924b2d4eae1d6047f3f
BLAKE2b-256 6826cb04b80b46784ee74b56a4458fe4658e6480ea73595c92f2e5bceb709ffb

See more details on using hashes here.

File details

Details for the file smds-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: smds-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 53.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.12

File hashes

Hashes for smds-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0e526fd8836de36a1b3ad29e50f8e3c31d9dcdd1bf7641a185eab9400134a11
MD5 b69512e54c41547b1ce14359ef518c18
BLAKE2b-256 2f31bda830a1247a937ed619809fef1f60316df9c93e844310d8cdd9c83145aa

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