File size: 6,841 Bytes
41e2b8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
"""
The dataset ships two Parquet configs under `data/`:

    canonical.parquet        652 rows β€” full benchmark; drives file-level eval
    function_level.parquet   343 rows β€” subset where edit_functions is non-empty

This script walks through both evaluation granularities (file-level and
function-level), decodes an image, reads a 20-row VCE+ preview from
`examples/preview/vce_plus_preview.jsonl`, and shows how to materialize
the underlying GitHub repository snapshot required at scoring time.

Run:
    python3 examples/load_dataset.py
"""

from __future__ import annotations

import json
from pathlib import Path

from datasets import Dataset

ROOT = Path(__file__).resolve().parent.parent
DATA = ROOT / "data"

ds = Dataset.from_parquet(str(DATA / "canonical.parquet"))
ds_fn = Dataset.from_parquet(str(DATA / "function_level.parquet"))

print(f"canonical:      {len(ds):4d} rows   (file-level eval β€” all edit_files non-empty)")
print(f"function_level: {len(ds_fn):4d} rows   (function-level eval β€” strict subset)")


# ===========================================================================
# 1. File-level evaluation
# ===========================================================================
# Input : issue_title + issue_body + images + (repo snapshot at base_commit)
# Output: ranked list of files to edit
# Gold  : row["edit_files"]  β€” always non-empty in the canonical config.
# ===========================================================================

row = ds[0]
print(f"\n── file-level example ──────────────────────────────────────────────")
print(f"  instance_id  : {row['instance_id']}")
print(f"  repo @ commit: {row['repo_full_name']} @ {row['base_commit'][:12]}")
print(f"  language     : {row['language']} ({row['language_category']})")
print(f"  difficulty   : {row['difficulty']}  (changed_files={row['changed_files']})")
print(f"  # images     : {len(row['images'])}")
print(f"  gold files   : {row['edit_files']}")
print(f"  (your model must rank {row['edit_files'][0]!r} near the top)")

# Decode the first screenshot β€” HF Image feature returns PIL.Image automatically.
img = row["images"][0]
print(f"  image[0]     : {img.size} px, mode={img.mode}, caption={row['image_alts'][0]!r}")
# img.save("first_issue_screenshot.png")  # persist for visual inspection


# ===========================================================================
# 2. Function-level evaluation
# ===========================================================================
# Input : same as file-level
# Output: ranked list of `path/to/file:function` identifiers
# Gold  : row["edit_functions"] (always non-empty in the function_level config)
# Caveat: exclude row["added_functions"] when scoring β€” those functions do
#         not exist at base_commit, so they cannot be retrieved from the
#         repository tree.
# ===========================================================================

fn_row = ds_fn[0]
print(f"\n── function-level example ──────────────────────────────────────────")
print(f"  instance_id    : {fn_row['instance_id']}")
print(f"  edit_functions : {fn_row['edit_functions']}")
print(f"  added_functions: {fn_row['added_functions']}  ← exclude from scoring")
print(f"  supports_function_level: {fn_row['supports_function_level']}")

# Pick any instance that is ONLY file-level (no function annotation) to
# illustrate the filter that separates the two configs.
file_only = next(r for r in ds if not r["supports_function_level"] or not r["edit_functions"])
print(f"\n  (a file-level-only instance in canonical but NOT in function_level)")
print(f"  instance_id                   : {file_only['instance_id']}")
print(f"  supports_function_level       : {file_only['supports_function_level']}")
print(f"  edit_functions (empty here!)  : {file_only['edit_functions']}")


# ===========================================================================
# 3. VCE+ preview (illustrative; not a shipped config)
# ===========================================================================
# VCE+ is a 7-dimensional structured extraction per screenshot (OCR, error
# signal, UI elements, user action, code hints, visual saliency, confidence)
# produced by a multimodal LLM. The FULL cache is a rerunnable byproduct and
# is NOT shipped in data/. A 20-row preview aligned by instance_id with
# examples/preview/preview.jsonl ships at examples/preview/vce_plus_preview.jsonl
# so the schema stays discoverable without running the extractor.
# ===========================================================================

vce_preview_path = ROOT / "examples" / "preview" / "vce_plus_preview.jsonl"
vce_rows = [json.loads(l) for l in vce_preview_path.open()]
print(f"\n── VCE+ preview (20 records) ──────────────────────────────────────")
print(f"  path: {vce_preview_path.relative_to(ROOT)}  ({len(vce_rows)} rows)")
vce_row = vce_rows[0]
print(f"  sample instance_id: {vce_row['instance_id']}  (category={vce_row['category']})")
for i, rec in enumerate(vce_row["records"]):
    err = rec["error_signal"] or {}
    ch = rec["code_hint"] or {}
    print(
        f"  record[{i}]: conf={rec.get('confidence', 0.0):.2f}  "
        f"error={err.get('kind', '')}/{err.get('type', '')!r}  "
        f"ui_elements={(rec.get('ui_elements') or [])[:3]}  "
        f"frameworks={ch.get('frameworks', [])}"
    )


# ===========================================================================
# 4. Repository snapshots
# ===========================================================================
# Scoring requires the repository tree at each row's base_commit. Repos are
# not embedded in the Parquet (they would total several GB and carry
# heterogeneous upstream licenses). Use commit_cache.json + the bundled
# script to fetch them:
#
#     export GITHUB_TOKEN=ghp_xxx
#     python3 scripts/download_repos.py         # fetch all 653 repos
#     python3 scripts/download_repos.py --only 5  # dry-run slice
# ===========================================================================

cache = json.loads((ROOT / "commit_cache.json").read_text())
entry = cache[row["instance_id"]]
print(f"\n── repo snapshot for the file-level example ─────────────────────────")
print(f"  expected directory: repos/{entry['dir_name']}/")
print(f"  equivalent to     :")
print(f"    git clone https://github.com/{entry['repo']} {entry['dir_name']}")
print(f"    git -C {entry['dir_name']} checkout {entry['sha']}")
print(f"  (or run: python3 scripts/download_repos.py  β€” see scripts/download_repos.py)")