Datasets:
Tasks:
Text Classification
Formats:
parquet
Languages:
Ancient Greek (to 1453)
Size:
100K - 1M
License:
| from collections import Counter, defaultdict | |
| import json | |
| from pathlib import Path | |
| import pyarrow.parquet as pq | |
| DATA_ROOT = Path(__file__).resolve().parents[1] / "data" | |
| BASE_CONFIGS = ("prose", "verse_sentence", "verse_metre") | |
| def test_atomic_splits_are_balanced_and_100_chunkable() -> None: | |
| for base_config in BASE_CONFIGS: | |
| config = f"{base_config}_1" | |
| counts = defaultdict(Counter) | |
| for path in sorted((DATA_ROOT / config).glob("*.parquet")): | |
| table = pq.read_table(path, columns=["author", "split"]) | |
| for row in table.to_pylist(): | |
| counts[row["author"]][row["split"]] += 1 | |
| assert counts | |
| for author, author_counts in counts.items(): | |
| assert author_counts["train"] > 0, (config, author) | |
| assert author_counts["validation"] == author_counts["test"], (config, author) | |
| assert author_counts["validation"] >= 100, (config, author) | |
| assert author_counts["validation"] % 100 == 0, (config, author) | |
| def test_each_genre_retains_approximately_balanced_source_splits() -> None: | |
| for base_config in BASE_CONFIGS: | |
| config = f"{base_config}_1" | |
| counts = Counter() | |
| for path in sorted((DATA_ROOT / config).glob("*.parquet")): | |
| splits = pq.read_table(path, columns=["split"])["split"].to_pylist() | |
| counts.update(splits) | |
| total = sum(counts.values()) | |
| assert total > 0 | |
| assert counts["validation"] == counts["test"] | |
| assert 0.78 <= counts["train"] / total <= 0.83, (config, counts) | |
| def test_chunkable_variants_have_atomic_train_and_exact_evaluation_chunks() -> None: | |
| for base_config in BASE_CONFIGS: | |
| for threshold in (10, 100): | |
| config = f"{base_config}_{threshold}" | |
| train_path = DATA_ROOT / config / "train-00000-of-00001.parquet" | |
| train_sizes = pq.read_table(train_path, columns=["chunk_size"])["chunk_size"].to_pylist() | |
| assert train_sizes and set(train_sizes) == {1} | |
| for split in ("validation", "test"): | |
| path = DATA_ROOT / config / f"{split}-00000-of-00001.parquet" | |
| table = pq.read_table( | |
| path, columns=["author", "chunk_size", "constituent_ids"], | |
| ) | |
| assert table.num_rows > 0 | |
| assert set(table["chunk_size"].to_pylist()) == {threshold} | |
| assert all( | |
| len(ids) == threshold for ids in table["constituent_ids"].to_pylist() | |
| ) | |
| def test_all_task_sizes_cover_exactly_the_same_atomic_rows() -> None: | |
| for base_config in BASE_CONFIGS: | |
| atomic_rows = {} | |
| for split in ("train", "validation", "test"): | |
| path = DATA_ROOT / f"{base_config}_1" / f"{split}-00000-of-00001.parquet" | |
| atomic_rows[split] = { | |
| row["id"]: row["text"] | |
| for row in pq.read_table(path, columns=["id", "text"]).to_pylist() | |
| } | |
| for threshold in (10, 100): | |
| for split in ("train", "validation", "test"): | |
| path = ( | |
| DATA_ROOT / f"{base_config}_{threshold}" | |
| / f"{split}-00000-of-00001.parquet" | |
| ) | |
| chunks = pq.read_table( | |
| path, columns=["text", "constituent_ids"], | |
| ).to_pylist() | |
| represented_ids = [ | |
| row_id for chunk in chunks for row_id in chunk["constituent_ids"] | |
| ] | |
| assert len(represented_ids) == len(set(represented_ids)) | |
| assert set(represented_ids) == set(atomic_rows[split]), ( | |
| base_config, | |
| threshold, | |
| split, | |
| ) | |
| separator = "\n" if base_config == "verse_metre" else "\n\n" | |
| for chunk in chunks: | |
| expected_text = ( | |
| atomic_rows[split][chunk["constituent_ids"][0]] | |
| if split == "train" | |
| else separator.join( | |
| atomic_rows[split][row_id].strip() | |
| for row_id in chunk["constituent_ids"] | |
| ) | |
| ) | |
| assert chunk["text"] == expected_text | |
| def test_verse_metre_chunks_concatenate_every_constituent_syllable() -> None: | |
| atomic_syllables = {} | |
| for split in ("train", "validation", "test"): | |
| path = DATA_ROOT / "verse_metre_1" / f"{split}-00000-of-00001.parquet" | |
| table = pq.read_table(path, columns=["id", "syllables"]) | |
| atomic_syllables[split] = { | |
| row["id"]: json.loads(row["syllables"]) | |
| for row in table.to_pylist() | |
| } | |
| for threshold in (10, 100): | |
| for split in ("train", "validation", "test"): | |
| path = ( | |
| DATA_ROOT / f"verse_metre_{threshold}" | |
| / f"{split}-00000-of-00001.parquet" | |
| ) | |
| table = pq.read_table(path, columns=["constituent_ids", "syllables"]) | |
| for row in table.to_pylist(): | |
| expected = [ | |
| syllable | |
| for row_id in row["constituent_ids"] | |
| for syllable in atomic_syllables[split][row_id] | |
| ] | |
| assert json.loads(row["syllables"]) == expected | |
| def test_scansion_is_not_published() -> None: | |
| for suffix in ("1", "10", "100"): | |
| for split in ("train", "validation", "test"): | |
| path = ( | |
| DATA_ROOT / f"verse_metre_{suffix}" | |
| / f"{split}-00000-of-00001.parquet" | |
| ) | |
| assert "scansion" not in pq.ParquetFile(path).schema_arrow.names | |
| for split in ("train", "validation", "test"): | |
| path = DATA_ROOT / "verse_sentence_1" / f"{split}-00000-of-00001.parquet" | |
| table = pq.read_table(path, columns=["metrical_lines"]) | |
| for encoded_lines in table["metrical_lines"].to_pylist(): | |
| assert all("scansion" not in line for line in json.loads(encoded_lines)) | |