Invisible Watermarks and File Provenance for AI-Generated Content

    This article explains why AI-generated text, images, and code need provenance signals, and how two complementary layers—text watermarks and file provenance metadata—address different tracing problems. It covers the green-list bias method for text watermarking, a z-score detection approach, the limits of statistical watermark detection, and why claims that watermarking does not change meaning require careful interpretation.

    1. Why Mark AI-Generated Content

    The volume of text, images, and code generated by large models is growing quickly, and content origin is becoming harder to determine. Platforms need to answer several questions: Was this text generated by a model? Has this file been processed by AI? Was the content modified as it spread? Manual review or keyword-based rules are difficult to apply at scale.

    In this context, service providers generally use two approaches. One embeds a mark directly into the content so that the mark travels with the content. The other attaches externally verifiable metadata to the content, records the generation source, and uses signatures to ensure integrity. Each approach has its own applicable scenarios, and practical systems often combine them. Regulatory requirements for labeling AI-generated content are also increasing in various regions, so enterprises need to prepare at the technical level.

    2. Basic Architecture of Two Marking Layers

    A complete marking scheme usually consists of two independent layers.

    Dimension Text watermark layer File provenance metadata layer
    Carrier Token selection distribution in text Signed manifest attached to the file
    Activation point Model generation stage File output stage
    Dependency on external metadata No; embedded in the text Yes; depends on file format support
    Coverage All text output Supported file types
    Primary use Determine whether text came from a model Determine whether a file was processed or tampered with
    Main weakness Signal weakens after substantial rewriting Format conversion or platform processing may strip metadata

    The two layers have different design goals. The goal of a text watermark is to let the mark follow the content, so that detection remains possible even if the content is copied elsewhere. The goal of a file signature is to provide verifiable proof of the file’s generation source and to produce a clear invalidation signal if the file is modified. Relying on either layer alone is therefore insufficient to cover all scenarios.

    3. How Text Watermarking Works

    3.1 Green Lists and Bias

    The mainstream approach to text watermarking introduces a controllable statistical bias during generation. Each time the model generates a token, it first produces a set of scores (logits) for all candidate tokens. Before sampling, the watermarking scheme uses the previous token and a key known only to the service provider to deterministically divide the entire vocabulary into two groups: a green list and a red list. During sampling, candidates in the green list receive a small boost, making the model more likely to choose them.

    The effect of this bias on any single token is small, and readers usually cannot perceive it. After accumulation over many tokens, however, the proportion of green-list tokens will be clearly higher than the random level. This is the basis for detection.

    The following is an illustrative implementation for teaching purposes only. It explains the principle and is not the scheme of any specific product.

    1. import hashlib
    2. import random
    3. def green_list(prev_token_id: int, vocab_size: int,
    4. gamma: float = 0.5, key: str = "secret-key") -> set[int]:
    5. """Deterministically define the green list based on the previous token and key."""
    6. seed_bytes = hashlib.sha256(f"{key}:{prev_token_id}".encode()).digest()
    7. rng = random.Random(int.from_bytes(seed_bytes[:8], "big"))
    8. tokens = list(range(vocab_size))
    9. rng.shuffle(tokens)
    10. return set(tokens[: int(vocab_size * gamma)])
    11. def biased_logits(logits: list[float], prev_token_id: int,
    12. delta: float = 2.0, gamma: float = 0.5) -> list[float]:
    13. """Add a fixed bias to candidate tokens in the green list."""
    14. green = green_list(prev_token_id, len(logits), gamma)
    15. return [x + delta if i in green else x for i, x in enumerate(logits)]

    In the illustrative code, each step shuffles the entire vocabulary, which is inefficient. Real systems cache and optimize the partitioning result. The important point here is the logic: the bias is determined by the key and the context, and anyone without the key cannot know in advance which tokens will be boosted.

    3.2 Detection and Statistical Testing

    After obtaining a piece of text, the detector needs to know the key and partitioning rule used during generation. The detection process counts how many tokens in the text fall into the corresponding green lists and compares that number with the random level.

    Assume the text has n token pairs, hits of them fall into green lists, and the green-list proportion is gamma. Without a watermark, the expected value of hits is gamma × n, and the standard deviation is √(n × gamma × (1 − gamma)). Dividing the difference between the two by the standard deviation gives a z-score.

    1. import math
    2. def detect_watermark(token_ids: list[int], vocab_size: int,
    3. gamma: float = 0.5, key: str = "secret-key") -> float:
    4. """Return the z-score. A larger z-score means the text looks more like watermarked output."""
    5. pairs = list(zip(token_ids[:-1], token_ids[1:]))
    6. n = len(pairs)
    7. if n == 0:
    8. return 0.0
    9. hits = sum(1 for prev, cur in pairs
    10. if cur in green_list(prev, vocab_size, gamma, key))
    11. expected = gamma * n
    12. std = math.sqrt(n * gamma * (1 - gamma))
    13. return (hits - expected) / std

    For ordinary human-written text, the z-score should be close to 0. The decision threshold needs to be determined according to the acceptable false-positive rate. The shorter the text, the lower the statistical power, and detection results for short sentences are unreliable. This is also why detection results should be treated as probabilistic evidence rather than absolute conclusions.

    3.3 Why “No Meaning Change” Is Difficult to Guarantee

    Service providers often emphasize that watermarks do not affect text quality. In principle, this claim needs to be understood carefully. Statistical bias does change the probability of token selection, but it generally operates only among multiple semantically reasonable candidates. As a result, the meaning of the text usually remains unchanged, while the distribution of wording differs slightly.

    In contrast, another class of schemes leaves fingerprints by replacing fixed words or adjusting phrasing. Such methods change the surface form of the text, may be noticeable to readers, and are easier to remove through manual rewriting. If a provider explicitly promises not to change meaning, that claim should be interpreted carefully.