ADVERTISING / NOTEBOOK LESSON

53 · A07 · Context targeting, expansion, and data boundaries

Study context targeting and expansion while keeping data-use boundaries explicit.

Constructed mechanism / simulationRead-only · saved experiment

Saved outputs come from recorded teaching runs; opening this page does not rerun an experiment. The code and original outputs are preserved; original-language data and annotations may remain.

A07 · Context targeting, expansion, and data boundaries

Prerequisites: foundations 31–34; A06.

Evidence: explicitly constructed mechanism experiments, not real ad logs. This chapter does not claim industrial-system reproduction or online gains.

Learning order: predict → change one variable → run → explain.

English companion. All instructional Markdown is translated. Experiment code, Chinese language examples, execution counts, and saved outputs remain as in the source edition; historical output text may therefore be Chinese. The initial setup cell anchors the working directory and Python import path for this companion's deeper folder; it does not change the experiment. Saved outputs are historical evidence, not a new run. Run from the top after preparing the required data and models.

PYTHON · 01
# English companions live one directory deeper; keep the original experiment code unchanged.
from pathlib import Path as _TranslationPath
import os as _translation_os
import sys as _translation_sys
_translation_root = next((p for p in [_TranslationPath.cwd(), *_TranslationPath.cwd().parents]
                          if (p / "reclab").is_dir()), None)
if _translation_root is None:
    raise RuntimeError("Open this notebook from inside the Search Recommendation Ads Lab checkout.")
_translation_os.chdir(_translation_root)
if str(_translation_root) not in _translation_sys.path:
    _translation_sys.path.insert(0, str(_translation_root))

Problem and input/output contract

Advertisers choose target contexts, and platforms match using limited fields. A DMP manages segments and data use; it does not imply unrestricted cross-domain identity joining. This example retains only page_context, without device identifiers or sensitive attributes. Cold start may use current-page context. Expansion increases reach but can reduce precision. Artificial relevance sets are mechanism labels only.

Before running, predict which result the changed variable will affect and which invariants must hold.

PYTHON · 02
from pathlib import Path
import sys
root=Path.cwd()
if not (root/'reclab').exists(): root=root.parent
if str(root) not in sys.path: sys.path.insert(0,str(root))
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from reclab import ads_curriculum as ac

Run the one-variable comparison

Inputs are small constructed examples visible in source. Output units and constraints are defined above. Run assertions to verify mathematics and accounting.

PYTHON · 03
strict=ac.targeting();expanded=ac.targeting(True)
display(pd.DataFrame([strict,expanded],index=['strict','expanded']))
assert expanded['coverage']>strict['coverage']
assert expanded['precision']<strict['precision']
assert strict['fields']==['page_context']
Saved notebook output · not executed on this page
selected coverage precision fields
strict [0, 3] 0.4 1.000000 [page_context]
expanded [0, 1, 3] 0.6 0.666667 [page_context]

Interpretation and limits

One expansion changes only allowed contexts. More coverage does not automatically mean more real conversions, and artificial relevance cannot validate an audience model. Criteo’s anonymous categories have unknown semantics and are not presented as age, interests, or cross-device identities.

Inspect source, then try an exercise

Add an unknown context and design a cold-start fallback. Write allowed fields and retention periods before deciding whether more data is necessary.

PYTHON · 04
import inspect
print(inspect.getsource(ac.targeting))
Saved notebook output · not executed on this page
def targeting(expand=False):
    # Context is deliberately provided; no device ID, inferred sensitive label or join.
    contexts=['运动','生活','旅行','运动','科技']
    allowed={'运动','生活'} if expand else {'运动'}
    chosen=[i for i,c in enumerate(contexts) if c in allowed]
    relevant={0,3}
    return dict(selected=chosen,coverage=len(chosen)/len(contexts),precision=len(set(chosen)&relevant)/max(1,len(chosen)),fields=['page_context'])

Sources and next step

A-RTB pp. 133–148; field minimization is a Lab extension. This is an original Lab exercise, not a copy of the complete lecture text.

Chinese GitHub chapter · Authors’ RTB slides. The Chinese deck is not a complete modern advertising-engineering course. Historical descriptions of platforms are not presented as current market facts.

After the exercise, return to the ads learning path and continue to the next semantic unit.

GO TO THE SOURCE

Sources for this lesson

Author tutorialEnglish

Weinan Zhang / Jian Xu · CIKM 2016 RTB Tutorial

PDF pages 133–148: targeting and expansion

164 author slides covering response prediction, bidding, attribution, pacing, targeting and reserve prices. Lab mechanisms are independently authored, not full paper replications.

Author tutorialEnglish

Weinan Zhang / Jian Xu · CIKM 2016 RTB Tutorial

164-page PDF: unit links open the relevant page

164 author slides covering response prediction, bidding, attribution, pacing, targeting and reserve prices. Lab mechanisms are independently authored, not full paper replications.

Completion marks are optional and stored only in this browser. Reading a page does not mark it complete.