Skip to main content

A streamlined approach to model card generation for machine learning models

Project description

Model Card Printer

The Model Card Printer simplifies the generation of model cards for machine learning models. Model Card Printer offers a standardized and structured approach to documenting machine learning models, while still providing flexibility for users to customize the document without being overly restrictive.

  • Works with popular data visualization libraries such as Pandas and Plotly.
  • Supports all text-based documentation in Markdown format.
  • Tailor your model card to fit your needs and preferences.
  • Supports exporting model cards in JSON, Pickle, and HTML formats.

Installation

Model Card Printer is available as a PyPI package. Install it using pip package manager:

pip install model-card-printer

Quickstart

1. Create documentation and data visualizations

Note: All visualizations generated here are for demonstration purposes. You could use Pandas to create your visualizations as well.

import plotly.express as px

# Create documentation (markdown format)
documentation_standalone = "# Model Card Demo\nHere is a paragraph related to the documentation.\n## Considerations\nThis demonstration is for anyone that wants to quickly start generating model cards with their trained ML models."

# Create data visualizations and related documentation
df = px.data.tips()
fig1 = px.box(df, y="total_bill")
fig2 = px.histogram(df, x="total_bill", color="sex", marginal="rug",
                         hover_data=df.columns)
fig3 = px.density_heatmap(df, x="total_bill", y="tip")

documentation_for_visuals = "# Quantitative Analysis\nThe visualizations presented are for demonstration purposes only."

# Create standalone data visualizations
df = px.data.iris()
fig_standalone = px.scatter_matrix(df,
    dimensions=["sepal_length", "sepal_width", "petal_length", "petal_width"],
    color="species", symbol="species",
    title="Scatter matrix of iris data set",
    labels={col:col.replace('_', ' ') for col in df.columns})
fig_standalone.update_traces(diagonal_visible=False)

2. Create model card

from model_card_printer import ModelCardPrinter

# Generate an empty model card
model_card = ModelCardPrinter.generate_card()

# Store all the information
model_card.add_custom_documentation(documentation_standalone, document_name = 'demo')
model_card.add_custom_visualization_collection({"demo fig 1": fig1, "demo fig 2": fig2, "demo fig 3": fig3},
                                               documentation = documentation_for_visuals,
                                               collection_name = "Demo visuals and text")
model_card.add_individual_custom_visualization(fig_standalone, "demo standalone fig")

# Save model card as HTML (default dark mode, else add parameter "is_dark_mode = False")
model_card.write_html("demo_model_card.html")

Model Card Export Formats

  1. Output as JSON
# Saving to JSON file
model_card.write_json("model_card.json")

# OPTIONAL: Intermediate output
model_card_json = model_card.to_json()
  1. Output as HTML
# Saving to HTML file
model_card.write_html("model_card.html")

# OPTIONAL: Intermediate output
model_card_html = model_card.to_html()
  1. Output as Pickle object (not recommended unless there is a need to store the datasets inside the model card)
import pickle

with open('model_card.pkl', 'wb') as file:
    pickle.dump(model_card, file)

Model Card Import Formats

  1. Load from JSON file
model_card = ModelCardPrinter(file_path = "model_card.json").load_from_json()
  1. Load from Python dictionary
dict_model_card = previous_model_card.to_dict()
model_card = ModelCardPrinter(data_dict = dict_model_card).load_from_dict()

Tutorials

For more in-depth demonstrations on model-card-printer package, refer to the provided examples.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

model_card_printer-0.1.1.tar.gz (23.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

model_card_printer-0.1.1-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file model_card_printer-0.1.1.tar.gz.

File metadata

  • Download URL: model_card_printer-0.1.1.tar.gz
  • Upload date:
  • Size: 23.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for model_card_printer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c69204b60e9c74de4ad92d932b005a8d117174d0cfc2b6e983429aeda994ae9b
MD5 271d71350340760c5ddc2ba5576891af
BLAKE2b-256 a021939aee816164df86707f0711e0d6e81131f815bf24108c9c2803c592720f

See more details on using hashes here.

File details

Details for the file model_card_printer-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for model_card_printer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5bdbe60e16f8289c97803b372b8db783dc6281df5c3a09cc8c9f331d01394498
MD5 18bc1ae4d77d6b47365a0b835efe393f
BLAKE2b-256 bf4660e6362e6ff2b3978f637e0851ff8ff12f6ff2b08fae76651ade26d55c5c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page