A research project for identifying potentially manipulative interface patterns in website and app screenshots using visual, textual, and structural evidence.
Based on Misleading Patterns — CDS Onboarding, including its model-design diagrams.
The TF-IDF/logistic-regression baseline reached 94.16% accuracy and 0.9414 macro-F1 on a page-grouped holdout of 565 e-commerce texts. All 501 ContextDP screenshots have cached OmniParser regions, CLIP image vectors, and MiniLM element embeddings. Baseline results · Screenshot cache and coverage
On the 99 ContextDP validation screenshots, OCR logistic regression led the single-input models with a platform-averaged macro-F1 of 0.4120. Parser geometry scored highest on mobile at 0.4525. Screenshot baselines, predictions, and reproduction commands
The fusion transformer averaged 0.4511 macro-F1 across web and mobile on the same validation split. The pooled MLP reached 0.4308 and had the higher web score. The epoch-5 transformer checkpoint is frozen for modality ablations. Fusion results, checkpoints, and reproduction commands
Frozen Qwen3-VL-2B-Instruct scored all 557 supported validation pairs using the screenshots and their cached OCR. It reached 0.6909 macro-F1 on web and 0.4141 on mobile, for a platform average of 0.5525. Vision-language results, frozen prompt, and reproduction command
Use Python 3.11, uv for environment/dependency management, scikit-learn for TF-IDF and logistic regression, and PyTorch for the UI encoder and transformer. The prototype runs on CPU.
-
Install uv using the official installation instructions.
-
From the repository root, create the environment and install the locked dependencies:
uv sync --locked
uv manages .venv/ and selects Python 3.11 using .python-version. Commit pyproject.toml, uv.lock, and .python-version; keep the environment and raw dataset/ directory out of Git. See the uv project guide for environment and lockfile behavior.
Run these commands from the repository root. Git ignores dataset/, so each teammate can retrieve the data their work needs. The unit tests and text smoke test run with the samples already in the repository.
Labeled ContextDP manifest. Download the pinned screenshots and annotations and rebuild the shared manifest with one command.
uv run --locked python scripts/prepare_contextdp_manifest.py --downloadThe manifest covers all 501 screenshots and 546 reference boxes. It includes image checksums, cue labels, and a mask for cues each platform omits. Manifest · Schema, category mapping, and counts
Use the frozen split for screenshot experiments. It assigns 299 images to training, 99 to validation, and 103 to test, keeping known sites, apps, and reviewed duplicates together. The protocol includes the per-cue counts, threshold and model-selection rules, and a command to validate a prediction file. Grouped splits and scoring protocol
The screenshot input cache contains raw OCR, generated captions, normalized boxes, and frozen CLIP and MiniLM features keyed by ContextDP ID. The batch commands resume after interruption and audit coverage against both upstream image tables. Rebuild the cache and inspect the development images · Per-image coverage
ContextDP release archive. For the standalone screenshots and annotations, download the AidUI evaluation archive (126 MiB). The checksum verifies that everyone starts with the same release.
mkdir -p dataset
curl -fL --retry 2 -o dataset/contextdp.tar.gz \
"https://github.com/SageSELab/AidUI/releases/download/v-ICSE%2723-data/AidUI-Evaluation-Dataset.tar.gz" &&
echo '55383f9c8bd56870a77d16ddd93897796679cae081e670868fa3511773b2d603 dataset/contextdp.tar.gz' | shasum -a 256 -c - &&
tar -xzf dataset/contextdp.tar.gz -C dataset --strip-components 1 evaluation_dataset/web evaluation_dataset/mobileThis puts 162 web screenshots in dataset/web/images/ and 339 mobile screenshots in dataset/mobile/images/. Each platform has a bounding-boxes.json alongside its images/ directory. For label counts or split preparation, the two annotation files alone are sufficient. The pinned upstream copies are named result.json and match the release annotations. Web annotations · Mobile annotations
E-commerce text corpus. For the full text baseline, the preparation script downloads the pinned Yada et al. corpus to dataset/ec-darkpattern/dataset.tsv and regenerates the 12-row example.
uv run --locked python scripts/prepare_real_dataset_sample.pyRun the text baseline and automated checks through the shared environment:
uv run python baseline.py --data examples/baseline_sample.jsonl
uv run python -m unittest discover -s tests -vThe baseline uses a stratified 75/25 split with seed 42 and fits TF-IDF only on
training text. It prints held-out texts, true labels, and predictions. The eight
manual transcriptions are tracked in examples/baseline_sample.jsonl; their
screenshot IDs and inherited labels are documented in the data report. The tiny
sample checks execution rather than model performance.
After retrieving the e-commerce text corpus, run the sample and full evaluations.
uv run python baseline.py --data examples/ec_darkpattern_sample.jsonl
uv run python baseline.py --ec-darkpattern dataset/ec-darkpattern/dataset.tsv \
--output dataset/ec-darkpattern/baseline_result.jsonThe full run uses all 2,356 source rows before removing 98 normalized-text duplicates. Pages sharing duplicate text stay together. A fixed grouped split (seed 42) yields 1,693 training and 565 held-out texts, with TF-IDF fitted only on training text. The JSON records dataset checksum, split IDs, leakage checks, metrics, a majority-class comparison, and held-out probabilities. See the results and limitations.
First export the screenshot's UI elements with OmniParser, following the isolated environment and weight setup:
dataset/.venv-omniparser/bin/python parse_ui.py \
--image dataset/web/images/knockaround.com.png --sample-id web:6 \
--output-dir dataset/parsed/web-6The wrapper saves elements.json with normalized [x1,y1,x2,y2] boxes,
native.json with OCR/caption provenance, and annotated.png. The report includes
a screenshot download command and observed parsing errors. OmniParser runs in a
separate Python 3.12 environment because its inference dependencies use
Transformers 4; the shared CLIP/MiniLM environment uses Transformers 5.
Run the screenshot and its exported elements through fusion:
uv run python fusion_model.py \
--image dataset/web/images/knockaround.com.png \
--elements dataset/parsed/web-6/elements.jsonThe first run downloads pinned CLIP and MiniLM checkpoints into the Hugging Face
cache. The demonstration checks finite logits and backward gradients through the
UI projection and fusion model, while both pretrained encoders remain frozen.
The demo initializes a fresh adapter projection and binary classifier and uses a demonstration target.
The real web:6 run produced [1,59,256] UI tokens and [1,1] logits and passed
all forward/backward checks. CLIP center-crops its input to 224 × 224, so its image features can miss content near the edges of wide or tall screenshots.
ui_encoder.py loads the parser's {sample_id, elements} JSON
and preserves element order, text, and normalized [x1,y1,x2,y2] boxes.
MiniLM-L6-v2
provides a 384-dimensional text embedding using attention-masked mean pooling and
L2 normalization. Each text is truncated to 256 wordpieces. A trainable linear
projection maps the text embedding plus four box coordinates (388 → 256) to a
UI token. OCR text and generated descriptions are embedded as exported;
native.json retains their provenance. No element-count truncation is applied.
load_ui_adapter() returns an adapter whose forward method accepts a list of
records from load_ui_record(path) or parse_ui.export_elements(...):
ui_tokens, ui_padding_mask = adapter(records)
logits = model(ui_tokens, image_features, ui_padding_mask)Tokens have shape [B,N,256], where N is the largest element count in the batch.
The boolean mask has shape [B,N]; True marks padding. Fusion prepends an
unmasked image token, so empty element lists remain valid. An entirely empty-UI
batch uses [B,0,256] tokens. MiniLM remains frozen and in evaluation mode when
the adapter is switched to training; train the adapter's projection alongside
the fusion model.
The automated tests run without model downloads and check manifest coverage, platform-specific labels, sample integration, grouped splitting, duplicate handling, metrics, pooling, geometry, variable-length batches, empty UI, padding invariance, and gradient isolation.
Compare text-only, vision-only, UI-structure, and multimodal approaches to determine which signals help identify dark patterns. The intended output is a set of pattern predictions with scores and supporting UI elements or regions.
The onboarding document also proposes a smaller click-to-cancel MVP: parse an interface with OmniParser and use a model to assess cancellation-related UI. Verifying that cancellation actually succeeds would require interaction evidence beyond a single screenshot. The MVP and the broader research pipeline are separate possible implementation scopes.
| Candidate category | Example evidence | Interpretation limit |
|---|---|---|
| False urgency | Countdown timers or urgency language | A screenshot can reveal urgency cues, but cannot establish that the urgency is false. |
| Visual interference | A prominent Accept button and a low-visibility Reject button | Assess relative size, contrast, and placement in context. |
| Hidden costs | Fee disclosures in small or low-visibility text | Additional screens or pricing context may be needed to establish that a cost was hidden. |
| Confirmshaming | Emotionally manipulative refusal wording | Retain the exact text and its surrounding choice. |
| Sneaking / preselection | A paid optional add-on already selected | Selection state and pricing context are relevant evidence. |
Multiple categories may apply to one screenshot. An insufficient evidence outcome should be distinct from a negative prediction. The model-design diagram uses related labels such as urgency/scarcity cues and low-visibility disclosures; the final taxonomy must reconcile these observable cues with the broader categories above.
The design combines parsed UI elements with a full-image visual branch that preserves information the parser may miss.
flowchart TD
A[UI screenshot] --> B[OmniParser and OCR]
A --> C[Full-image visual encoder]
B --> D[Element crops, text, roles, and bounding boxes]
D --> E[Visual, text, and structural encoders]
E --> F[Element-level multimodal fusion]
F --> G[Relational transformer]
C --> G
G --> H[Multi-label classification]
G --> I[Evidence localization]
| Component | Responsibility | Candidates in the onboarding document |
|---|---|---|
| Input processing | Load screenshots and optional HTML | Pillow, BeautifulSoup |
| UI parsing | Extract text, UI regions, bounding boxes, and element roles | OmniParser V2, AidUI UIED, OCR |
| Visual encoding | Represent the screenshot and individual element crops | CLIP / ViT, ResNet |
| Text encoding | Represent UI wording | MiniLM, DeBERTa-v3-small, BERT, RoBERTa |
| Structural encoding | Represent geometry, relative prominence, contrast, and roles | OpenCV, bounding-box features, MLP |
| Fusion | Combine visual, text, and structural representations | Concatenation with an MLP; relational or cross-modal attention |
| Prediction | Produce pattern scores and supporting regions | Multi-label sigmoid classifier, element-localization head |
| Results interface | Present predictions and evidence | React with FastAPI, if a demo is included in a later scope |
For element i, the proposed fusion is z_i = MLP([v_i; t_i; s_i]), where v_i, t_i, and s_i are its visual, textual, and structural embeddings. The model-design diagrams propose a shared 256-dimensional representation and a relational transformer with two layers and eight attention heads.
The source contains two related transformer designs: one combines element tokens with full-image patch tokens; the other uses an Element-Aware Multimodal Transformer (EAMT) with a global screenshot token and a maximum of 64 UI elements. These are design candidates, not a finalized implementation. The choice of global representation, element-selection policy, and localization supervision remains open.
ContextDP is the recommended starting point for a screenshot-based experiment. It includes web and mobile screenshots with dark-pattern categories and bounding-box annotations, making it suitable for comparing text-only, visual, and UI-element approaches. The AidUI paper describes its construction and evaluation.
- Access: See Retrieving the datasets for the release archive and annotation files.
- Size: The authors report 162 web and 339 mobile screenshots, depicting 301 dark-pattern and 243 non-dark-pattern instances. These are instance counts, not counts of positive and negative screenshots; a screenshot can contain multiple instances.
- Annotations: The manifest resolves category IDs separately for web and mobile. Each positive cue has one screenshot-level label and retains every associated reference box.
- Text: The inspected annotation files do not include transcribed UI text. Extract it from screenshots with OCR or OmniParser for the text baseline and review extraction quality.
- Scope and limitations: ContextDP is small and consists of static screenshots. It cannot establish behavior across a user journey, such as whether cancellation succeeds. The frozen evaluation reports four test screenshots with unresolved source identity separately. Confirm dataset reuse terms before redistribution or publication; the repository's code license does not by itself establish rights to every screenshot.
Two web screenshots each have a second box for the same cue. The 303 positive boxes therefore correspond to 301 distinct positive screenshot–cue pairs, matching AidUI's classification count. The remaining 243 annotations are NO DP. Manifest audit
Track the screenshot benchmark, model comparisons, and detector release in the project milestones.
The prototype uses ContextDP screenshots, Microsoft OmniParser, and OpenAI CLIP.
External source checkouts, screenshots, and generated parsing outputs stay under
the ignored dataset/ directory; CLIP weights use the Hugging Face cache.