Skip to content

TorchSOM is a PyTorch-based library for training Self-Organizing Maps (SOMs), a type of unsupervised learning algorithm used for clustering and dimensionality reduction. Designed for scalability and ease of use, this implementation is optimized for large-scale data.

License

Notifications You must be signed in to change notification settings

michelin/TorchSOM

torchsom: The Reference PyTorch Library for Self-Organizing Maps

PyPI version Python versions PyTorch versions License: Apache 2.0

Quality Gate Status Reliability Rating Security Rating Maintainability Rating Coverage

Tests Code Quality Downloads GitHub stars

Code style: black Imports: isort Ruff

TorchSOM_logo

The most comprehensive, scalable, and PyTorch-native implementation of Self-Organizing Maps

πŸ“š Documentation | πŸš€ Quick Start | πŸ“Š Examples | 🀝 Contributing

⭐ If you find torchsom valuable, please consider starring this repository ⭐


🎯 Why torchsom?

torchsom is the reference PyTorch library for Self-Organizing Maps (SOMs), purpose-built for seamless integration with modern deep learning and scientific workflows. Unlike legacy SOM packages, torchsom is engineered from the ground up to fully leverage PyTorch’s ecosystemβ€”offering native GPU acceleration, scalable performance, and compatibility with neural network pipelines. Whether you are a researcher or practitioner, torchsom empowers you to efficiently incorporate SOMs into your machine learning projects, from exploratory data analysis to advanced model architectures.

torchsom is the official implementation accompanying the paper: torchsom: The Reference PyTorch Library for Self-Organizing Maps. If you use torchsom in academic or industrial work, please cite the paper and the software (see CITATION).

Note: Check the table below for a comprehensive comparison of how torchsom differs from existing SOM libraries, and explore our Visualization Gallery for examples of the rich visual outputs available.

⚑ Key Advantages

Aspect torchsom MiniSom SimpSOM SOMPY somoclu som-pbc
Framework PyTorch NumPy NumPy NumPy C++/CUDA NumPy
GPU Acceleration CUDA ❌ CuPy/CUML ❌ CUDA ❌
API Design scikit-learn Custom Custom MATLAB Custom custom
Maintenance Active Active Minimal Minimal Minimal ❌
Documentation Rich ❌ Basic ❌ Basic Basic
Test Coverage ~86% ❌ ~53% ❌ Minimal ❌
PyPI Distribution βœ… βœ… βœ… ❌ βœ… ❌
SOM Variants Multiple ❌ PBC ❌ PBC PBC (only)
Visualization Advanced ❌ Moderate Moderate Basic Basic
Extensibility High Moderate Low Low Low Low

πŸ“‘ Table of Contents


πŸš€ Quick Start

Get started with torchsom in just a few lines of code:

import torch
from torchsom.core import SOM
from torchsom.visualization import SOMVisualizer

# Create a 10x10 map for 3D input
som = SOM(x=10, y=10, num_features=3, epochs=50)

# Train SOM for 50 epochs on 1000 samples
X = torch.randn(1000, 3)
som.initialize_weights(data=X, mode="pca")
QE, TE = som.fit(data=X)

# Visualize results
visualizer = SOMVisualizer(som=som, config=None)
visualizer.plot_training_errors(quantization_errors=QE, topographic_errors=TE, save_path=None)
visualizer.plot_distance_map(save_path=None)
visualizer.plot_hit_map(data=X, save_path=None)

πŸ““ Tutorials

Explore our comprehensive collection of Jupyter notebooks:

🎨 Visualization Gallery

πŸ—ΊοΈ D-Matrix Visualization

Michelin production line (regression)

U-Matrix
πŸ“ Hit Map Visualization

Michelin production line (regression)

Hit Map
πŸ“Š Mean Map Visualization

Michelin production line (regression)

Mean Map
πŸ—ΊοΈ Component Planes Visualization

Another Michelin line (regression)

Component Plane 1 Component Plane 2
🏷️ Classification Map

Wine dataset (multi-classification)

Classification Map
πŸ“Š Cluster Metrics

Clustering analysis

Cluster Metrics
πŸ“ˆ K-Means Elbow

Optimal cluster selection

K-Means Elbow
🎯 HDBSCAN Cluster Map

Cluster visualization

HDBSCAN Cluster Map


πŸ’Ύ Installation

πŸ“¦ PyPI

pip install torchsom

πŸ”§ Development Version

git clone https://github.com/michelin/TorchSOM.git
cd TorchSOM
python3.9 -m venv .torchsom_env
source .torchsom_env/bin/activate
pip install -e ".[dev]"

πŸ“š Documentation

Comprehensive documentation is available at opensource.michelin.io/TorchSOM


πŸ“ Citation

If you use torchsom in your research, please cite both the paper and software:

@inproceedings{Berthier2025TorchSOM,
    title={torchsom: The Reference PyTorch Library for Self-Organizing Maps},
    author={Berthier, Louis},
    booktitle={Conference Name},
    year={2025}
}

@software{Berthier_TorchSOM_The_Reference_2025,
    author={Berthier, Louis},
    title={torchsom: The Reference PyTorch Library for Self-Organizing Maps},
    url={https://github.com/michelin/TorchSOM},
    version={1.0.0},
    year={2025}
}

For more details, please refer to the CITATION file.


🀝 Contributing

We welcome contributions from the community! See our Contributing Guide and Code of Conduct for details.


πŸ™ Acknowledgments


πŸ“„ License

torchsom is licensed under the Apache License 2.0. See the LICENSE file for details.


πŸ“š References

πŸ“– Core Papers

πŸ”— Related Projects

  • MiniSom: Minimalistic Python SOM
  • SimpSOM:Simple Self-Organizing Maps
  • SOMPY: Python SOM library
  • somoclu: Massively Parallel Self-Organizing Maps
  • som-pbc: A simple self-organizing map implementation in Python with periodic boundary conditions
  • SOM Toolbox: MATLAB implementation

About

TorchSOM is a PyTorch-based library for training Self-Organizing Maps (SOMs), a type of unsupervised learning algorithm used for clustering and dimensionality reduction. Designed for scalability and ease of use, this implementation is optimized for large-scale data.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published