Attend the Women in ML Symposium on December 7 Register now


Stay organized with collections Save and categorize content based on your preferences.

A TFX component to generate a model card.

The ModelCardGenerator is a TFX Component that generates model cards.

The model cards are written to a ModelCard artifact that can be fetched from the outputs['model_card]' property.


context = InteractiveContext()
mc_gen = ModelCardGenerator(
    json="{'model_details': {'name': 'my_model'} }",
        ('html/default_template.html.jinja', 'model_card.html'),
        ('md/', '')
mc_artifact = mc_gen.outputs['model_card'].get()[0]
mc_path = os.path.join(mc_artifact.uri, 'model_card', 'model_card.html')
with open(mc_path) as f:
  mc_content = f.readlines()

evaluation TFMA output from an Evaluator component, used to populate quantitative analysis fields in the model card.
statistics TFDV output from a StatisticsGen component, used to populate dataset fields in the model card.
pushed_model PushedModel output from a Pusher component, used to populate model details in the the model card.
json A JSON string containing ModelCard fields. This is particularly useful for fields that cannot be auto-populated from earlier TFX components. If a field is populated both by TFX and JSON, the JSON value will overwrite the TFX value. Use the Model Card JSON schema.
template_io A list of input/output pairs. The input is the path to a Jinja template. Using data extracted from TFX components and json, this template is populated and saved as a model card. The output is a file name where the model card will be written to in the model_card/ directory. By default, ModelCardToolkit's default HTML template (default_template.html.jinja) and file name (model_card.html) are used.

outputs Component's output channel dict.