Jinja templates are the backend structure of a Model Card document. The Model Card Toolkit comes with a few pre-made templates, but you can freely modify these templates or even build your own. In this document, we will discuss how to do this.
The following is the standard way you may initialize the Model Card Toolkit.
mct_directory = ... # where the Model Card assets will be generated mct = ModelCardToolkit(mct_directory) model_card = mct.scaffold_assets() ... # set the model_card's fields here mct.update_model_card(model_card)
When you run
mct.scaffold_assets(), the contents of model_card_toolkit/template are copied into
mct_directory/template. This includes premade templates such as default_template.html.jinja and default_template.md.jinja.
object generated above can be manually populated. Once you are ready to generate
a Model Card document, you can pass the
model_card back into MCT with
In Model Card Toolkit 2.0, Jinja templates will be replaced with a new TypeScript/Lit-based rendering system.
Use a Premade Model Card Template
We can then generate a Model Card document using one of the default templates, via the code below.
template_path = os.path.join(mct_directory, 'template/html/default_template.html.jinja') mct.export_format(template_path=template_path, output_file='model_card.html')
Modify the Model Card Template
You can freely modify a premade template to change styling, reorganize information, etc. You should be familiar with the Jinja API and control structures. Model Card field names are taken from model_card.py.
Creating a new Model Card Template
Creating a new Model Card template works the same as modifying an existing one.
my_custom_template_path = ... # where the template is stored mct.export_format(template_path=my_custom_template_path, output_file'model_card.html') # generate the final Model Card