Papa Programmer
Lesson 36 of 36

Safety, licences and upkeep

9 min read

Optional

What the licences allow

A fine-tuned model combines several things, and each has its own terms: the base model, the training data, the libraries and any outputs you used from another model. Check each one for:

  • Use. Some licences restrict commercial use, large deployments or particular fields.
  • Distribution. Whether you may share or sell the tuned weights, and under which terms.
  • Attribution. Whether you must name the base model or pass the licence on.
  • Outputs from other models. Provider terms may limit using their outputs to train a competing model, as Distillation noted.

Record the exact model version, dataset versions and licence text with every release. Nothing in this Lesson is legal advice, so ask a lawyer when the stakes are high.

Private data in the training set

Training data collected from real use often holds email addresses, phone numbers, account numbers and secrets. A model can memorise rare strings, so removing the source file later does not remove the influence from trained weights. The safest time to act is before training. Keep only what you need, limit who can read it and set a deletion process.

The program below scans a few training rows for common patterns and replaces them with labels. The data is invented, and the patterns catch only simple cases. Names, addresses and free-text details need more than a regular expression, so treat the scan as a first filter and sample by hand afterwards.

python
import re

patterns = {
	"email": re.compile(r"[\w.+-]+@[\w-]+\.[\w.]+"),
	"phone": re.compile(r"\+?\d[\d \-]{7,}\d"),
	"key": re.compile(r"\bsk-[A-Za-z0-9]{8,}\b"),
}

rows = [
	"Please email maria@example.test about order 118.",
	"Call me on +49 170 1234567 after noon.",
	"My key is sk-test1234abcd, please check it.",
	"How do I reset my password?",
]

found = {name: 0 for name in patterns}
clean = []
for row in rows:
	for name, pattern in patterns.items():
		found[name] += len(pattern.findall(row))
		row = pattern.sub(f"[{name}]", row)
	clean.append(row)

print("found:", found)
print(f"rows changed: {sum(a != b for a, b in zip(rows, clean))} of {len(rows)}")
for row in clean:
	print(" ", row)

It prints:

text
found: {'email': 1, 'phone': 1, 'key': 1}
rows changed: 3 of 4
  Please email [email] about order 118.
  Call me on [phone] after noon.
  My key is [key], please check it.
  How do I reset my password?

Three of four rows held private details. Keep the raw file out of the repository and out of logs, and apply the same care to evaluation sets and review tools, as Cleaning data and checking quality describes.

Test for harmful output

Write tests for the harms that matter for your application, such as revealing private data, giving unsupported advice or following instructions hidden in user text. Include prompts that try to bypass the intended behaviour. Run them on the base model and on the tuned model, because fine-tuning can weaken safety behaviour that the base model had, as Catastrophic forgetting warned. Record failures, and decide in advance which outputs a person must review. The OWASP list for LLM applications is a useful starting checklist.

Watch it after release

A model that passed its tests can still get worse in use, because inputs and users change. Track error rate, latency, refusals and user reports, and compare them with the numbers from your evaluation. The program below flags the first week in which the weekly accuracy has stayed below an agreed floor for two weeks in a row.

python
evaluation_accuracy = 0.90
floor = evaluation_accuracy - 0.05
weekly = [0.91, 0.89, 0.88, 0.86, 0.84, 0.83]

below = 0
for week, accuracy in enumerate(weekly, start=1):
	below = below + 1 if accuracy < floor else 0
	status = "ALERT" if below >= 2 else "ok"
	print(f"week {week}: {accuracy:.0%}  {status}")

It prints:

text
week 1: 91%  ok
week 2: 89%  ok
week 3: 88%  ok
week 4: 86%  ok
week 5: 84%  ok
week 6: 83%  ALERT

Week 5 is the first below the 85% floor, and week 6 is the second in a row, so the alert fires then. A single low week can be noise, so the rule waits for two. Pick the floor and the number of weeks before launch and write them down. Sample outputs for review only where your privacy rules permit it. Keep the previous model ready for a quick rollback.

When to retrain

Retrain when a measured change justifies it: new products, new policies, a shift in the inputs or a drop that error analysis ties to the data. First check whether updated retrieval, a changed prompt or application code solves it, as RAG or fine-tuning? explains, because a retrain costs time and risks new regressions. When you do retrain, evaluate on current cases and on the older behaviour you must keep, as Evaluating a fine-tuned model describes. The NIST AI Risk Management Framework offers a wider structure for these decisions.

  1. LicenceRecord model, data and licence versions.
  2. CleanRemove private details from training data.
  3. TestRun harm tests on the tuned and the base model.
  4. MonitorTrack quality, latency and reports against a floor.
  5. RespondRoll back, fix the data or retrain, then re-test.
Before and after release
Clean firstPrivate data is easiest to remove before training.
Test the tuned modelTuning can weaken safety behaviour the base model had.
Set the alert in advanceDecide the floor and the number of weeks before launch.

Your reading position is saved

0%

0 of 36 complete

Contents

Learning tools