Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Watermarks, content credentials and deepfakes

After this lesson: I can judge how far a watermark, a content credential or a deepfake detector can be trusted.

70 min lesson4 commandsJupyterLab data science lab: pandas, Matplotlib and scikit-learn in the browser

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

Is this video real?

Provenance is the record of where a picture, a sound or a text came from and what was done to it. Watermarks and content credentials are two ways to carry it, and deepfake detectors try to work without it.

A cloned voice asking a finance team to pay an invoice is a real kind of fraud. Knowing what each check proves, and what it cannot, is part of building generators responsibly.

By the end of this lesson

Note

I can judge how far a watermark, a content credential or a deepfake detector can be trusted.

Key words

WordWhat it means
Provenancea record of where media came from and what changed it
Watermarka hidden signal a generator adds for a checker to find
Content credentialsa signed record of origin attached to a file
Deepfakegenerated media that shows a real person doing what they never did
False positivea real item wrongly flagged as fake
Base ratehow common something is before any test

The cells students fill in are left blank in this preview.

Starter

Have a go

Starter

4 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

A text watermark is a hidden count

Here is one published idea for a text watermark. A secret key splits the vocabulary into green and red halves, and the generator is nudged towards green tokens. A reader sees ordinary text.

A checker with the key counts the green tokens. Plain text is about half green. Far more than half is unlikely by chance, and a z-score says how unlikely: how many spreads above half the count sits.

Worked example: 200 tokens, half green by chance

StepValue
Expected green by chance200 × 0.5 = 100
Spread by chance√(200 × 0.25) = 7.07
Green tokens counted140
z-score(140 - 100) / 7.07 = 5.66
ReadingAbove about 4: almost never by chance

The cells students fill in are left blank in this preview.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Write the watermark checker

Command
docker exec jupyter sh -c "printf '%s\n' 'import numpy as np' 'green = set(np.random.default_rng(42).permutation(1000)[:500].tolist())' 'r = np.random.default_rng(7)' 'def check(name, tokens):' '    hits = sum(1 for t in tokens if t in green)' '    z = (hits - 0.5 * len(tokens)) / np.sqrt(0.25 * len(tokens))' '    print(name, hits, \"green of\", len(tokens), \"z =\", round(z, 2))' 'greens = np.array(sorted(green))' 'plain = r.integers(0, 1000, 200)' 'marked = np.where(r.random(200) < 0.8, r.choice(greens, 200), r.integers(0, 1000, 200))' 'reworded = np.where(r.random(200) < 0.4, r.integers(0, 1000, 200), marked)' 'check(\"plain text:\", plain)' 'check(\"watermarked:\", marked)' 'check(\"reworded:\", reworded)' 'check(\"short piece:\", marked[:20])' > steps/mark.py"

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Check four texts for the watermark

Command
docker exec jupyter python3 steps/mark.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

What mark.py printed

TextGreenz-score
Plain text, 200 tokens1091.27
Watermarked, 200 tokens17410.47
Watermarked, then 40% reworded1334.67
First 20 watermarked tokens173.13

The cells students fill in are left blank in this preview.

What a watermark can and cannot prove

Rewording cut the z-score from 10.47 to 4.67, and heavier rewording cuts it further. A short piece carries little evidence even when every token is marked. A checker finds only watermarks whose key it holds, and a generator run without one adds none.

Picture and sound watermarks can be weakened by cropping, resizing or re-recording. So a strong signal is good evidence, and no signal proves nothing.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Content credentials sign a record of origin

Content credentials follow an open standard from the C2PA, an industry group. A tool writes a manifest saying who made the file and what was done to it. It binds the manifest to the content with a hash and signs it with a certificate.

A checker recomputes the hash and checks the signature. The lab's script uses a keyed seal from Python as a stand-in for that certificate signature.

Write the credentials checker

Command
docker exec jupyter sh -c "printf '%s\n' 'import hashlib, hmac' 'key = b\"the maker key\"' 'def h(data):' '    return hashlib.sha256(data).hexdigest()' 'def seal_of(claim):' '    return hmac.new(key, claim.encode(), \"sha256\").hexdigest()' 'photo = bytes(range(256)) * 4' 'claim = \"made by camera app, captured, \" + h(photo)' 'seal = seal_of(claim)' 'def verify(name, data, claim, seal):' '    if claim is None:' '        print(name, \"no credentials: nothing either way\")' '    else:' '        print(name, \"seal valid:\", seal == seal_of(claim), \"content matches:\", claim.endswith(h(data)))' 'verify(\"original:\", photo, claim, seal)' 'edited = bytearray(photo)' 'edited[100] = 0' 'verify(\"one byte edited:\", bytes(edited), claim, seal)' 'verify(\"claim changed:\", photo, claim.replace(\"camera app\", \"news agency\"), seal)' 'verify(\"stripped:\", photo, None, None)' > steps/cred.py"

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Check a file four ways

Command
docker exec jupyter python3 steps/cred.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

What cred.py printed

FileSeal validContent matchesWhat it tells you
OriginalTrueTrueThis tool signed this exact content
One byte editedTrueFalseChanged after signing
Claim changed to a news agencyFalseTrueThe record was forged
Credentials strippedNothing either way

The cells students fill in are left blank in this preview.

A common mistake

Warning

Many people think media with no credentials or watermark must be fake, or must be real. Most files carry neither, and both can be stripped. Missing provenance is no evidence either way, and a valid credential proves who signed, not that the content is true.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Deepfakes cause real harm

A deepfake puts a real person into generated media. The harms are concrete: sexual images made without consent, fraud by a cloned voice or face on a call, and invented clips before an election. Real recordings can also be dismissed as fakes.

Law is catching up. In the UK, sharing a sexually explicit deepfake of a real person without consent is a crime. The EU's AI Act requires deepfakes to be labelled as generated.

Detectors fail more often than they seem

A detector is a discriminative model trained on known fakes. A new generator can fool it, and compression or a re-recording can hide what it looks for.

Even a good detector misleads when fakes are rare. The base rate matters: a small share of false positives on many real items can outnumber every fake it catches.

Worked example: 100,000 videos, 100 fakes

FlaggedNot flagged
100 fakes, 95% caught955
99,900 real, 5% wrongly flagged4,99594,905
Share of flagged that are fake95 / 5,090 = 0.019

The cells students fill in are left blank in this preview.

Try it: the base rate

Code: python
# A deepfake detector on a site that gets 100,000 videos a day.
videos = 100000
fakes = 100                # 1 in 1,000 is a deepfake
catches = 0.95             # it flags 95% of the fakes
false_alarms = 0.05        # and wrongly flags 5% of the real videos

caught = fakes * catches
wrongly_flagged = (videos - fakes) * false_alarms
flagged = caught + wrongly_flagged
print("flagged:", flagged)
print("share of flagged that are fake:", round(caught / flagged, 3))
# Change fakes to 10000. What share of the flagged are fake now?

Make a free account to save your work and track your progress.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Assignment: check a watermark

Write a small watermark checker and the base-rate sum.

is_green(token, key) is True when (token * 31 + key) % 100 is below 50. green_count(tokens, key) counts the green tokens in a list. z_score(green, total) gives (green - 0.5 * total) / math.sqrt(0.25 * total) rounded to 2 places. verdict(tokens, key, threshold) gives "watermarked" when the z-score of the tokens is at least threshold, and "no evidence" otherwise: never "human", because no signal proves nothing. flagged_fake(items, fake_share, catch_rate, false_rate) gives the share of flagged items that are really fake, rounded to 3 places.

Code: python
import math


def is_green(token, key):
    return False


def green_count(tokens, key):
    return 0


def z_score(green, total):
    return 0.0


def verdict(tokens, key, threshold):
    return "no evidence"


def flagged_fake(items, fake_share, catch_rate, false_rate):
    return 0.0

Make a free account to save your work and track your progress.

Exit quiz

Have a go

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.