File size: 3,244 Bytes
6a4d673 | 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 | """Validate annotation counts, label distributions, and local resources."""
from __future__ import annotations
import json
import sqlite3
import sys
from collections import Counter
from pathlib import Path
from load_armbench_vl import iter_document_pages, load_records, resolve_images
def main(root: Path) -> None:
config = json.loads((root / "dataset_config.json").read_text(encoding="utf-8"))
errors: list[str] = []
for task, expected in config.items():
records = load_records(root, task)
if len(records) != expected["expected_examples"]:
errors.append(
f"{task}: expected {expected['expected_examples']} examples, "
f"found {len(records)}"
)
actual_tags = Counter(record.get("rm_tag") for record in records)
if dict(actual_tags) != expected["rm_tag_counts"]:
errors.append(
f"{task}: expected rm_tag counts {expected['rm_tag_counts']}, "
f"found {dict(actual_tags)}"
)
for record in records:
for image in resolve_images(root, task, record):
if not image.is_file():
errors.append(f"{task}: missing image {image}")
if task == "multimodal_long_document_qa":
doc_ids = {record["doc_id"] for record in records}
for doc_id in doc_ids:
if not list(iter_document_pages(root, doc_id)):
errors.append(f"{task}: no retrieval pages for {doc_id}")
index_db = root / expected["retrieval_index"] / "chroma.sqlite3"
if not index_db.is_file():
errors.append(f"{task}: missing retrieval index {index_db}")
else:
connection = sqlite3.connect(f"file:{index_db}?mode=ro", uri=True)
collections = {
row[0] for row in connection.execute("SELECT name FROM collections")
}
if expected["retrieval_collection"] not in collections:
errors.append(
f"{task}: missing Chroma collection "
f"{expected['retrieval_collection']}"
)
indexed_docs = {
row[0]
for row in connection.execute(
"SELECT DISTINCT string_value FROM embedding_metadata "
"WHERE key = 'source'"
)
}
expected_docs = {Path(doc_id).stem for doc_id in doc_ids}
missing_docs = expected_docs - indexed_docs
if missing_docs:
errors.append(
f"{task}: {len(missing_docs)} documents are missing from "
"the retrieval index"
)
connection.close()
print(f"validated {task}: {len(records)} examples")
if errors:
print("\n".join(errors[:100]), file=sys.stderr)
raise SystemExit(f"validation failed with {len(errors)} error(s)")
print("ARMBench-VL validation passed: 1,499 examples")
if __name__ == "__main__":
main(Path(sys.argv[1] if len(sys.argv) > 1 else ".").resolve())
|