Skops library enables scikit-learn model hosting, documentation, and collaboration on Hugging Face Hub
TL;DR
Skops is a new Hugging Face library that streamlines the process of serializing scikit-learn models, generating compliant model cards, and publishing them to the Hub, thereby improving reproducibility, discoverability, and interactive inference.
End‑to‑end workflow for a scikit-learn model
Conclusion: Skops provides a concise, scriptable pipeline that starts with a trained model and ends with a publicly shareable repository containing the model file, configuration, and a rich model card.
- Train a model – any scikit-learn estimator can be used. The example trains a
DecisionTreeClassifieron the breast‑cancer dataset. - Serialize the model – save the estimator with
pickle(orjoblib). The file path is passed toskops.hub_utils.init. - Initialize a local Hub repository –
hub_utils.initcreates a folder containing:- the serialized model file,
- a configuration JSON that records the model’s features, required library version, task identifier (
tabular-classification), and a sample input.
- Generate a model card – instantiate
skops.card.Cardwith the model path and metadata extracted viametadata_from_config. The card’s YAML header holds required metadata (license, library name, task), while the markdown body is populated with sections such as description, authors, limitations, and usage code. - Add evaluation details – use
addto describe the evaluation method andadd_metricsto insert numeric results (e.g., accuracy, F1). Plots (e.g., a confusion matrix) can be attached withadd_plot. - Save and push – write the card to
README.md, then callhub_utils.pushwith a Hub repo ID and authentication token. Settingcreate_remote=Truecreates the remote repo if it does not exist. - Download and update – others can retrieve the repository with
hub_utils.download. If dependencies change,hub_utils.update_envrewrites the environment specification.
Model card structure and automation
Conclusion: Skops automatically fills the Hugging Face model‑card template, ensuring that every required metadata field is present for discoverability and that the inference widget can be activated.
- The template consists of a YAML metadata block followed by free‑form markdown.
- Required YAML keys (license, library, task, etc.) are populated from the configuration file generated in step 3.
Card.addinjects custom fields such asmodel_description,limitations,citation_bibtex, andget_started_code.Card.add_metricsconverts metric dictionaries into a markdown table.Card.add_plotlinks image files (e.g.,confusion_matrix.png) into the card, which the Hub renders in the UI.
Inference widget integration
Conclusion: Once a repository contains a model file, configuration, and a correctly formatted card, the Hub automatically displays an interactive inference widget.
- The widget reads the
taskand example input from the configuration to build a UI for tabular‑classification predictions. - Users can test the model directly on the model page without writing any code.
Resources and examples
Conclusion: Hugging Face provides ready‑made tutorials and documentation to help users adopt Skops quickly.
- Model card tutorial – step‑by‑step guide for creating and customizing cards.
- hub_utils tutorial – demonstrates repository initialization, pushing, and downloading.
- Full API reference – detailed class and method documentation.
- An example repository showcasing the complete workflow is available at
https://huggingface.co/scikit-learn/skops-blog-example.
Why Skops matters
Conclusion: By coupling scikit-learn model serialization with Hub‑native metadata and interactive inference, Skops lowers the barrier for reproducible ML deployment, encourages community sharing of classic ML models, and extends the Hub’s model‑card ecosystem beyond deep‑learning frameworks.
Sources
- OriginalIntroducing Skops