Sub topic 10
Machine-Readable Metadata in Model Cards
Prerequisites and purpose
This chapter assumes basic supervised machine learning, Python, Markdown, and version control. You should know the difference between training and test data and recognize metrics such as accuracy and F1 score.
A model card has two audiences:
- People need readable explanations about the model.
- Tools need predictable fields that they can parse without understanding the prose.
Machine-readable metadata is structured information stored in a format such as YAML or JSON. It describes facts such as the model's license, language, task, dataset, metrics, and base model. A platform or pipeline can read these fields to search, filter, display, or validate a model.
YAML front matter
A common pattern is YAML front matter. It appears at the beginning of a Markdown file between two lines containing three hyphens. The first line marks the beginning of metadata. The second line marks its end.
For example, a model card might begin like this:
---
license: apache-2.0
language:
- en
library_name: transformers
pipeline_tag: text-classification
tags:
- support-tickets
datasets:
- my-org/support-tickets
metrics:
- accuracy
- f1
base_model: distilbert-base-uncased
---The keys should use stable, documented names. Values should be precise enough for automated use. For example, apache-2.0 is more useful than “permissive license” because a tool can recognize the standard identifier.
Metadata does not replace the explanatory sections below it. The metadata identifies and categorizes the model. The prose explains how the model was trained, evaluated, and intended to be used.
| Field | What it communicates | Example |
|---|---|---|
| license | Legal terms for using the model | apache-2.0 |
| language | Languages represented by the model or task | en |
| pipeline_tag | Main task category | text-classification |
| datasets | Training or evaluation data references | my-org/support-tickets |
| metrics | Names of reported measures | accuracy, f1 |
| base_model | Model from which this version was adapted | distilbert-base-uncased |
Choosing useful fields
Use metadata that downstream users can verify. A language field should describe the language in the data or task, not the language used to write the README. A datasets field should point to a dataset identifier or a documented internal reference. A metrics field should name metrics that are actually reported in the evaluation section.
Record the model version in a normal section or in the platform's supported metadata fields. Do not place information in metadata merely because it sounds complete. Incorrect metadata can cause a model to appear in searches where it does not belong.
How metadata supports automation
A publication pipeline can inspect front matter before publishing a model. It can reject a card with no license, task, or dataset reference. It can also compare declared metrics with the results recorded in the evaluation section.
A validator should check both structure and meaning where possible. Structural checks can confirm that required keys exist. Semantic checks can confirm that a metric value is numeric, a license is approved, or a referenced dataset is available.
Validating required sections
Metadata validation is only one part of card validation. A card should also contain human-readable sections such as intended use, training data, evaluation, and limitations.
The following script checks required headings. It reads a file named README.md and exits with an error when a section is missing.
import re
REQUIRED = ["Intended use", "Training data", "Evaluation", "Limitations"]
def missing_sections(markdown: str) -> list[str]:
headings = {
match.group(1).strip().lower()
for match in re.finditer(r"^#{1,6}\s+(.+)$", markdown, re.MULTILINE)
}
return [
section
for section in REQUIRED
if not any(section.lower() in heading for heading in headings)
]
with open("README.md", encoding="utf-8") as file:
missing = missing_sections(file.read())
if missing:
raise SystemExit(f"Model card is missing sections: {missing}")
print("Model card contains all required sections.")This check does not prove that the claims are true. It only enforces a minimum structure. Stronger checks can parse YAML, validate allowed values, and compare metadata with experiment records.
Versioning and maintenance
Keep the model card in the same repository or release process as the model artifact. Update the card when the model, training data, evaluation procedure, license, or intended use changes. Review metadata as part of each release.
A new model version may require new metrics, limitations, or dataset references. Do not copy an older card unchanged when those facts differ.
Exercise
Why should a model card contain both YAML metadata and prose sections?
Show answer
YAML gives tools predictable fields for search and validation, while prose gives people the context needed to understand intended use, evaluation, limitations, and risks.