Download scripts/validate_release.py from ChrisDing1105/ARMBench-VL: direct link, hf CLI and curl.
- Browser
- Download file 3.24 kB
-
https://huggingface.co/datasets/ChrisDing1105/ARMBench-VL/resolve/main/scripts/validate_release.py
- Command line
-
hf download hf://datasets/ChrisDing1105/ARMBench-VL/scripts/validate_release.py
-
curl -L -o validate_release.py https://huggingface.co/datasets/ChrisDing1105/ARMBench-VL/resolve/main/scripts/validate_release.py
3.24 kB
| """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()) | |