polish-dynaword / AGENTS.md
kacperwikiel's picture
Contributor guidance: source findings log + PR/normalization requirements (#17)
a9d134a
|
Raw
History Blame
8.59 kB
# AGENTS.md
Guidance for agents and contributors adding a source and cutting a release.
Read this before opening a PR — several recent contributions added data but
skipped the doc/version bump, forcing a maintainer cleanup release.
## How the docs are actually maintained
`src/make_docs.py` is a **scaffolding/assembly helper, not a round-trip source
of truth.** It regenerates the README source table + release totals, `LICENSE`,
a `CHANGELOG` stub, and *template* datasheets — but it does **not** reproduce the
committed docs on its own:
- 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 every regenerated datasheet's "Added" with the single global `ADDED`
constant, overwriting real per-source add dates.
- It cannot reproduce hand-written README narrative (audit notes, policy notes,
the phrase-frequency section).
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.
## 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.
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.
## 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.
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**: scrub before the parquet is written, not after. At minimum
email addresses, phone numbers, and national identifiers (PESEL, NIP, REGON,
account numbers). Replace with a stable placeholder (`[PII]`, `[Telefon]`)
rather than deleting, so sentence structure survives. Names of public
officials acting in an official capacity are not PII and should stay —
removing them would gut parliamentary and judicial sources.
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 (the part that gets skipped)
1. In `src/make_docs.py`: bump `VERSION` and `RELEASE_DATE`. Add a row for the new
version to the version table and a row for yourself to the Contributors table
(both are literal rows in the template).
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. Splice the tables
and chart embeds into the README "Results" section by hand.
3. Update `README.md` by hand: header totals, version table, source table row,
Contributors row. The document/token totals must equal the sum of the
per-source `stats.json` files.
4. Prepend the release notes to `CHANGELOG.md` under a new `## vX.Y.Z (date)`
heading. History is append-only — never rewrite earlier releases.
## 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
- `biblioteka_nauki`, `europeana`, `parlamint_pl` are in `SOURCES` but have no
`data/` shard (make_docs skips them with `! no stats`). Intentional placeholders
or stale — confirm before relying on `build_dynaword.py --all`.
- The global `ADDED` datasheet stamp is a footgun: give datasheets a per-source
add date (or `custom_datasheet`) before making make_docs regenerate them.