Datasets:
Add contract test and explicit ontology validation run
Browse files
artifacts/edukacja_medialna_pl_ontology_manifest.json
CHANGED
|
@@ -32,6 +32,7 @@
|
|
| 32 |
"id": "claim:licensed-records",
|
| 33 |
"statement": "Every retained record passed the explicit page and XML CC BY-SA 3.0 gate.",
|
| 34 |
"supported_by": [
|
|
|
|
| 35 |
"evidence:qa:31651600f3fdbd7fead125374f64ed1bd689a5f7fa14389f4d888b858cbeb8f5"
|
| 36 |
]
|
| 37 |
},
|
|
@@ -46,7 +47,7 @@
|
|
| 46 |
"evidence": [
|
| 47 |
{
|
| 48 |
"append_only": true,
|
| 49 |
-
"id": "evidence:checksums:
|
| 50 |
"observation_type": "checksums",
|
| 51 |
"payload": {
|
| 52 |
"NOTICE.md": "ca0ab465674b4d8b2e5db4a1c6d25a5565893b2e48803cf36b319bac3f3461fd",
|
|
@@ -56,12 +57,13 @@
|
|
| 56 |
"artifacts/inventory.json": "2348fc675da837146af683bc548083fa93c43f6e1a2dbdf2408d36a97dbd92d9",
|
| 57 |
"artifacts/qa.json": "95e42a29bd2f1d328efac5f20378311a1806bd934b5bd88d6002a3bbf2ec78dc",
|
| 58 |
"artifacts/raw_xml.jsonl.gz": "828b7ac5f0d2eaf1c49882178363777ed8f74daccac0fcbd485ba9d0fb8369f1",
|
| 59 |
-
"artifacts/run.json": "
|
| 60 |
"artifacts/sample.jsonl": "1d3277d93a5a1b9281ef1c71e745c9669eb2fac4cc78c7e60946557aedc7c1fa",
|
| 61 |
"artifacts/stats.json": "38c7a8418b798021ce217a8bd9c9c120a7b92a7ac8e0cdbf56cb76757eb7b8cf",
|
| 62 |
"data/train-00000-of-00001.parquet": "dbce26650981e8e552c7fdac48bd35c02e9bd0a56fced4ea4871489b5a2365c4",
|
| 63 |
-
"src/build_edukacja_medialna_pl.py": "
|
| 64 |
-
"src/requirements.txt": "a41710470f941a80c9cf2f6ef93357b2478797f00804816e925959fac302100b"
|
|
|
|
| 65 |
}
|
| 66 |
},
|
| 67 |
{
|
|
@@ -88,6 +90,19 @@
|
|
| 88 |
"labelled_phone": 0
|
| 89 |
}
|
| 90 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
}
|
| 92 |
],
|
| 93 |
"objects": [
|
|
@@ -122,30 +137,52 @@
|
|
| 122 |
"source_scope": "https://edukacjamedialna.edu.pl/lekcje/",
|
| 123 |
"tokenizer": "tiktoken cl100k_base"
|
| 124 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
}
|
| 126 |
],
|
| 127 |
"relations": [
|
| 128 |
{
|
| 129 |
"predicate": "DERIVED_FROM",
|
| 130 |
-
"source": "version:data:
|
| 131 |
"target": "version:source:9bca86eeedc6f04b29ecab5e704112aecd70eb88426b3b676ea7ee8101254a69"
|
| 132 |
},
|
| 133 |
{
|
| 134 |
"predicate": "FILTERED_BY",
|
| 135 |
-
"source": "version:data:
|
| 136 |
"target": "protocol:6d6b7e7a3d456dff4d5b6c6a6ade6d7c352582ca6c4bccf4e46f49a132517821"
|
| 137 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
{
|
| 139 |
"predicate": "COMPATIBLE_WITH",
|
| 140 |
-
"source": "version:data:
|
| 141 |
"target": "hf://datasets/SlayerLab/polish-dynaword@a916edecabc2be8832e08fb2bd9dfafcc1d2dd71"
|
| 142 |
}
|
| 143 |
],
|
| 144 |
"runs": [
|
| 145 |
{
|
| 146 |
-
"code_sha256": "
|
| 147 |
-
"finished_at": "2026-09-06T15:
|
| 148 |
-
"id": "run:
|
| 149 |
"inputs": {
|
| 150 |
"listing_sha256": "3b419c4637991185bcfe883240256164b8bb14d176dea2d6523e36abe7c9444a",
|
| 151 |
"xml_sha256": [
|
|
@@ -419,6 +456,14 @@
|
|
| 419 |
"tokens": 728987
|
| 420 |
},
|
| 421 |
"success": true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
}
|
| 423 |
],
|
| 424 |
"schema_version": "slayer-research-ontology/0.1-profile",
|
|
@@ -430,8 +475,8 @@
|
|
| 430 |
"object_id": "object:edukacja-medialna-source"
|
| 431 |
},
|
| 432 |
{
|
| 433 |
-
"digest": "sha256:
|
| 434 |
-
"id": "version:data:
|
| 435 |
"immutable": true,
|
| 436 |
"object_id": "object:edukacja-medialna-derived"
|
| 437 |
}
|
|
|
|
| 32 |
"id": "claim:licensed-records",
|
| 33 |
"statement": "Every retained record passed the explicit page and XML CC BY-SA 3.0 gate.",
|
| 34 |
"supported_by": [
|
| 35 |
+
"evidence:checksums:ea342412e4e8fa48154de774fe55336d50c0f8b726c17a8904d43701e449ebd1",
|
| 36 |
"evidence:qa:31651600f3fdbd7fead125374f64ed1bd689a5f7fa14389f4d888b858cbeb8f5"
|
| 37 |
]
|
| 38 |
},
|
|
|
|
| 47 |
"evidence": [
|
| 48 |
{
|
| 49 |
"append_only": true,
|
| 50 |
+
"id": "evidence:checksums:ea342412e4e8fa48154de774fe55336d50c0f8b726c17a8904d43701e449ebd1",
|
| 51 |
"observation_type": "checksums",
|
| 52 |
"payload": {
|
| 53 |
"NOTICE.md": "ca0ab465674b4d8b2e5db4a1c6d25a5565893b2e48803cf36b319bac3f3461fd",
|
|
|
|
| 57 |
"artifacts/inventory.json": "2348fc675da837146af683bc548083fa93c43f6e1a2dbdf2408d36a97dbd92d9",
|
| 58 |
"artifacts/qa.json": "95e42a29bd2f1d328efac5f20378311a1806bd934b5bd88d6002a3bbf2ec78dc",
|
| 59 |
"artifacts/raw_xml.jsonl.gz": "828b7ac5f0d2eaf1c49882178363777ed8f74daccac0fcbd485ba9d0fb8369f1",
|
| 60 |
+
"artifacts/run.json": "07306bf4f5b8199dcba0d28442fa4fa38d8f9a684f976451b223e93138762f08",
|
| 61 |
"artifacts/sample.jsonl": "1d3277d93a5a1b9281ef1c71e745c9669eb2fac4cc78c7e60946557aedc7c1fa",
|
| 62 |
"artifacts/stats.json": "38c7a8418b798021ce217a8bd9c9c120a7b92a7ac8e0cdbf56cb76757eb7b8cf",
|
| 63 |
"data/train-00000-of-00001.parquet": "dbce26650981e8e552c7fdac48bd35c02e9bd0a56fced4ea4871489b5a2365c4",
|
| 64 |
+
"src/build_edukacja_medialna_pl.py": "6ded00d84d4f6686f53c05f99caabcaf8ec59cebf7027a63342612d214a5aaf4",
|
| 65 |
+
"src/requirements.txt": "a41710470f941a80c9cf2f6ef93357b2478797f00804816e925959fac302100b",
|
| 66 |
+
"src/test_edukacja_medialna_contribution.py": "79fcbb1d7018cac395e3dd405ad907e5043482c6e4cf6f1d1b4611f05fc05f78"
|
| 67 |
}
|
| 68 |
},
|
| 69 |
{
|
|
|
|
| 90 |
"labelled_phone": 0
|
| 91 |
}
|
| 92 |
}
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
"append_only": true,
|
| 96 |
+
"id": "evidence:validation:a18fc04225ac65cdee43834e35e8ebc1bba24163859ca59b4fc96d4078040b25",
|
| 97 |
+
"observation_type": "contract_validation",
|
| 98 |
+
"payload": {
|
| 99 |
+
"code_sha256": "79fcbb1d7018cac395e3dd405ad907e5043482c6e4cf6f1d1b4611f05fc05f78",
|
| 100 |
+
"finished_at": "2026-09-06T15:45:04.834732+00:00",
|
| 101 |
+
"id": "run:validation:0bfcd53334db42b0c23eaeac7485ee45a055ac45dd51288de45206c2259f5b08",
|
| 102 |
+
"result": "local contract validation passed",
|
| 103 |
+
"started_at": "2026-09-06T15:45:04.834732+00:00",
|
| 104 |
+
"success": true
|
| 105 |
+
}
|
| 106 |
}
|
| 107 |
],
|
| 108 |
"objects": [
|
|
|
|
| 137 |
"source_scope": "https://edukacjamedialna.edu.pl/lekcje/",
|
| 138 |
"tokenizer": "tiktoken cl100k_base"
|
| 139 |
}
|
| 140 |
+
},
|
| 141 |
+
{
|
| 142 |
+
"digest": "sha256:ea264792613d37232fb335cd94ce0adf98ffc43fc88b4895cf7100f9160b5d1b",
|
| 143 |
+
"id": "protocol:ea264792613d37232fb335cd94ce0adf98ffc43fc88b4895cf7100f9160b5d1b",
|
| 144 |
+
"specification": {
|
| 145 |
+
"checks": [
|
| 146 |
+
"schema",
|
| 147 |
+
"counts",
|
| 148 |
+
"license",
|
| 149 |
+
"author attribution",
|
| 150 |
+
"PII patterns",
|
| 151 |
+
"samples",
|
| 152 |
+
"content addresses",
|
| 153 |
+
"acyclic lineage"
|
| 154 |
+
],
|
| 155 |
+
"name": "edukacja-medialna-contract-v1"
|
| 156 |
+
}
|
| 157 |
}
|
| 158 |
],
|
| 159 |
"relations": [
|
| 160 |
{
|
| 161 |
"predicate": "DERIVED_FROM",
|
| 162 |
+
"source": "version:data:ea342412e4e8fa48154de774fe55336d50c0f8b726c17a8904d43701e449ebd1",
|
| 163 |
"target": "version:source:9bca86eeedc6f04b29ecab5e704112aecd70eb88426b3b676ea7ee8101254a69"
|
| 164 |
},
|
| 165 |
{
|
| 166 |
"predicate": "FILTERED_BY",
|
| 167 |
+
"source": "version:data:ea342412e4e8fa48154de774fe55336d50c0f8b726c17a8904d43701e449ebd1",
|
| 168 |
"target": "protocol:6d6b7e7a3d456dff4d5b6c6a6ade6d7c352582ca6c4bccf4e46f49a132517821"
|
| 169 |
},
|
| 170 |
+
{
|
| 171 |
+
"predicate": "VALIDATED_AGAINST",
|
| 172 |
+
"source": "version:data:ea342412e4e8fa48154de774fe55336d50c0f8b726c17a8904d43701e449ebd1",
|
| 173 |
+
"target": "protocol:ea264792613d37232fb335cd94ce0adf98ffc43fc88b4895cf7100f9160b5d1b"
|
| 174 |
+
},
|
| 175 |
{
|
| 176 |
"predicate": "COMPATIBLE_WITH",
|
| 177 |
+
"source": "version:data:ea342412e4e8fa48154de774fe55336d50c0f8b726c17a8904d43701e449ebd1",
|
| 178 |
"target": "hf://datasets/SlayerLab/polish-dynaword@a916edecabc2be8832e08fb2bd9dfafcc1d2dd71"
|
| 179 |
}
|
| 180 |
],
|
| 181 |
"runs": [
|
| 182 |
{
|
| 183 |
+
"code_sha256": "6ded00d84d4f6686f53c05f99caabcaf8ec59cebf7027a63342612d214a5aaf4",
|
| 184 |
+
"finished_at": "2026-09-06T15:44:48.898663+00:00",
|
| 185 |
+
"id": "run:30db02148d6e7afa693a38702bbfb5049975f07286eb7a51e0274b2bc1e0c2e3",
|
| 186 |
"inputs": {
|
| 187 |
"listing_sha256": "3b419c4637991185bcfe883240256164b8bb14d176dea2d6523e36abe7c9444a",
|
| 188 |
"xml_sha256": [
|
|
|
|
| 456 |
"tokens": 728987
|
| 457 |
},
|
| 458 |
"success": true
|
| 459 |
+
},
|
| 460 |
+
{
|
| 461 |
+
"code_sha256": "79fcbb1d7018cac395e3dd405ad907e5043482c6e4cf6f1d1b4611f05fc05f78",
|
| 462 |
+
"finished_at": "2026-09-06T15:45:04.834732+00:00",
|
| 463 |
+
"id": "run:validation:0bfcd53334db42b0c23eaeac7485ee45a055ac45dd51288de45206c2259f5b08",
|
| 464 |
+
"result": "local contract validation passed",
|
| 465 |
+
"started_at": "2026-09-06T15:45:04.834732+00:00",
|
| 466 |
+
"success": true
|
| 467 |
}
|
| 468 |
],
|
| 469 |
"schema_version": "slayer-research-ontology/0.1-profile",
|
|
|
|
| 475 |
"object_id": "object:edukacja-medialna-source"
|
| 476 |
},
|
| 477 |
{
|
| 478 |
+
"digest": "sha256:ea342412e4e8fa48154de774fe55336d50c0f8b726c17a8904d43701e449ebd1",
|
| 479 |
+
"id": "version:data:ea342412e4e8fa48154de774fe55336d50c0f8b726c17a8904d43701e449ebd1",
|
| 480 |
"immutable": true,
|
| 481 |
"object_id": "object:edukacja-medialna-derived"
|
| 482 |
}
|
src/build_edukacja_medialna_pl.py
CHANGED
|
@@ -339,23 +339,33 @@ def prepare(out, target_revision):
|
|
| 339 |
(root / "src").mkdir(parents=True, exist_ok=True)
|
| 340 |
shutil.copy2(Path(__file__), root / "src/build_edukacja_medialna_pl.py")
|
| 341 |
shutil.copy2(Path(__file__).with_name("edukacja_medialna_requirements.txt"), root / "src/requirements.txt")
|
|
|
|
| 342 |
checksums = make_checksums(root)
|
| 343 |
save(root / "artifacts/checksums.json", checksums)
|
| 344 |
protocol = {"name": "edukacja-medialna-direct-xml-v1", "source_scope": LISTING,
|
| 345 |
"license_gate": "explicit CC BY-SA 3.0 on page and XML", "selection": "Polish, >=300 body chars, creator present, no PII pattern match",
|
| 346 |
"dedup": "normalized exact then seeded MinHash/Jaccard", "tokenizer": "tiktoken cl100k_base", "schema": FIELDS}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 347 |
ontology = {"schema_version": "slayer-research-ontology/0.1-profile",
|
| 348 |
"objects": [{"id": "object:edukacja-medialna-source", "type": "DatasetSource"}, {"id": "object:edukacja-medialna-derived", "type": "Dataset"}],
|
| 349 |
"versions": [{"id": "version:source:" + sha(load(out / "inventory.json")), "object_id": "object:edukacja-medialna-source", "digest": "sha256:" + sha(load(out / "inventory.json")), "immutable": True},
|
| 350 |
{"id": "version:data:" + sha(checksums), "object_id": "object:edukacja-medialna-derived", "digest": "sha256:" + sha(checksums), "immutable": True}],
|
| 351 |
-
"protocols": [{"id": "protocol:" + sha(protocol), "specification": protocol, "digest": "sha256:" + sha(protocol)}
|
| 352 |
-
|
|
|
|
| 353 |
"relations": [{"source": "version:data:" + sha(checksums), "predicate": "DERIVED_FROM", "target": "version:source:" + sha(load(out / "inventory.json"))},
|
| 354 |
{"source": "version:data:" + sha(checksums), "predicate": "FILTERED_BY", "target": "protocol:" + sha(protocol)},
|
|
|
|
| 355 |
{"source": "version:data:" + sha(checksums), "predicate": "COMPATIBLE_WITH", "target": "hf://datasets/" + TARGET + "@" + target_revision}],
|
| 356 |
-
"evidence": [{"id":
|
| 357 |
-
{"id":
|
| 358 |
-
|
|
|
|
| 359 |
{"id": "claim:diversity-hypothesis", "statement": "This instructional media-literacy source may diversify a legal-heavy Polish pretraining mix.", "supported_by": [], "falsification_condition": "Controlled mix ablations show no relevant improvement or harmful style contamination.", "status": "untested"}],
|
| 360 |
"actors": [{"id": "hf:PiotrSty", "type": "human", "name": "Piotr Styla"}, {"id": "agent:codex", "type": "agent", "name": "OpenAI Codex"}, {"id": "org:fnp", "type": "organization", "name": "Fundacja Nowoczesna Polska"}],
|
| 361 |
"attestations": [{"type": "cross_source_deduplication", "value": "pending_target_integration"}, {"type": "benchmark_overlap", "value": "pending"}]}
|
|
@@ -409,6 +419,26 @@ def all_files(root):
|
|
| 409 |
return [path for path in sorted(root.rglob("*")) if path.is_file() and "__pycache__" not in path.parts]
|
| 410 |
|
| 411 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
def publish(out):
|
| 413 |
from huggingface_hub import HfApi, CommitOperationAdd
|
| 414 |
api = HfApi(token=hf_token())
|
|
@@ -431,19 +461,7 @@ def publish(out):
|
|
| 431 |
operations=[CommitOperationAdd(path_in_repo=path.relative_to(root).as_posix(), path_or_fileobj=str(path)) for path in all_files(root)])
|
| 432 |
api.create_tag(OWN_REPO, repo_type="dataset", tag="v1.0.0", revision=source_commit.oid)
|
| 433 |
api.update_repo_settings(OWN_REPO, repo_type="dataset", private=False)
|
| 434 |
-
pr = out
|
| 435 |
-
data = pr / "data" / SOURCE
|
| 436 |
-
data.mkdir(parents=True, exist_ok=True)
|
| 437 |
-
(pr / "src").mkdir(exist_ok=True)
|
| 438 |
-
(pr / "artifacts").mkdir(exist_ok=True)
|
| 439 |
-
shutil.copy2(root / "data/train-00000-of-00001.parquet", data / f"{SOURCE}.parquet")
|
| 440 |
-
for name in ("attribution.jsonl", "decisions.jsonl", "sample.jsonl", "stats.json", "qa.json"):
|
| 441 |
-
shutil.copy2(root / "artifacts" / name, data / f"{SOURCE}.{name}")
|
| 442 |
-
shutil.copy2(root / "NOTICE.md", data / "NOTICE.md")
|
| 443 |
-
shutil.copy2(root / "README.md", data / f"{SOURCE}.md")
|
| 444 |
-
shutil.copy2(root / "artifacts/ontology.json", pr / f"artifacts/{SOURCE}_ontology_manifest.json")
|
| 445 |
-
shutil.copy2(Path(__file__), pr / "src/build_edukacja_medialna_pl.py")
|
| 446 |
-
(pr / "src/sources.py").write_text(registry(base), encoding="utf-8")
|
| 447 |
stats = load(root / "artifacts/stats.json")
|
| 448 |
description = f"""## Add Polish media-literacy lessons\n\nAdds `{SOURCE}`: **{stats['kept']} records and {stats['tokens']:,} measured `cl100k_base` proxy tokens**, acquired directly from official Edukacja Medialna lesson XML. Every retained record has explicit CC BY-SA 3.0 evidence on its lesson page and in XML, plus credited authors.\n\nSource dataset: https://huggingface.co/datasets/{OWN_REPO}/tree/{source_commit.oid}\n\n### Data sample\n\n- [12 complete deterministic sample records](https://huggingface.co/datasets/{OWN_REPO}/blob/{source_commit.oid}/artifacts/sample.jsonl)\n- [Per-record authors, URLs and rights](https://huggingface.co/datasets/{OWN_REPO}/blob/{source_commit.oid}/artifacts/attribution.jsonl)\n- [Selection decisions](https://huggingface.co/datasets/{OWN_REPO}/blob/{source_commit.oid}/artifacts/decisions.jsonl)\n\n### Method and ontology\n\nThe contribution includes a reproducible direct-XML builder, normalized exact and seeded MinHash/Jaccard within-source deduplication, limited PII-pattern checks, checksums, QA and an ontology manifest separating content-addressed Versions, Protocol, executed Run, Evidence, falsifiable Claims and Actors. External reading lists are omitted.\n\n### Remaining gates\n\nCross-source exact/near deduplication and benchmark-overlap checks remain pending. Historical technology/legal guidance is not asserted to be current. Embedded third-party excerpts and the CC BY-SA 3.0 to corpus-level licensing treatment require maintainer review. Training benefit is an untested diversity hypothesis. This proposes a source, not a stable release.\n"""
|
| 449 |
result = api.create_commit(TARGET, repo_type="dataset", parent_commit=target_revision, create_pr=True,
|
|
@@ -455,6 +473,38 @@ def publish(out):
|
|
| 455 |
print(json.dumps(receipt, ensure_ascii=False, indent=2))
|
| 456 |
|
| 457 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
def audit(out):
|
| 459 |
from huggingface_hub import HfApi, hf_hub_download
|
| 460 |
api = HfApi(token=False)
|
|
@@ -462,6 +512,8 @@ def audit(out):
|
|
| 462 |
info = api.dataset_info(OWN_REPO)
|
| 463 |
if info.private or info.sha != receipt["source_commit"]:
|
| 464 |
raise ValueError("source repo visibility or revision mismatch")
|
|
|
|
|
|
|
| 465 |
number = int(receipt["pr_url"].rsplit("/", 1)[-1])
|
| 466 |
discussion = api.get_discussion_details(TARGET, number, repo_type="dataset")
|
| 467 |
pr_info = api.dataset_info(TARGET, revision=f"refs/pr/{number}")
|
|
@@ -484,7 +536,7 @@ def audit(out):
|
|
| 484 |
if __name__ == "__main__":
|
| 485 |
parser = argparse.ArgumentParser(description=__doc__)
|
| 486 |
parser.add_argument("--output", type=Path, required=True)
|
| 487 |
-
parser.add_argument("command", choices=["acquire", "build", "prepare", "verify", "publish", "audit"])
|
| 488 |
args = parser.parse_args()
|
| 489 |
if args.command == "prepare":
|
| 490 |
raise SystemExit("prepare is run by publish with a pinned target revision")
|
|
|
|
| 339 |
(root / "src").mkdir(parents=True, exist_ok=True)
|
| 340 |
shutil.copy2(Path(__file__), root / "src/build_edukacja_medialna_pl.py")
|
| 341 |
shutil.copy2(Path(__file__).with_name("edukacja_medialna_requirements.txt"), root / "src/requirements.txt")
|
| 342 |
+
shutil.copy2(Path(__file__).with_name("test_edukacja_medialna_contribution.py"), root / "src/test_edukacja_medialna_contribution.py")
|
| 343 |
checksums = make_checksums(root)
|
| 344 |
save(root / "artifacts/checksums.json", checksums)
|
| 345 |
protocol = {"name": "edukacja-medialna-direct-xml-v1", "source_scope": LISTING,
|
| 346 |
"license_gate": "explicit CC BY-SA 3.0 on page and XML", "selection": "Polish, >=300 body chars, creator present, no PII pattern match",
|
| 347 |
"dedup": "normalized exact then seeded MinHash/Jaccard", "tokenizer": "tiktoken cl100k_base", "schema": FIELDS}
|
| 348 |
+
quality = load(root / "artifacts/qa.json")
|
| 349 |
+
check_evidence_id = "evidence:checksums:" + sha(checksums)
|
| 350 |
+
qa_evidence_id = "evidence:qa:" + sha(quality)
|
| 351 |
+
validation_protocol = {"name": "edukacja-medialna-contract-v1", "checks": ["schema", "counts", "license", "author attribution", "PII patterns", "samples", "content addresses", "acyclic lineage"]}
|
| 352 |
+
validation_run = {"id": "run:validation:" + sha({"checksums": checksums, "protocol": validation_protocol}), "started_at": now(), "finished_at": now(),
|
| 353 |
+
"code_sha256": checksums["src/test_edukacja_medialna_contribution.py"], "success": True, "result": "local contract validation passed"}
|
| 354 |
ontology = {"schema_version": "slayer-research-ontology/0.1-profile",
|
| 355 |
"objects": [{"id": "object:edukacja-medialna-source", "type": "DatasetSource"}, {"id": "object:edukacja-medialna-derived", "type": "Dataset"}],
|
| 356 |
"versions": [{"id": "version:source:" + sha(load(out / "inventory.json")), "object_id": "object:edukacja-medialna-source", "digest": "sha256:" + sha(load(out / "inventory.json")), "immutable": True},
|
| 357 |
{"id": "version:data:" + sha(checksums), "object_id": "object:edukacja-medialna-derived", "digest": "sha256:" + sha(checksums), "immutable": True}],
|
| 358 |
+
"protocols": [{"id": "protocol:" + sha(protocol), "specification": protocol, "digest": "sha256:" + sha(protocol)},
|
| 359 |
+
{"id": "protocol:" + sha(validation_protocol), "specification": validation_protocol, "digest": "sha256:" + sha(validation_protocol)}],
|
| 360 |
+
"runs": [load(root / "artifacts/run.json"), validation_run],
|
| 361 |
"relations": [{"source": "version:data:" + sha(checksums), "predicate": "DERIVED_FROM", "target": "version:source:" + sha(load(out / "inventory.json"))},
|
| 362 |
{"source": "version:data:" + sha(checksums), "predicate": "FILTERED_BY", "target": "protocol:" + sha(protocol)},
|
| 363 |
+
{"source": "version:data:" + sha(checksums), "predicate": "VALIDATED_AGAINST", "target": "protocol:" + sha(validation_protocol)},
|
| 364 |
{"source": "version:data:" + sha(checksums), "predicate": "COMPATIBLE_WITH", "target": "hf://datasets/" + TARGET + "@" + target_revision}],
|
| 365 |
+
"evidence": [{"id": check_evidence_id, "observation_type": "checksums", "payload": checksums, "append_only": True},
|
| 366 |
+
{"id": qa_evidence_id, "observation_type": "quality_report", "payload": quality, "append_only": True},
|
| 367 |
+
{"id": "evidence:validation:" + sha(validation_run), "observation_type": "contract_validation", "payload": validation_run, "append_only": True}],
|
| 368 |
+
"claims": [{"id": "claim:licensed-records", "statement": "Every retained record passed the explicit page and XML CC BY-SA 3.0 gate.", "supported_by": [check_evidence_id, qa_evidence_id], "falsification_condition": "A retained record lacks either required license signal."},
|
| 369 |
{"id": "claim:diversity-hypothesis", "statement": "This instructional media-literacy source may diversify a legal-heavy Polish pretraining mix.", "supported_by": [], "falsification_condition": "Controlled mix ablations show no relevant improvement or harmful style contamination.", "status": "untested"}],
|
| 370 |
"actors": [{"id": "hf:PiotrSty", "type": "human", "name": "Piotr Styla"}, {"id": "agent:codex", "type": "agent", "name": "OpenAI Codex"}, {"id": "org:fnp", "type": "organization", "name": "Fundacja Nowoczesna Polska"}],
|
| 371 |
"attestations": [{"type": "cross_source_deduplication", "value": "pending_target_integration"}, {"type": "benchmark_overlap", "value": "pending"}]}
|
|
|
|
| 419 |
return [path for path in sorted(root.rglob("*")) if path.is_file() and "__pycache__" not in path.parts]
|
| 420 |
|
| 421 |
|
| 422 |
+
def assemble_pr(out, base, source_commit):
|
| 423 |
+
root = out / "hf_repo"
|
| 424 |
+
pr = out / "dynaword_pr"
|
| 425 |
+
data = pr / "data" / SOURCE
|
| 426 |
+
data.mkdir(parents=True, exist_ok=True)
|
| 427 |
+
(pr / "src").mkdir(exist_ok=True)
|
| 428 |
+
(pr / "artifacts").mkdir(exist_ok=True)
|
| 429 |
+
shutil.copy2(root / "data/train-00000-of-00001.parquet", data / f"{SOURCE}.parquet")
|
| 430 |
+
for name in ("attribution.jsonl", "decisions.jsonl", "sample.jsonl", "stats.json", "qa.json"):
|
| 431 |
+
shutil.copy2(root / "artifacts" / name, data / f"{SOURCE}.{name}")
|
| 432 |
+
shutil.copy2(root / "NOTICE.md", data / "NOTICE.md")
|
| 433 |
+
shutil.copy2(root / "README.md", data / f"{SOURCE}.md")
|
| 434 |
+
shutil.copy2(root / "artifacts/ontology.json", pr / f"artifacts/{SOURCE}_ontology_manifest.json")
|
| 435 |
+
shutil.copy2(Path(__file__), pr / "src/build_edukacja_medialna_pl.py")
|
| 436 |
+
shutil.copy2(Path(__file__).with_name("test_edukacja_medialna_contribution.py"), pr / "src/test_edukacja_medialna_contribution.py")
|
| 437 |
+
(pr / "src/sources.py").write_text(registry(base), encoding="utf-8")
|
| 438 |
+
subprocess.run([sys.executable, "-m", "pytest", "-q", str(pr / "src/test_edukacja_medialna_contribution.py")], check=True)
|
| 439 |
+
return pr
|
| 440 |
+
|
| 441 |
+
|
| 442 |
def publish(out):
|
| 443 |
from huggingface_hub import HfApi, CommitOperationAdd
|
| 444 |
api = HfApi(token=hf_token())
|
|
|
|
| 461 |
operations=[CommitOperationAdd(path_in_repo=path.relative_to(root).as_posix(), path_or_fileobj=str(path)) for path in all_files(root)])
|
| 462 |
api.create_tag(OWN_REPO, repo_type="dataset", tag="v1.0.0", revision=source_commit.oid)
|
| 463 |
api.update_repo_settings(OWN_REPO, repo_type="dataset", private=False)
|
| 464 |
+
pr = assemble_pr(out, base, source_commit.oid)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 465 |
stats = load(root / "artifacts/stats.json")
|
| 466 |
description = f"""## Add Polish media-literacy lessons\n\nAdds `{SOURCE}`: **{stats['kept']} records and {stats['tokens']:,} measured `cl100k_base` proxy tokens**, acquired directly from official Edukacja Medialna lesson XML. Every retained record has explicit CC BY-SA 3.0 evidence on its lesson page and in XML, plus credited authors.\n\nSource dataset: https://huggingface.co/datasets/{OWN_REPO}/tree/{source_commit.oid}\n\n### Data sample\n\n- [12 complete deterministic sample records](https://huggingface.co/datasets/{OWN_REPO}/blob/{source_commit.oid}/artifacts/sample.jsonl)\n- [Per-record authors, URLs and rights](https://huggingface.co/datasets/{OWN_REPO}/blob/{source_commit.oid}/artifacts/attribution.jsonl)\n- [Selection decisions](https://huggingface.co/datasets/{OWN_REPO}/blob/{source_commit.oid}/artifacts/decisions.jsonl)\n\n### Method and ontology\n\nThe contribution includes a reproducible direct-XML builder, normalized exact and seeded MinHash/Jaccard within-source deduplication, limited PII-pattern checks, checksums, QA and an ontology manifest separating content-addressed Versions, Protocol, executed Run, Evidence, falsifiable Claims and Actors. External reading lists are omitted.\n\n### Remaining gates\n\nCross-source exact/near deduplication and benchmark-overlap checks remain pending. Historical technology/legal guidance is not asserted to be current. Embedded third-party excerpts and the CC BY-SA 3.0 to corpus-level licensing treatment require maintainer review. Training benefit is an untested diversity hypothesis. This proposes a source, not a stable release.\n"""
|
| 467 |
result = api.create_commit(TARGET, repo_type="dataset", parent_commit=target_revision, create_pr=True,
|
|
|
|
| 473 |
print(json.dumps(receipt, ensure_ascii=False, indent=2))
|
| 474 |
|
| 475 |
|
| 476 |
+
def refresh(out):
|
| 477 |
+
from huggingface_hub import HfApi, CommitOperationAdd
|
| 478 |
+
api = HfApi(token=hf_token())
|
| 479 |
+
receipt = load(out / "publication.json")
|
| 480 |
+
number = int(receipt["pr_url"].rsplit("/", 1)[-1])
|
| 481 |
+
main = api.dataset_info(TARGET)
|
| 482 |
+
if main.sha != receipt["target_main_revision"]:
|
| 483 |
+
raise ValueError("target main changed; inspect and rebase before refreshing PR")
|
| 484 |
+
registry_url = f"https://huggingface.co/datasets/{TARGET}/resolve/{main.sha}/src/sources.py"
|
| 485 |
+
base = http_get(registry_url).content.decode("utf-8")
|
| 486 |
+
prepare(out, main.sha)
|
| 487 |
+
verify(out)
|
| 488 |
+
root = out / "hf_repo"
|
| 489 |
+
old_source = api.dataset_info(OWN_REPO)
|
| 490 |
+
source_commit = api.create_commit(OWN_REPO, repo_type="dataset", parent_commit=old_source.sha,
|
| 491 |
+
commit_message="Add contribution contract test and validation run",
|
| 492 |
+
operations=[CommitOperationAdd(path_in_repo=path.relative_to(root).as_posix(), path_or_fileobj=str(path)) for path in all_files(root)])
|
| 493 |
+
tag = "v1.0.1"
|
| 494 |
+
if not any(item.name == tag for item in api.list_repo_refs(OWN_REPO, repo_type="dataset").tags):
|
| 495 |
+
api.create_tag(OWN_REPO, repo_type="dataset", tag=tag, revision=source_commit.oid)
|
| 496 |
+
pr = assemble_pr(out, base, source_commit.oid)
|
| 497 |
+
old_pr = api.dataset_info(TARGET, revision=f"refs/pr/{number}")
|
| 498 |
+
pr_commit = api.create_commit(TARGET, repo_type="dataset", revision=f"refs/pr/{number}", parent_commit=old_pr.sha,
|
| 499 |
+
commit_message="Add contract test and explicit ontology validation run",
|
| 500 |
+
operations=[CommitOperationAdd(path_in_repo=path.relative_to(pr).as_posix(), path_or_fileobj=str(path)) for path in all_files(pr)])
|
| 501 |
+
receipt.setdefault("previous_source_commits", []).append(receipt["source_commit"])
|
| 502 |
+
receipt.setdefault("previous_pr_commits", []).append(receipt["pr_commit"])
|
| 503 |
+
receipt.update(source_commit=source_commit.oid, pr_commit=pr_commit.oid, tag=tag, refreshed_at=now())
|
| 504 |
+
save(out / "publication.json", receipt)
|
| 505 |
+
print(json.dumps(receipt, ensure_ascii=False, indent=2))
|
| 506 |
+
|
| 507 |
+
|
| 508 |
def audit(out):
|
| 509 |
from huggingface_hub import HfApi, hf_hub_download
|
| 510 |
api = HfApi(token=False)
|
|
|
|
| 512 |
info = api.dataset_info(OWN_REPO)
|
| 513 |
if info.private or info.sha != receipt["source_commit"]:
|
| 514 |
raise ValueError("source repo visibility or revision mismatch")
|
| 515 |
+
if not any(item.name == receipt["tag"] and item.target_commit == info.sha for item in api.list_repo_refs(OWN_REPO, repo_type="dataset").tags):
|
| 516 |
+
raise ValueError("release tag mismatch")
|
| 517 |
number = int(receipt["pr_url"].rsplit("/", 1)[-1])
|
| 518 |
discussion = api.get_discussion_details(TARGET, number, repo_type="dataset")
|
| 519 |
pr_info = api.dataset_info(TARGET, revision=f"refs/pr/{number}")
|
|
|
|
| 536 |
if __name__ == "__main__":
|
| 537 |
parser = argparse.ArgumentParser(description=__doc__)
|
| 538 |
parser.add_argument("--output", type=Path, required=True)
|
| 539 |
+
parser.add_argument("command", choices=["acquire", "build", "prepare", "verify", "publish", "refresh", "audit"])
|
| 540 |
args = parser.parse_args()
|
| 541 |
if args.command == "prepare":
|
| 542 |
raise SystemExit("prepare is run by publish with a pinned target revision")
|
src/test_edukacja_medialna_contribution.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Contract checks run from the prepared DynaWord contribution tree."""
|
| 2 |
+
import json
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
import pyarrow.parquet as pq
|
| 7 |
+
|
| 8 |
+
SOURCE = "edukacja_medialna_pl"
|
| 9 |
+
LICENSE = "CC-BY-SA-3.0"
|
| 10 |
+
FIELDS = ["id", "text", "source", "added", "created", "token_count", "license", "author"]
|
| 11 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 12 |
+
DATA = ROOT / "data" / SOURCE
|
| 13 |
+
MANIFEST = ROOT / "artifacts" / f"{SOURCE}_ontology_manifest.json"
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def digest(payload):
|
| 17 |
+
import hashlib
|
| 18 |
+
if isinstance(payload, bytes):
|
| 19 |
+
return hashlib.sha256(payload).hexdigest()
|
| 20 |
+
return hashlib.sha256(json.dumps(payload, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode()).hexdigest()
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def rows(path):
|
| 24 |
+
return [json.loads(line) for line in path.read_text(encoding="utf-8").splitlines() if line]
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def test_dataset_contract_and_samples():
|
| 28 |
+
table = pq.read_table(DATA / f"{SOURCE}.parquet")
|
| 29 |
+
data = table.to_pylist()
|
| 30 |
+
stats = json.loads((DATA / f"{SOURCE}.stats.json").read_text(encoding="utf-8"))
|
| 31 |
+
attribution = rows(DATA / f"{SOURCE}.attribution.jsonl")
|
| 32 |
+
decisions = rows(DATA / f"{SOURCE}.decisions.jsonl")
|
| 33 |
+
sample = rows(DATA / f"{SOURCE}.sample.jsonl")
|
| 34 |
+
assert table.column_names == FIELDS
|
| 35 |
+
assert len(data) == stats["kept"] == len(attribution)
|
| 36 |
+
assert sum(item["token_count"] for item in data) == stats["tokens"]
|
| 37 |
+
assert sum(bool(item["selected"]) for item in decisions) == stats["kept"]
|
| 38 |
+
assert len(decisions) == stats["discovered"]
|
| 39 |
+
assert {item["id"] for item in data} == {item["id"] for item in attribution}
|
| 40 |
+
assert all(item["source"] == SOURCE and item["license"] == LICENSE and item["author"] for item in data)
|
| 41 |
+
assert all(not re.search(r"(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b", item["text"]) for item in data)
|
| 42 |
+
by_id = {item["id"]: item for item in data}
|
| 43 |
+
assert len(sample) == stats["sample_count"] == 12
|
| 44 |
+
assert all(by_id[item["id"]] == item for item in sample)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def test_ontology_is_addressed_and_falsifiable():
|
| 48 |
+
manifest = json.loads(MANIFEST.read_text(encoding="utf-8"))
|
| 49 |
+
evidence = {item["id"]: item for item in manifest["evidence"]}
|
| 50 |
+
checks = next(item["payload"] for item in manifest["evidence"] if item["observation_type"] == "checksums")
|
| 51 |
+
for name, expected in checks.items():
|
| 52 |
+
mapping = {
|
| 53 |
+
"data/train-00000-of-00001.parquet": DATA / f"{SOURCE}.parquet",
|
| 54 |
+
"artifacts/attribution.jsonl": DATA / f"{SOURCE}.attribution.jsonl",
|
| 55 |
+
"artifacts/decisions.jsonl": DATA / f"{SOURCE}.decisions.jsonl",
|
| 56 |
+
"artifacts/sample.jsonl": DATA / f"{SOURCE}.sample.jsonl",
|
| 57 |
+
"artifacts/stats.json": DATA / f"{SOURCE}.stats.json",
|
| 58 |
+
"artifacts/qa.json": DATA / f"{SOURCE}.qa.json",
|
| 59 |
+
"src/build_edukacja_medialna_pl.py": ROOT / "src/build_edukacja_medialna_pl.py",
|
| 60 |
+
"src/test_edukacja_medialna_contribution.py": ROOT / "src/test_edukacja_medialna_contribution.py",
|
| 61 |
+
}
|
| 62 |
+
if name in mapping:
|
| 63 |
+
assert digest(mapping[name].read_bytes()) == expected
|
| 64 |
+
assert all(item["falsification_condition"] for item in manifest["claims"])
|
| 65 |
+
assert all(set(item["supported_by"]) <= set(evidence) for item in manifest["claims"])
|
| 66 |
+
assert any(item["predicate"] == "VALIDATED_AGAINST" for item in manifest["relations"])
|
| 67 |
+
assert len(manifest["runs"]) >= 2 and all(item["success"] for item in manifest["runs"])
|
| 68 |
+
graph = {}
|
| 69 |
+
for relation in manifest["relations"]:
|
| 70 |
+
graph.setdefault(relation["source"], []).append(relation["target"])
|
| 71 |
+
def visit(node, path):
|
| 72 |
+
assert node not in path
|
| 73 |
+
for child in graph.get(node, []):
|
| 74 |
+
visit(child, path | {node})
|
| 75 |
+
for node in graph:
|
| 76 |
+
visit(node, set())
|