Download validate_dataset.py from Tarnyd/sv-blimp: direct link, hf CLI and curl.
- Browser
- Download file 4.81 kB
-
https://huggingface.co/datasets/Tarnyd/sv-blimp/resolve/main/validate_dataset.py
- Command line
-
hf download hf://datasets/Tarnyd/sv-blimp/validate_dataset.py
-
curl -L -o validate_dataset.py https://huggingface.co/datasets/Tarnyd/sv-blimp/resolve/main/validate_dataset.py
4.81 kB
| import json | |
| import re | |
| import sys | |
| from collections import defaultdict | |
| CATS = ["subordinate_word_order", "v2_violation", "particle_verbs", "gender_agreement", | |
| "determiners", "anaphor_agreement", "argument_structure", "binding", "ellipsis", | |
| "irregular_forms", "island_effects", "nominalization", "npi_licensing", | |
| "passives", "quantifiers", "relative_clauses"] | |
| # Present-tense verbs that must NOT follow past-time adverbs in v2_violation, | |
| # plus the past-time adverb list -- both come from the canonical generator. | |
| import generate_sv_blimp as g | |
| PRESENT_VERBS = set(g.PRESENT_VERBS) | |
| PAST_ADVS = tuple(g.ADV_PAST) | |
| # Morphologically corrupted tokens from an earlier string-derivation approach; | |
| # they must never appear. Regression guard against reintroducing naive | |
| # inflection by string manipulation (the current generator stores explicit forms). | |
| GARBAGE = ["vitr", "srorr", "lirer", "runr", "svärr", "byggsar", "skrivsar", "mätssar", | |
| "manen", "ma.", "orde.", "huse.", "glase.", "storta huse"] | |
| def skeleton(s): | |
| """Replace known slot words with X so we can group identical patterns.""" | |
| words = s.split() | |
| out = [] | |
| for w in words: | |
| if re.fullmatch(r"[A-Z][a-zäöåÄÖÅé]+", w) and w in KNOWN_AGENTS: | |
| out.append("AG") | |
| elif w in KNOWN_OBJECTS: | |
| out.append("OB") | |
| else: | |
| out.append(w) | |
| return " ".join(out) | |
| KNOWN_AGENTS = set() | |
| KNOWN_OBJECTS = set() | |
| def load_pools(): | |
| KNOWN_AGENTS.update(g.ALL_AGENTS) | |
| KNOWN_OBJECTS.update(g.ALL_OBJECTS) | |
| def main(): | |
| load_pools() | |
| total_errors = 0 | |
| all_skeletons = defaultdict(set) | |
| for cat in CATS: | |
| path = f"sv_blimp_{cat}.jsonl" | |
| lines = open(path, encoding="utf-8").read().splitlines() | |
| errs = [] | |
| ids = set() | |
| seen_pairs = set() | |
| seen_singles = {"sentence_good": set(), "sentence_bad": set()} | |
| for ln, line in enumerate(lines, 1): | |
| e = json.loads(line) | |
| ids.add(e["item_id"]) | |
| pair = (e["sentence_good"], e["sentence_bad"]) | |
| if pair in seen_pairs: | |
| errs.append(f"L{ln}: duplicate (good, bad) pair: {pair}") | |
| seen_pairs.add(pair) | |
| if e["sentence_good"] == e["sentence_bad"]: | |
| errs.append(f"L{ln}: good == bad: {e['sentence_good']}") | |
| for key in ("sentence_good", "sentence_bad"): | |
| s = e[key] | |
| if not s[0].isupper(): | |
| errs.append(f"L{ln} {key}: lowercase start: {s}") | |
| if not s.endswith((".", "?")): | |
| errs.append(f"L{ln} {key}: no terminal punctuation: {s}") | |
| for tok in GARBAGE: | |
| if re.search(rf"\b{re.escape(tok)}\b", s): | |
| errs.append(f"L{ln} {key}: garbage token '{tok}': {s}") | |
| # Uniqueness of each sentence on its own (in addition to the pair). | |
| for key in ("sentence_good", "sentence_bad"): | |
| s = e[key] | |
| if s in seen_singles[key]: | |
| errs.append(f"L{ln} {key}: duplicate sentence: {s}") | |
| seen_singles[key].add(s) | |
| # v2 tense check: a past-time adverb must be followed by a preterite, | |
| # i.e. no present-tense verb form may appear AFTER the adverb. | |
| # (The adverb prefix is stripped first: "I går" contains the token | |
| # "går", which is itself a present-tense verb form.) | |
| if cat == "v2_violation": | |
| for key in ("sentence_good", "sentence_bad"): | |
| s = e[key] | |
| adv = next((a for a in PAST_ADVS if s.startswith(a)), None) | |
| if adv is not None: | |
| rest = s[len(adv):].split() | |
| if any(w in PRESENT_VERBS for w in rest): | |
| errs.append(f"L{ln} {key}: present tense after past adverb: {s}") | |
| all_skeletons[cat].add(skeleton(e["sentence_good"])) | |
| all_skeletons[cat].add(skeleton(e["sentence_bad"])) | |
| if len(lines) != 1000: | |
| errs.append(f"expected 1000 lines, got {len(lines)}") | |
| if ids != set(range(1, 1001)): | |
| errs.append("item_id set is not 1..1000") | |
| status = "OK" if not errs else f"{len(errs)} ERRORS" | |
| print(f"[{status}] {cat}") | |
| for e in errs[:10]: | |
| print(" ", e) | |
| total_errors += len(errs) | |
| print("\n=== UNIQUE SKELETONS PER CATEGORY (for manual review) ===") | |
| for cat in CATS: | |
| print(f"\n--- {cat} ({len(all_skeletons[cat])} unique skeletons) ---") | |
| for sk in sorted(all_skeletons[cat]): | |
| print(" ", sk) | |
| print(f"\nTotal errors: {total_errors}") | |
| sys.exit(1 if total_errors else 0) | |
| if __name__ == "__main__": | |
| main() | |