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.

  1. Train a model – any scikit-learn estimator can be used. The example trains a DecisionTreeClassifier on the breast‑cancer dataset.
  2. Serialize the model – save the estimator with pickle (or joblib). The file path is passed to skops.hub_utils.init.
  3. Initialize a local Hub repositoryhub_utils.init creates 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.
  4. Generate a model card – instantiate skops.card.Card with the model path and metadata extracted via metadata_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.
  5. Add evaluation details – use add to describe the evaluation method and add_metrics to insert numeric results (e.g., accuracy, F1). Plots (e.g., a confusion matrix) can be attached with add_plot.
  6. Save and push – write the card to README.md, then call hub_utils.push with a Hub repo ID and authentication token. Setting create_remote=True creates the remote repo if it does not exist.
  7. Download and update – others can retrieve the repository with hub_utils.download. If dependencies change, hub_utils.update_env rewrites 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.add injects custom fields such as model_description, limitations, citation_bibtex, and get_started_code.
  • Card.add_metrics converts metric dictionaries into a markdown table.
  • Card.add_plot links 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 task and 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