Braindump

Search

Search IconIcon to open search

SKOPS

Last updated Jan 3, 2023

SKOPS is python library that allow to share your model huggingface.

Hugging Face Hub

Requirements

To use model the huggingface hub needs some info, which is stored in metadata in README.md or config.json

https://huggingface.co/docs/hub/model-cards

{
    "sklearn": {
	"columns": [
	    "petal length (cm)",
	    "petal width (cm)",
	    "sepal length (cm)",
	    "sepal width (cm)",
	],
	"environment": ['scikit-learn="1.1.1"', "numpy"],
	"example_input": {
	    "petal length (cm)": [1.4, 1.4, 1.3],
	    "petal width (cm)": [0.2, 0.2, 0.2],
	    "sepal length (cm)": [5.1, 4.9, 4.7],
	    "sepal width (cm)": [3.5, 3.0, 3.2],
	},
	"model": {"file": "model.pkl"},
	"task": "tabular-classification",
    }
}

The config file is created automatically by “skops.hub_utils.init()” You almost never need to create or touch this file manually, and it’s created when you call skops.hub_utils.init(). ``

# contents of train.py
...
hub_utils.init(model, dst=local_repo)
hub_utils.add_files(__file__, dst=local_repo)  # adds train.py to repo
hub_utils.push(...)

Model Cards for scikit learn

https://huggingface.co/docs/hub/model-cards#model-card-metadatahttps://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/modelcard_template.md

Add plots or Tables

Card.add_plot() method. For tables, you can pass either dictionaries with the key being the header and the values being list of row entries, or a pandas DataFrame; use the Card.add_table() method for this.

Add content to existing Section

Card select

Card delete

Automatically Generated

The template also contains the following sections that are automatically generated by skops.

“Hyperparameters”: Hyperparameters of the model.

“Model Plot”: A diagram of the model, most relevant in case the model is a complex scikit-learn Pipeline.

Main Classes

Using Custom Templates For Model Cards

https://github.com/skops-dev/skops/issues/248https://skops.readthedocs.io/en/stable/model_card.htmlhttps://github.com/skops-dev/skops/pull/257

https://github.com/skops-dev/skops/pull/203/commits/68e474822906490e0013edc1d75014df10dd7e3c

To create a custom template user can define a template using dict.

User can add metrics plots using convienence method.

How can a user add certain section from default template.

currently, The I need section names but the problem i self.add(**SKOPS_TEMPLATE) , or specify certain section from the

then I can use self.add_model_plot() self.add_hyperparams() self.add_get_started_code()

to add other section to the model.

In this way I can use custom template, also use sections from the default templates.