What is a model card?
A model card is a short document about one model. It says what the model is for, what data it learned from, how it performs for each group and where it must not be used.
A model keeps running long after the people who built it have moved on. In this lesson you write down a model and set a check that tells you when it has drifted.
By the end of this lesson
Note
I can document a model on a model card and set a check that tells a named person when it has drifted.
Key words
| Word | What it means |
|---|---|
| Model card | a short document that describes a model |
| Intended use | the job a model was built for |
| Monitoring | checking a live model's inputs and results over time |
| Drift | a change in the data a model sees after launch |
| Owner | the named person who answers for a model |
The cells students fill in are left blank in this preview.
A model card says what it is for
A model card is written so that a stranger can decide whether to use the model. It names the intended use, the data it learned from, and how it performs for each group.
It also says where the model must not be used and who answers for it. The Run below prints a short invented card for a model that ranks loan requests for a person to read.
Worked example: a model card
| Field | What it says |
|---|---|
| Purpose | Rank loan requests so a person reviews the riskiest first |
| Data | 5,000 past requests, 4,000 from group A and 1,000 from group B |
| How well it works | Selection rate and true positive rate by group, with the date measured |
| Limits | Refused applicants have no repayment record; group B is a small sample |
| Not for | A final refusal with no person looking |
| Owner | The head of lending, reviewed every six months |
The cells students fill in are left blank in this preview.
Print part of a model card
docker exec jupyter python3 -c 'card={"purpose":"rank loan requests for a person to review","not for":"a final decision with no person"};print("\n".join(k+": "+v for k,v in card.items()))'Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Data changes after a model launches
A model learns from data from the past. After launch, the people who apply can change with a new product or a new season.
Drift is that change. A model that was tested once is only tested on the past, so monitoring compares what it sees now with what it learned from. A large gap is a signal to ask the owner to look.
Compare an input then and now
docker exec jupyter python3 -c 'old=[40,42,38,44,36];new=[52,50,46,54,48];print(sum(old)/len(old),sum(new)/len(new))'Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Flag a change of more than a fifth
old = [40, 42, 38, 44, 36]
new = [52, 50, 46, 54, 48]
old_mean = sum(old) / len(old)
new_mean = sum(new) / len(new)
change = (new_mean - old_mean) / old_mean
print("Change:", change)
if change > 0.2:
print("Drift: ask the owner to look")
# Change the new values so the change falls below 0.2, then run again.
Watch the results by group as well
Drift in an input is one signal. The results by group are another. A model can keep its overall accuracy while the gap between two groups grows.
The Run below prints the gap each month between the number selected per 100 people in group A and in group B. It rises from 30 to 37.
Print the gap each month
docker exec jupyter python3 -c 'a=[50,50,48];b=[20,19,11];print([x-y for x,y in zip(a,b)])'Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
A named person must answer for the model
Monitoring only helps if a check leads to a person who can act. Write down who is told when a check fires and who can switch the model off. Also write down how long a person waits to have a decision looked at.
Add a review date to the card. A card with no owner and no date tells the reader nobody is looking.
A common mistake
Warning
Many people think responsibility ends when a model passes its test. A test only covers the past. Watch the inputs and the results by group on a schedule, and name the person who acts when a check fires.
Going further
Write a model card for the line you fitted in the data science module. Use the six fields from the worked example.
Then pick two inputs you would monitor, say what change would make you look, and name who you would tell.