# Publishing the Dataset to HuggingFace Hub ## Files | File | Purpose | |---|---| | `build_dataset.py` | Converts `CzechHistoricalNewspapers.json` into two HuggingFace Dataset configs | | `dataset_card.md` | Hub README — copy as `README.md` in the Hub repo before pushing | --- ## Dataset configs produced | Config | Rows | Granularity | Best for | |---|---|---|---| | `pages` | 30 | One row per newspaper page | Running clustering experiments (texts list + labels list per page) | | `annotations` | 881 | One row per text annotation | Cross-page filtering, per-annotation analysis | --- ## Workflow ### 1. Install dependencies ```bash pip install datasets huggingface_hub ``` ### 2. Build locally (no Hub account needed) ```bash python build_dataset.py # Output saved to ./hf_dataset/pages/ and ./hf_dataset/annotations/ ``` ### 3. Log in and push to Hub ```bash huggingface-cli login python build_dataset.py --push your-hf-username # Publishes as: your-hf-username/czech-historical-newspapers ``` ### 4. Add the dataset card Copy `dataset_card.md` as `README.md` in the Hub repo (via the Hub UI or `huggingface_hub` API). --- ## Loading the dataset from anywhere ```python from datasets import load_dataset # Page-level (for clustering experiments) ds = load_dataset("your-username/czech-historical-newspapers", "pages") row = ds["train"][0] texts = row["texts"] # list of OCR strings for the page labels = row["cluster_labels"] # ground-truth article assignment per text # Annotation-level (for per-region analysis) ds = load_dataset("your-username/czech-historical-newspapers", "annotations") page = ds["train"].filter(lambda x: x["image_name"] == "Brnenske_48_D.jpg") ``` --- ## Key design decisions - **Two configs** instead of one flat table: the page-level view avoids reconstructing the grouping logic in every experiment notebook. - **Cluster label alignment**: the script iterates annotations in the original JSON order (same as the notebook), so `cluster_labels[i]` always corresponds to `texts[i]`. - **Filtered categories**: region types 1 (SeparatorRegion), 3 (Caption), 6 (ImageRegion), and 7 (Article) are excluded — they carry no OCR text and are not part of the cluster arrays. - **Images not included**: the original JPEGs are not in the JSON. The dataset is text-only; `image_name` serves as a reference key.