pattern2code / README.md
knguyennguyen's picture
Use the Zenodo concept DOI for the artifact link
48a8688 verified
|
Raw
History Blame Contribute Delete
6.57 kB
metadata
pretty_name: Pattern2Code
license: odc-by
task_categories:
  - image-to-text
  - text-generation
language:
  - en
tags:
  - screenshot-to-code
  - multimodal
  - html
  - css
  - visual-grounding
  - benchmark
size_categories:
  - n<1K
configs:
  - config_name: default
    default: true
    data_files:
      - split: train
        path: data/train-*.parquet
dataset_info:
  features:
    - name: standard_image
      dtype: image
    - name: noise_image
      dtype: image
    - name: example_id
      dtype: string
    - name: source_id
      dtype: string
    - name: pattern_family
      dtype: string
    - name: pattern_name
      dtype: string
    - name: attribute_name
      dtype: string
    - name: attribute_token
      dtype: string
    - name: position
      dtype: string
    - name: target_value
      dtype: string
    - name: target_value_from_filename
      dtype: string
    - name: bias_value
      dtype: string
    - name: pattern_description
      dtype: string
    - name: element_description
      dtype: string
    - name: code_snippet_line
      dtype: string
    - name: code_snippet_context
      dtype: string
    - name: html_path
      dtype: string
    - name: standard_image_path
      dtype: string
    - name: noise_image_path
      dtype: string
    - name: modified_index
      dtype: int32
  splits:
    - name: train
      num_examples: 720

Pattern2Code

Benchmark for the ASE 2026 paper "Pattern Over Pixels: Measuring Pattern Completion Bias in Multimodal Code Generation."

Project page: https://pattern2code.github.io/ · Artifact (Zenodo): https://doi.org/10.5281/zenodo.19341952

Pattern2Code measures visual pattern-completion bias in screenshot-to-code generation: when a webpage contains a repeated UI pattern and exactly one element deviates from it, does a multimodal LLM write the code that matches the pixels, or the code that matches the pattern?

Each example pairs a rendered screenshot with the element's HTML snippet in which the deviating CSS value is masked as __. The model must recover the masked value from the image.

Key results (5 frontier MLLMs)

Family Mean accuracy Mean bias rate
Card patterns (width) 21.17% 69.78%
Text patterns (font-size) 7.89% 80.22%

Bias rate = fraction of predictions equal to the repeated baseline 100%.

Contents

  • 720 perturbed instances = 30 webpages × 2 pattern families × 3 positions × 4 magnitudes
  • 360 structural-card (width) + 360 text-style (font-size) examples
  • 1,440 screenshots — every instance rendered under 2 conditions (standard_image, noise_image)
  • Perturbation magnitudes: 80%, 90%, 110%, 120%; unperturbed baseline is 100%

Layout

data/train-*.parquet         # the dataset: one row per instance, screenshots embedded
data/examples.jsonl          # the same rows as raw JSON (image columns are paths only)
metadata/dataset_info.json   # summary statistics
metadata/validation_report.json
html/{cards,texts}/          # perturbed HTML
images/{cards,texts}/{standard,noise}/   # the screenshots as loose PNG files

The Parquet files carry the screenshots inline, so both image columns render directly in the dataset viewer and decode to PIL.Image with no extra setup. The loose PNGs under images/ are the same files, kept for anyone who wants to work with them outside the datasets library.

Row schema

Field Description
standard_image Image — the rendered screenshot
noise_image Image — the same page with eight opaque rectangles overlaid
example_id Unique instance id
source_id Seed webpage id (Design2Code)
pattern_family structural_card or text_style
pattern_name, pattern_description, element_description The repeated pattern being probed
attribute_name Masked CSS property (width or font_size)
attribute_token The mask token (__)
position Which element was perturbed: first, mid, last
modified_index Index of the perturbed element within the pattern
target_value Ground truth — the perturbed value (e.g. 120%)
bias_value The pattern-consistent baseline (always 100%)
code_snippet_line The masked element's HTML
code_snippet_context Masked element plus its sibling elements (model input)
html_path Relative path to the full perturbed HTML
standard_image_path / noise_image_path Relative paths to the two screenshot files

Loading

from datasets import load_dataset

ds = load_dataset("knguyennguyen/pattern2code", split="train")

ex = ds[0]
ex["standard_image"]        # PIL.Image — already decoded, no cast_column needed
ex["noise_image"]           # PIL.Image
print(ex["attribute_name"], ex["target_value"], "vs baseline", ex["bias_value"])
print(ex["code_snippet_context"])

Evaluation protocol

Prompt the model with standard_image (or noise_image) plus code_snippet_context:

You are doing a visual code fill-in-the-blank task. Given the webpage screenshot
and HTML snippet below, fill the blank token __ with ONLY the missing CSS/HTML
value. The goal is to predict the masked value to recreate the {pattern} in the
webpage design. Return the final answer in JSON format: {"answer":"<value>"}.
The blank must be a percentage value divisible by 10.

Score each prediction into three mutually exclusive outcomes:

  • Correct — equals target_value
  • Bias-aligned — equals bias_value (100%)
  • Other error — neither

Citation

@inproceedings{nguyen2026pattern,
  title     = {Pattern Over Pixels: Measuring Pattern Completion Bias in
               Multimodal Code Generation},
  author    = {Nguyen, Khai-Nguyen and Chaparro, Oscar and Mastropaolo, Antonio},
  booktitle = {Proceedings of the 41st IEEE/ACM International Conference on
               Automated Software Engineering (ASE)},
  year      = {2026}
}

License & provenance

The seed webpages come from the Design2Code dataset, which is released under the Open Data Commons Attribution License (ODC-By) as it is built on the C4 corpus (also ODC-By). All perturbed HTML and screenshots here are derivative works and are redistributed under ODC-By with attribution. Copyright in the original website content remains with the respective site owners; the material is shared for research and reproducibility purposes.