File size: 18,522 Bytes
81fafcb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# AGENTS.md

Guidance for agents and contributors adding a source and cutting a release.
Read this before opening a PR. Source PRs and releases are separate: a source PR
adds one source with `release: None`; the maintainer later cuts one release that
bumps the version and docs for every source merged since the last one.
**Every source needs a recorded rights review before its PR and before its release:
open `.agents/skills/source-rights-review/SKILL.md` and follow it** (see "Rights
review" below; agents that don't auto-discover skills must open it by path).

## How the docs are actually maintained

The README is hand-written. `src/make_docs.py` refreshes only its generated
blocks: the stable line of the header, the counts in the current version's row of
the releases table, the Sources and Excluded tables, and Results (from
`artifacts/pattern_frequency_hf_snippet.md`). It fails if one of those blocks is
missing, and `src/test_make_docs.py` checks that the committed README is what it
renders. It also writes `LICENSE`, a `CHANGELOG` stub for a new version and the
*template* datasheets. What it does not do:

- It iterates `SOURCES` in `src/sources.py`; any source in `data/` but missing
  from `SOURCES` is silently dropped from the table and totals.
- It stamps a regenerated datasheet's "Added" with the source's `added` field,
  falling back to the global `ADDED` constant when the entry has none — so a new
  entry without `added` still gets a wrong date.
- It does not write README narrative: the releases text, version details,
  contributors, changes, notices and policy sections are edited by hand.

So datasheets and the README narrative are **hand/contributor-maintained**.
Never run `make_docs.py` and commit the result blind — `git diff` first and
restore anything it dropped or restamped.

## Before you start: check the findings log

`artifacts/source_findings.md` records sources already investigated, including
the rejected ones and *why*. Check it before spending a day on a source someone
already found to be blocked — and append your own finding there whether the
answer was yes or no.

## Rights review (required before a source PR and before a release)

**Follow `.agents/skills/source-rights-review/SKILL.md`** — method, failure classes,
templates. Do not rely on auto-discovery: open the file. HPLT was released on a
CC0 label that covered only the packaging of crawled pages and was removed after
v0.2.5; the 2026-10 audit (`artifacts/rights_audit_2026-10/`) found the same flaw
in five more shipped sources. Rules:

1. A licence on a platform, package or compilation is not a licence on the works
   inside. Find who wrote the text and what *they* granted.
2. Unverified = not admitted. Merge with `release: None`; never release.
3. Read the full terms, not the badge: NC/ND, AI-training and scraping bans,
   per-item rights fields. A fetcher reads the licence from upstream and fails on
   NC/ND or AI-use clauses; it never hard-codes it.
4. Rights per item → per-row `license`, not one label. "Public domain" means every
   author and translator died in 1955 or earlier (2026; life + 70).
5. Sample for third-party content (seed recorded, ≥40 docs per stratum, Wilson
   interval, token share). Filters go in the committed fetch/clean script, with a test.
6. Name every intermediary (HF snapshot, SpeakLeash, dump) in the datasheet and
   `provenance`, and write down what you did not check.
7. Record it: `license`/`license_spdx`/`legal_note` in `src/sources.py`,
   `data/<key>/<key>.license-evidence.json`, a decision record, a findings-log entry.
8. Never write to rights holders, accept terms, create accounts or get past a
   CAPTCHA — hand those to the maintainer.

## Add a source

1. Produce the artifact under `data/<key>/`:
   - `<key>.parquet` — built by `src/build_dynaword.py` (LFS-tracked automatically).
   - `<key>.stats.json` — doc/token/char counts (drives all totals).
   - `<key>.md` — datasheet (see below).
2. Add the ingestion script: `src/fetch_<key>.py` or `src/clean_<key>.py`, so the
   source is reproducible. `build_source` (build_dynaword.py) expects a
   `<file_key|speakleash_key>.jsonl.zst` intermediate.
3. Register the source in `src/sources.py` (`SOURCES`) — required, or make_docs
   never sees it. Copy an existing entry's shape: `pretty`, `license`,
   `license_spdx`, `traceable`, `upstream`, `domain`, `created`, `is_ocr`, and the
   `speakleash_key`/`file_key`. If the datasheet is hand-authored (rich provenance
   or a fixed add date), add `"custom_datasheet": True` so make_docs leaves it
   alone.

   Also set `added` (the real add date) and `release`. `release` is what admits a
   source to a release's totals: `None` means "on main, not in any release yet",
   which is the correct value for a new source until the release that ships it is
   cut. Nothing is counted just because it has a `stats.json`.
4. Add a contract test: `src/test_<key>_contract.py` (canonical schema, non-empty
   text, positive token counts, uniform source/license, stats-file consistency).
   Run `python3 -m pytest src/` before committing; install the test dependencies
   once with `pip install -r requirements-dev.txt`.

### Keep the PR to your source

Many source PRs are open at once, and each one that touches shared files
conflicts with the others. A source PR changes only:

- `data/<key>/*`, `src/fetch_<key>.py` / `src/clean_<key>.py`,
  `src/test_<key>_contract.py`;
- **one** new entry in `src/sources.py`, with `release: None`;
- your entry appended to `artifacts/source_findings.md`.

It does **not** touch `README.md`, `CHANGELOG.md`, `VERSION`/`RELEASE_DATE` in
`src/make_docs.py`, the phrase-frequency report, `AGENTS.md`, or other sources'
fetchers — those change in the release commit (below) or in their own PR.
`.gitattributes` already LFS-tracks `data/*/*.attribution.jsonl` and
`*.decisions.jsonl`; do not add per-file lines.
Commit with LF line endings — a CRLF `sources.py` shows as a whole-file rewrite
and conflicts with every other PR. Rebase onto `main` before asking for review.

## What the PR must show

These two are not optional — they are the difference between a source a reviewer
can accept and one that sits in the queue. Treat every source PR as a worked
example other contributors will copy.

1. **A sample of the data, inline in the PR description.** A few real documents
   (or truncated ones), verbatim, so a reviewer can see at a glance what kind of
   text this actually is — prose, transcripts, boilerplate, OCR noise, HTML
   leftovers. Include the metadata columns too, not just `text`. Don't make the
   reviewer download a parquet to find out — and a linked `.sample.jsonl` is not
   a substitute: on the Hub it renders as one escaped line per document.

   Generate it from the built shard and paste the output into the PR description:
   ```bash
   python3 src/render_sample.py data/<key>/<key>.parquet -n 3
   ```
   Each document is a fenced block — metadata as `key: value` lines, a blank
   line, then the text with its real line breaks, truncated with `[…]`:
   ````
   ```
   id: sejm_interpellations_2388
   source: sejm_interpellations
   added: 2026-07-19
   token_count: 415
   license: public-domain (official documents)
   author: Daniel Milewski

   Szanowny Panie Ministrze,

   latem 2022 roku na podlaskiej części granicy z Białorusią ukończono […]
   ```
   ````
   Pick rows that show the typical document; if the source has distinct
   document types (question vs reply, article vs talk page), show one of each.

2. **Provenance and licensing, written out in the datasheet (`data/<key>/<key>.md`)
   and summarized in the PR description:**
   - Where the data comes from — the concrete origin (institution, portal, API,
     dump), not just a domain name. Link it.
   - Under what license, and **where that license statement lives** — link the
     exact terms-of-use page, API docs section, or statute. "Public domain
     because it's government data" is a claim, not a source; cite the provision.
   - What the texts are — genre, register, time span, language variety, whether
     they are OCR'd, machine-translated, or user-generated.
   - How it was collected and filtered — dedup, minimum length, language ID,
     anything dropped and why.
   - The argument for inclusion — what this adds that the corpus does not
     already have, and any known bias or quality caveat a downstream user should
     weigh.

Yes, this is meta work on top of the fetching. That is the point: the datasheet
is the artifact other people read to learn how to contribute well.

## Normalize the text before you build

`build_dynaword.py` applies only *minimal gates* — strip, `len < 200`, Polish
diacritic ratio, OCR alpha ratio, exact sha1 dedup. It does **not** clean text.
`src/normalize_schema.py` is a schema/stats tool despite the name; it never
touches `text`. So normalization is the fetcher's job, and today each fetcher
reimplements it (`fetch_govpl.py:43` and `fetch_saos.py:42` carry byte-identical
`html_to_text`; `clean_samorzad_gov_pl.py:65` a third variant). If you are
writing a new fetcher, factor the shared parts out rather than pasting a fourth
copy.

What a fetcher should do to `text` before writing the `.jsonl.zst`:

- **Unicode**: NFKC normalize. Map non-breaking/thin/zero-width spaces to plain
  space (or drop), strip control characters and soft hyphens, normalize the
  quote/dash/ellipsis zoo. Repair mojibake if the upstream encoding is unreliable.
- **Whitespace**: collapse runs of spaces/tabs, trim per line, cap blank runs at
  one empty line. Do not flatten paragraph breaks — they carry structure.
- **Structural junk**: navigation, cookie banners, "share this", pagination,
  footnote back-references, and — for OCR/PDF sources — page headers/footers,
  running titles, and hyphenation split across line breaks.
- **Numbering**: strip standalone chapter/section/page numbers and repeated
  heading numerals (`1.`, `Art. 5.`, `Rozdział III`) *only where they are layout
  artifacts*. In `dziennik_ustaw` or `saos` the article numbering is content —
  removing it destroys the document. Judge per source, and say what you did in
  the datasheet.
- **Boilerplate**: near-identical blocks repeated across most documents of a
  source (license footers, institutional disclaimers, "Pokaż odpowiedź"-style UI
  chrome) should be detected by frequency across the shard and removed, not
  hand-listed.
- **Personal data**: do not keep a scrubber in this repo. Apply
  [`SlayerLab/NERGAL`](https://huggingface.co/SlayerLab/NERGAL) before the
  parquet is written (frozen regex ∪ model; placeholders `[PII]` / `[PHONE]`,
  and `[PERSON]` with names on). A phone mask is `[PHONE]`; the NERGAL pass
  renames the legacy `[Telefon]`, so no shard ships it.
  Names of public officials acting in an official capacity are not PII and
  should stay — removing them would gut parliamentary and judicial sources.
  A source scrubbed some other way may still merge with `release: None`, but it
  is not admitted to a release until its shard has been re-run through NERGAL.
  The one exception is v0.2.6, which shipped before the NERGAL pass; the pass
  runs on every source before v0.2.7.
  Say in the datasheet which scrubber ran. Note that `main` is public on the Hub
  whether or not a source is released.

Two rules about all of the above:

1. **The normalization must live in the committed fetch/clean script**, so the
   shard is reproducible. A shard whose datasheet describes a cleaning step that
   no script in `src/` performs is not reproducible, however good the intent.
2. **Report it in the datasheet**: which steps ran, and what the gates dropped.
   Include a handful of before/after excerpts in the PR — this is the fastest way
   for a reviewer to see whether normalization ate real content.

## Cut the release (maintainer, one commit after the source PRs merge)

0. In `src/sources.py`, set `release` on each merged source this release ships
   (check its shard went through NERGAL first; v0.2.6 was the one exception), and
   `removed` on each source it drops. A source is not released until its rights
   review is recorded (see "Rights review").
1. In `src/make_docs.py`: bump `VERSION` and `RELEASE_DATE`.
2. Regenerate the phrase-frequency report and charts (registry-independent — it
   globs `data/*/*.parquet`):
   ```bash
   python3 src/pattern_frequency_report.py
   ```
   Writes `artifacts/pattern_frequency_hf_snippet.md` + 10 PNGs; step 3 splices
   it into the README "Results" section.
3. Edit `README.md` by hand: add a ``| `vX.Y.Z` | stable release | 0 | 0B |`` row
   to the stable releases table (relabel the previous one), a Contributors row
   for each new contributor, the version details and the main block of the
   header. Then run `python3 src/make_docs.py`: it fills in the totals, the
   header's stable line and the Sources and Excluded tables, from the
   per-source `stats.json` files. `git diff` the result.
4. Append the release to `VERSIONS`, `DOCUMENTS` and `TOKENS` in
   `src/plot_version_growth.py`, using the same stats sums as step 3. Then check the
   paper (polish-dynaword-v2) against the tree:
   ```bash
   python3 src/verify_paper_claims.py --tex ../polish-dynaword-v2/main.tex --ref worktree
   ```
   It exits 0 once the paper describes this release. Without `--ref`, it reads
   every repository file at the revision the paper's `\snapshot` pins.
5. Prepend the release notes to `CHANGELOG.md` under a new `## vX.Y.Z (date)`
   heading. History is append-only — never rewrite earlier releases.
6. Tag the commit where the docs and the artifacts agree, and push the tag:
   ```bash
   git tag -a vX.Y.Z <commit> -m "vX.Y.Z stable: <docs> documents / <tokens> tokens / <n> sources"
   git push origin vX.Y.Z
   ```
   A release with no tag can only be cited by hash, and every later doc fix
   makes that hash a worse citation than the one before it — which is how
   `v0.2.5` ended up cited three different ways. Tag it once and cite the tag.

## Push to Hugging Face

`origin` is the Hub itself
(`https://huggingface.co/datasets/SlayerLab/polish-dynaword`) — there is no GitHub
remote. `git push` authenticates through the git credential helper (macOS:
`osxkeychain`), which is separate from `hf auth login`: pushes can work fine while
`hf auth whoami` still reports "Not logged in". The Python API and `hf` CLI need
the login (or `HF_TOKEN`).

Hub pull requests use no forks and no named branches. A PR *is* the ref
`refs/pr/N` and the Hub assigns `N`, so you cannot open one by pushing — the ref
has to exist first. (Plain branches can be pushed, but a branch is not a PR and
nobody reviews it.)

Open a PR for work already committed locally:

```bash
# 1. create the empty PR (needs the write token)
python3 -c "
from huggingface_hub import HfApi
pr = HfApi().create_pull_request(
    'SlayerLab/polish-dynaword', repo_type='dataset',
    title='<title>', description='<what changed and why>')
print(pr.num, pr.url)"

# 2. push your local branch onto that ref
git push origin <local-branch>:refs/pr/<N>
```

Opened this way the PR starts in **draft** — publish it from the web UI.

Pick up an existing PR (42 here):

```bash
GIT_LFS_SKIP_SMUDGE=1 git -c fetch.negotiationAlgorithm=noop fetch origin refs/pr/42:pr/42
git checkout pr/42
git push origin pr/42:refs/pr/42
```

The `noop` negotiation is needed: for some refs the Hub fails the have/ack
exchange (`fatal: expected 'acknowledgments'`), and skipping it makes the server
send the full history instead. `GIT_LFS_SKIP_SMUDGE=1` keeps it to pointers;
pull a single blob with `git lfs pull --include <path>`.

`repo_type='dataset'` is required on every `huggingface_hub` call — this is a
dataset repo, not a model. Push straight to `main` only when cutting a release.

## Do not commit

`*.log` (fetch/build logs), `.DS_Store`, `src/__pycache__/`. Only `logs/` is in
`.gitignore` — root-level logs and OS cruft are not, so check `git status`
before staging. `*.parquet` is LFS-tracked; commit the pointer, not the blob.

## Known drift / cleanup opportunities

- `europeana` is in `SOURCES` but has no `data/` shard anywhere. make_docs
  skips it with `! no stats`. Intentional placeholder or stale — confirm
  before relying on `build_dynaword.py --all`.
- make_docs computes the current release's totals from the `stats.json` files in
  the tree. After a released source is rebuilt on main, rerunning it with the
  same `VERSION` would move the released counts; bump `VERSION` first.
- `uzp_orzeczenia_pl` is in `SOURCES` (`release: None`), but its data is held off
  main until v0.2.8 (personal data). `src/build_uzp_orzeczenia_pl.py`, its
  tests and `artifacts/uzp_orzeczenia_pl_ontology_manifest.json` stay, and the
  legitimate-interest note is at `artifacts/uzp_orzeczenia_pl_legitimate_interest.md`
  until the shard returns; make_docs skips it with `! no stats`.
- `sejm_interpellations` is in `SOURCES` (`release: None`), but its data is held
  off main until v0.2.7 (letters from the public, some with health details).
  Its fetch and attribution scripts and tests stay; `src/conftest.py` and the
  attribution test's own guard skip the tests that read `data/sejm_interpellations/`,
  and make_docs skips it with `! no stats`.
- `parliamentary` ships without the Sejm's interpellations, questions and
  replies of the PPC dump: `HOLD_INTERPELLATIONS` in `src/fetch_parliamentary.py`
  counts them as `interpellation_held` until v0.2.7 (NERGAL pass). Their code
  path stays; `test_interpellations_are_built_whole_when_not_held` covers it.
  For v0.2.7, set the flag to False, rebuild and update the card and stats.
- `kultura_bez_barier_pl` is in `SOURCES` (`release: None`), but its data is
  held off main until the scope of its licence is answered. Its build, clean
  and licence-basis scripts, tests and
  `artifacts/kultura_bez_barier_pl_ontology_manifest.json` stay; `src/conftest.py`
  skips the tests that read `data/kultura_bez_barier_pl/`, and make_docs skips it
  with `! no stats`.
- The release tags `v0.2.0`-`v0.2.5` were deleted after the October 2026 rights
  audit, so `git checkout v0.2.x --` and `revision="v0.2.x"` fail for them.
  The eight builders whose inputs were only there (see CHANGELOG, Unreleased)
  stay as the record of how v0.2.6 was built; `src/test_cited_paths.py` accepts
  only `main` and tags from `v0.2.6` on.