Sub topic 1
Why models need documentation
Prerequisites
This chapter assumes you already know the following:
- Basic supervised machine learning: training, validation, and test sets.
- Common evaluation metrics such as accuracy, precision, and recall.
- Basic Python and Markdown, so you can read the short code samples.
- Git or a similar version control system.
You do not need to know what a model card is yet. This chapter explains why one is needed. Later chapters cover what a card contains and how to write each section.
The problem: a model is more than its weights
A trained model is a file of numbers plus the code that loads it. Those two things tell you how to run the model. They do not tell you whether you should.
Suppose a colleague hands you a file named ticket_classifier_final_v3.pkl. You can call predict() on it. To use it responsibly, you also need answers to questions the file cannot give you:
- What task was it built for, and for whom?
- What data was it trained on, and where did that data come from?
- How was it evaluated, and on which data?
- Does it work equally well for every kind of input?
- What should nobody use it for?
- Who do you ask when it misbehaves?
If those answers live only in someone's head, a chat thread, or a notebook that no longer runs, they are effectively lost. Documentation is the practice of writing them down in a stable place that travels with the model.
What goes wrong without documentation
The failures below are common in practice. Each one comes from information that existed at some point but was never recorded.
Reuse in the wrong context
A model is trained under specific conditions: a language, a time period, a population, a data source, a sensor type. Performance measured under those conditions is only evidence about similar conditions.
Without a record of those conditions, a new team may reuse the model somewhere different. A ticket classifier trained on English text gets pointed at a Spanish-language queue. It still returns a label for every ticket, so nothing crashes. The output is simply wrong more often, and nobody sees it, because the model never signals that it left its comfort zone.
Misread metrics
A number such as "accuracy 0.91" means little without context. A reader needs to know:
- which dataset it was computed on,
- how that dataset was sampled,
- the class balance,
- the metric's exact definition.
A model that reports 0.91 accuracy on a dataset where 90% of examples belong to one class is barely better than always guessing that class. Metrics without evaluation context invite false confidence.
Hidden gaps between groups
An overall metric averages over everything. If a model works well for a large group and badly for a small one, the average still looks fine. Only a breakdown by group shows the gap. If the breakdown is never computed or recorded, the people affected by the weaker performance have no way to learn of it, and the team deploying the model has no reason to look.
Lost provenance and failed audits
Provenance is the record of where something came from. For a model, that includes the training data, the code version, the base model if it was fine-tuned, and the license terms of each.
When an auditor, regulator, or customer asks how a decision was made, the team has to reconstruct this history. If the person who trained the model has left, the reconstruction may be impossible. License problems are a concrete case. If a model was fine-tuned from a base model with a restrictive license and nobody recorded that, the restriction may be discovered only after the model ships.
Silent drift in how a model is used
Models outlive the purpose they were built for. A model made to prioritize tickets gets reused to rank employee performance reviews because it is already available. Each reuse step is small, and nobody decides to cross a line. Without a written statement of intended use and out-of-scope use, there is no document to point to when someone proposes the next step.
Slow incident response
When a model starts producing bad outputs, the on-call engineer needs to answer quickly: what changed, what are the known weak spots, and who owns this. Without documentation, the first hours go to archaeology instead of repair.
Who reads model documentation
Different readers need different things from the same model. Good documentation serves several of them at once.
| Reader | Typical question | What they need |
|---|---|---|
| Engineer reusing the model | Can I use this for my task? | Intended use, input format, known failure modes |
| Reviewer or auditor | How was this built and checked? | Training data, evaluation method, versions |
| Product or policy owner | What risks come with shipping this? | Limitations, ethical considerations, out-of-scope uses |
| Affected person or advocate | Does this work for people like me? | Results broken down by group |
| Future maintainer | Why was it built this way? | Design choices, contacts, change history |
The overlap matters. The same short document answers all five readers, which is cheaper than answering each reader separately every time.
Documentation as a communication contract
A useful way to think about model documentation is as a contract between the people who build a model and the people who use it. The builder states what the model was designed to do and how well it did it under tested conditions. The user accepts that claims outside those conditions are not backed by evidence.
This framing explains two properties good documentation needs:
- It must be specific. "Works well on support tickets" is not a claim anyone can check. "Routes English-language tickets to one of five queues, 0.91 accuracy on a held-out 2024 sample" can be checked, challenged, and re-tested.
- It must include what the model does not do. A contract with only promises is a sales brochure. The limits are the part that protects users.
The model card as the answer
In 2019, Mitchell and colleagues published "Model Cards for Model Reporting". They proposed a short, structured document that accompanies a trained model and reports how it was built, what it is meant for, and how it performs. The idea was borrowed from the practice of attaching a specification sheet to a product. Later chapters cover the paper's origins and sections in detail. For now, one point matters: the card is a standard shape for the answers listed at the start of this chapter, so readers know where to look.
The code below shows the idea in miniature. A card is structured content, so you can represent it as data and render it as Markdown.
from dataclasses import dataclass, field
@dataclass
class ModelCard:
name: str
version: str
intended_use: str
out_of_scope: str
training_data: str
metrics: dict
limitations: list = field(default_factory=list)
def to_markdown(self) -> str:
lines = [
f"# {self.name} (v{self.version})",
"",
"## Intended use",
self.intended_use,
"",
"## Out-of-scope use",
self.out_of_scope,
"",
"## Training data",
self.training_data,
"",
"## Evaluation",
]
lines += [f"- {name}: {value}" for name, value in self.metrics.items()]
lines += ["", "## Limitations"]
lines += [f"- {item}" for item in self.limitations]
return "\n".join(lines) + "\n"
card = ModelCard(
name="support-ticket-classifier",
version="1.2.0",
intended_use="Route English-language support tickets to one of five queues.",
out_of_scope="Not for legal, medical, or safety-critical triage.",
training_data="120k anonymized tickets collected 2022-2024.",
metrics={"accuracy": 0.91, "macro_f1": 0.88},
limitations=["Accuracy drops on tickets shorter than 5 words."],
)
print(card.to_markdown())Running this prints a short document with five sections. Each section answers one of the questions from earlier. Notice that the card names an out-of-scope use and a limitation. These are the entries people most often leave out.
Why a single number is not enough
The most common documentation failure is reporting one aggregate metric. The next example shows why. It computes accuracy overall and then per group.
from collections import defaultdict
def accuracy_by_group(y_true, y_pred, groups):
correct = defaultdict(int)
total = defaultdict(int)
for truth, pred, group in zip(y_true, y_pred, groups):
total[group] += 1
correct[group] += int(truth == pred)
return {group: correct[group] / total[group] for group in total}
y_true = [1, 0, 1, 1, 0, 0]
y_pred = [1, 0, 1, 1, 1, 1]
groups = ["a", "a", "a", "b", "b", "b"]
print(accuracy_by_group(y_true, y_pred, groups))
# {'a': 1.0, 'b': 0.3333333333333333}Overall accuracy is 4 correct out of 6, about 0.67. That number sounds mediocre but usable. The per-group result shows something different: group a is classified perfectly, and group b is right only one time in three. A reader who sees only 0.67 cannot tell whether the errors are spread evenly or concentrated, and the right response differs in each case.
Real data has more groups, more conditions, and small sample sizes that make per-group numbers noisy. Those issues are the subject of a later chapter on disaggregated evaluation. The point here is that documentation should include the breakdown, because the aggregate can hide the problem.
How the pieces fit together
The next diagram shows how missing documentation leads to harm, and how a model card interrupts that path.
The "Yes" branch does not guarantee a good outcome. It guarantees that the decision is made with evidence, and that the evidence can be reviewed later.
What documentation cannot do
It helps to be realistic about limits, so you do not oversell documentation inside your own team.
- It does not improve the model. A card describes quality. It does not create it.
- It can be wrong or stale. A card written once and never updated describes a model that no longer exists. Keeping cards current is covered in the final chapter.
- It can be performative. A card filled with vague statements satisfies a checklist and informs no one. "May not perform well in all cases" is a typical empty sentence.
- It is not enforcement. Writing "not for medical use" does not stop anyone. It gives you a clear basis for review, access controls, and accountability.
- It does not replace testing. A reader still needs to validate the model on their own data before relying on it.
These limits are why the later chapters spend time on specificity, automation, and review, and not just on a list of headings.
Cost and benefit
Writing a card takes time, often a few hours for a first version, and a smaller amount to update it with each release. The benefit is hard to see because it appears as problems that did not happen.
A rough comparison helps you decide how much effort fits a given model:
| Situation | Documentation effort that fits |
|---|---|
| Throwaway experiment in a notebook | A few lines of notes in the repository |
| Internal model used by one team | A short card covering use, data, metrics, limits |
| Model shared across teams or published | Full card with per-group results and contacts |
| Model affecting people's access to services, money, or safety | Full card, review sign-off, and linked data and system documentation |
Effort should grow with the number of people who will rely on the model and the harm a wrong output can cause.
Summary of the argument
Models travel further than their authors expect. Information that is not written down is lost when people change teams, when the model is reused, or when someone outside the team asks how it works. Undocumented models lead to reuse in untested contexts, misread metrics, hidden gaps between groups, failed audits, and slow incident response. A model card is a standard, structured, specific document that addresses these failures by recording what the model is for, what it was built from, how it performed, and where it should not be used.
Exercise
A teammate says: "Our fraud model has 98% accuracy, so it needs no further documentation." Give two specific reasons this statement is not enough, and name one thing you would ask them to add.
Show answer
First, accuracy alone depends on the evaluation data and class balance. If only 2% of transactions are fraud, a model that always predicts "not fraud" also gets 98%, so the number says little about how well fraud is caught. Second, an overall figure can hide gaps between groups or conditions, such as different regions, card types, or transaction sizes, where the model may perform much worse. Things to add include: precision and recall for the fraud class, the evaluation dataset and how it was sampled, results broken down by relevant groups, the intended use and out-of-scope use, or the known limitations. Any one of these is an acceptable answer.
Exercise
Run the accuracybygroup example with y_pred changed to [1, 0, 1, 1, 0, 1]. What are the per-group accuracies, and what is the overall accuracy? Does the overall number now hide a gap?
Show answer
Group a is still 3 of 3, so 1.0. Group b has truth [1, 0, 0] and predictions [1, 0, 1], so 2 of 3, or about 0.667. Overall accuracy is 5 of 6, about 0.83. The gap is much smaller than before (1.0 versus 0.67), but it still exists, and the overall figure of 0.83 does not show it. You only see it in the per-group report.
Exercise
Name three kinds of readers of a model's documentation and, for each, one question the documentation should help them answer.
Show answer
Examples: an engineer reusing the model asks whether it fits their task (intended use, input format). An auditor asks how it was built and checked (training data, evaluation method, versions). A person affected by the model asks whether it works for people like them (results broken down by group). Product owners (risks and out-of-scope uses) and future maintainers (design choices and contacts) are also valid.