Supervised Multi-Dimensional Scaling
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
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
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| supervised_multidimensional_scaling-0.9.1.tar.gz | 377.1 kB | Without provenance | Details for supervised_multidimensional_scaling-0.9.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| supervised_multidimensional_scaling-0.9.1-py3-none-any.whl | Python 3 | none | any | Details for supervised_multidimensional_scaling-0.9.1-py3-none-any.whl |
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
|
Security for supervised-multidimensional-scaling 0.9.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.