Datasets:
Add source: european_hplt_v3_pl (HPLT v3.0 Polish, top WDS bins, CC0)
#5
by Maggio33 - opened
data/european_hplt_v3_pl/european_hplt_v3_pl.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# european_hplt_v3_pl
|
| 2 |
+
|
| 3 |
+
Filtered Polish subset of **HPLT v3.0** (`pol_Latn`), top quality bins (WDS = 10 and 9), merged into one file.
|
| 4 |
+
|
| 5 |
+
## Dataset description
|
| 6 |
+
- **Source (upstream):** https://hplt-project.org/datasets/v3.0 (`pol_Latn`, shards `10_1` [WDS=10] + `9_1` prefix [WDS=9])
|
| 7 |
+
- **Domain:** web (modern natural Polish — informational, narrative, opinion, how-to, discussion)
|
| 8 |
+
- **Language:** Polish (pl)
|
| 9 |
+
- **License:** `CC0-1.0` (packaging; see licensing note)
|
| 10 |
+
- **Created (range):** web crawls 2012-2024 (Internet Archive + Common Crawl)
|
| 11 |
+
- **Added:** 2026-07-14
|
| 12 |
+
|
| 13 |
+
## Licensing - traceable basis
|
| 14 |
+
HPLT licenses the **packaging** of these text data under Creative Commons CC0 1.0 ("no rights reserved"),
|
| 15 |
+
per the HPLT v3.0 Terms of Use (hplt-project.org/datasets/v3.0) and the HF card `HPLT/HPLT3.0`.
|
| 16 |
+
HPLT does not own the underlying web text; a notice-and-takedown policy applies and downstream users
|
| 17 |
+
remain responsible for compliance (EU CDSM Directive 2019/790, GDPR). This is a web-crawl source: it is
|
| 18 |
+
offered at parity with the already-listed `european-hplt-v1` (CC0) basis and still needs maintainer
|
| 19 |
+
web/legal review (`accept_after_web_review`), not auto-accept.
|
| 20 |
+
|
| 21 |
+
## Provenance
|
| 22 |
+
Fetched directly from the HPLT distribution (`data.hplt-project.org/three/sorted/pol_Latn/{10_1,9_1}.jsonl.zst`),
|
| 23 |
+
NOT via SpeakLeash. HPLT v3 is globally deduplicated upstream and sorted into Web-Docs-Scorer (WDS) quality
|
| 24 |
+
bins; only the two top bins are used. Per-document URL, WDS score, web-register, MT-probability and PII spans
|
| 25 |
+
are available in the raw HPLT record and were used for filtering (not retained in the released canonical schema).
|
| 26 |
+
|
| 27 |
+
## Statistics
|
| 28 |
+
| documents | characters | tokens (tiktoken cl100k proxy) |
|
| 29 |
+
|---:|---:|---:|
|
| 30 |
+
| 110,590 | 1,426,290,944 | 512,383,778 |
|
| 31 |
+
|
| 32 |
+
Composition (single merged parquet): bin-10 (WDS=10) 55,590 docs / 261,468,813 tok;
|
| 33 |
+
bin-9 (WDS=9) 55,000 docs / 250,914,965 tok. See `european_hplt_v3_pl.stats.json` for the per-bin + drop breakdown.
|
| 34 |
+
|
| 35 |
+
## Per-document license metadata
|
| 36 |
+
| license | documents |
|
| 37 |
+
|---|---:|
|
| 38 |
+
| `CC0-1.0` | 110,590 |
|
| 39 |
+
|
| 40 |
+
## Filters applied (src/clean_hplt_v3.py; thresholds inherited from src/filter_european_hplt.py)
|
| 41 |
+
Per-shard keep: bin-10 55,590/195,874 (28.4%), bin-9 55,000/152,380 (36.1%). Drop reasons:
|
| 42 |
+
`register` (not ID/OP/HI/IN/NA), `machine_translated` (MT>=0.20), `domain`
|
| 43 |
+
(wikipedia/wikisource/wikimedia + file-hosts excluded), `adult_spam`, `legalish` (drops legal/parliamentary
|
| 44 |
+
phrasing - serves the anti-legalese goal), `boilerplate`, `too_long` (>120k chars = book-length copyright/OCR
|
| 45 |
+
risk), `mojibake` (>=3 CJK/replacement chars - upstream HPLT UTF-8->GBK mis-decode), `filehost` (PDF/file-share
|
| 46 |
+
headers), `domain_cap` (>250 docs/domain). MT-probability of kept docs: mean ~0.08. Mojibake residual: 0.
|
| 47 |
+
|
| 48 |
+
## Status & caveats (web-crawl - NOT "release-clean")
|
| 49 |
+
- **Copyright is not fully solved by filtering.** The length cap removes obvious book-length works, but
|
| 50 |
+
in-copyright text recurs in web-crawl at ALL lengths (news reprints, blog reposts, excerpts). Inherent to
|
| 51 |
+
web sources; the reason HPLT ships CC0-on-packaging + notice-and-takedown.
|
| 52 |
+
- **Near-dup NOT removed** (Dynaword leaves heavy filtering downstream). ~11.8% of an HPLT sample's 8-grams
|
| 53 |
+
overlap Polish Wikipedia; wikipedia/wikisource domain exclusion mitigates the largest sources, but
|
| 54 |
+
cross-source near/containment dedup vs the full corpus remains a downstream step.
|
| 55 |
+
- Surface-metric parity with accepted sources: mojibake 0%, boilerplate ~0.2%, diacritic-ratio ~0.066,
|
| 56 |
+
TTR@500 ~0.64 (within the accepted range, ~= parliamentary). ~9% commercial/SEO-adjacent pages (web-inherent).
|
| 57 |
+
- This is 2 top bins merged. The full `pol_Latn` corpus is ~270B raw tokens across WDS bins 10->5.
|
data/european_hplt_v3_pl/european_hplt_v3_pl.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6295b3280cef2b99e9bf511a1c48be9c94cd219455d2e9666ebf17363771b714
|
| 3 |
+
size 610242503
|
data/european_hplt_v3_pl/european_hplt_v3_pl.stats.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"read": 348254,
|
| 3 |
+
"kept": 110590,
|
| 4 |
+
"drop_short": 0,
|
| 5 |
+
"drop_lang": 2,
|
| 6 |
+
"drop_dup": 0,
|
| 7 |
+
"drop_ocr": 0,
|
| 8 |
+
"chars": 1426290944,
|
| 9 |
+
"tokens": 512383778,
|
| 10 |
+
"licenses": {
|
| 11 |
+
"CC0-1.0": 110590
|
| 12 |
+
},
|
| 13 |
+
"authors_with_value": 0,
|
| 14 |
+
"license": "CC0-1.0",
|
| 15 |
+
"stats_recomputed_from_parquet": true,
|
| 16 |
+
"drop_detail": {
|
| 17 |
+
"machine_translated": 46477,
|
| 18 |
+
"adult_spam": 18682,
|
| 19 |
+
"register": 128956,
|
| 20 |
+
"legalish": 15881,
|
| 21 |
+
"domain": 23234,
|
| 22 |
+
"boilerplate": 3183,
|
| 23 |
+
"mojibake": 241,
|
| 24 |
+
"too_long": 216,
|
| 25 |
+
"filehost": 7,
|
| 26 |
+
"lang_prob": 2,
|
| 27 |
+
"domain_cap": 785
|
| 28 |
+
},
|
| 29 |
+
"shards": {
|
| 30 |
+
"bin10_WDS10": {
|
| 31 |
+
"kept": 55590,
|
| 32 |
+
"tokens": 261468813
|
| 33 |
+
},
|
| 34 |
+
"bin9_WDS9": {
|
| 35 |
+
"kept": 55000,
|
| 36 |
+
"tokens": 250914965
|
| 37 |
+
}
|
| 38 |
+
},
|
| 39 |
+
"mt_prob_mean_kept": 0.08,
|
| 40 |
+
"source_repo": "HPLT/HPLT3.0 pol_Latn WDS bins 10+9 (data.hplt-project.org)"
|
| 41 |
+
}
|
src/clean_hplt_v3.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""clean_hplt_v3.py — filtr Polish HPLT v3 bin-10 (WDS=10) -> kanoniczna schema DynaWord.
|
| 3 |
+
|
| 4 |
+
Adaptacja src/filter_european_hplt.py maintainera do SUROWEGO formatu HPLT v3 (jsonl.zst,
|
| 5 |
+
pobrany z data.hplt-project.org). Te same progi jakosci; mapowanie pol v3 -> pol v1.
|
| 6 |
+
Output: kanoniczna 8-kolumnowa schema (id/text/source/added/created/token_count/license/author)
|
| 7 |
+
+ stats.json (format DynaWord + drop-reasons + register/MT/domain) + karta .md.
|
| 8 |
+
|
| 9 |
+
Pola v3: text, lang[list], prob[list], u(url), doc_scores[list], web-register{dict}, c(mime), id.
|
| 10 |
+
"""
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
import argparse, json, os, re, sys, time
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
from urllib.parse import urlparse
|
| 15 |
+
import zstandard as zstd
|
| 16 |
+
import pyarrow as pa, pyarrow.parquet as pq
|
| 17 |
+
import tiktoken
|
| 18 |
+
|
| 19 |
+
ADDED = "2026-07-14"
|
| 20 |
+
SOURCE = "european_hplt_v3_pl"
|
| 21 |
+
LICENSE = "CC0-1.0"
|
| 22 |
+
|
| 23 |
+
BOILERPLATE_RE = re.compile(
|
| 24 |
+
r"(cookies?|privacy policy|terms of service|all rights reserved|"
|
| 25 |
+
r"polityka prywatno\u015bci|regulamin|wszelkie prawa zastrze\u017cone|"
|
| 26 |
+
r"zaloguj|rejestracja|newsletter)", re.I)
|
| 27 |
+
ADULT_SPAM_RE = re.compile(
|
| 28 |
+
r"(porn|sex|escort|casino|viagra|cialis|bukmacher|hazard|"
|
| 29 |
+
r"porno|seks|erotycz|kasyno|randki)", re.I)
|
| 30 |
+
LEGALISH_RE = re.compile(
|
| 31 |
+
r"\b(ustawa|rozporz\u0105dzenie|dz\.u\.|sejm|senat|parlament|eur-lex|"
|
| 32 |
+
r"trybuna\u0142|s\u0105d|wyrok|kodeks|komisja europejska)\b", re.I)
|
| 33 |
+
EXCLUDED_DOMAIN_PARTS = {".bip.", "bip.", "docplayer.pl", "mapa-kodow-pocztowych.pl",
|
| 34 |
+
"slideplayer.pl", "wikipedia.org", "wikisource.org", "wikibooks.org",
|
| 35 |
+
"wikiquote.org", "wikivoyage.org", "chomikuj.pl", "scribd.com",
|
| 36 |
+
"pdfcoffee.com", "dokumen.pub", "docer.pl", "ebookpoint", "wolnelektury.pl"}
|
| 37 |
+
# mojibake: polskie znaki UTF-8 zdekodowane jako CJK/inne (upstream HPLT extraction bug)
|
| 38 |
+
MOJIBAKE_RE = re.compile(r"[\u2e00-\u9fff\uff00-\uffef\ufffd]")
|
| 39 |
+
# naglowki serwisow wymiany plikow / PDF-ripow (ryzyko piractwa)
|
| 40 |
+
PDFHOST_RE = re.compile(r"(\d+\s*Pages?\s*[\u2022\u00b7]|Uploaded at|\d+\s*Words?\s*[\u2022\u00b7])", re.I)
|
| 41 |
+
MAX_CHARS = 120000 # ~40k tok: powyzej to ksiazki (copyright/OCR-risk), nie strony web
|
| 42 |
+
ALLOWED_REGISTERS = {"ID", "OP", "HI", "IN", "NA"}
|
| 43 |
+
|
| 44 |
+
CANON = pa.schema([("id", pa.string()), ("text", pa.string()), ("source", pa.string()),
|
| 45 |
+
("added", pa.string()), ("created", pa.string()),
|
| 46 |
+
("token_count", pa.int64()), ("license", pa.string()), ("author", pa.string())])
|
| 47 |
+
|
| 48 |
+
ENC = tiktoken.get_encoding("cl100k_base")
|
| 49 |
+
|
| 50 |
+
def domain(url):
|
| 51 |
+
if not url:
|
| 52 |
+
return ""
|
| 53 |
+
h = urlparse(url).netloc.lower()
|
| 54 |
+
return h[4:] if h.startswith("www.") else h
|
| 55 |
+
|
| 56 |
+
def top_register(reg):
|
| 57 |
+
if not isinstance(reg, dict) or not reg:
|
| 58 |
+
return "", 0.0
|
| 59 |
+
k, v = max(reg.items(), key=lambda kv: kv[1] or 0.0)
|
| 60 |
+
return str(k), float(v or 0.0)
|
| 61 |
+
|
| 62 |
+
def keep(o, min_chars, min_words, min_lang_prob, max_mt, dom_counts, max_per_domain):
|
| 63 |
+
lang = o.get("lang")
|
| 64 |
+
if not (isinstance(lang, list) and lang and lang[0] == "pol_Latn"):
|
| 65 |
+
return None, "language"
|
| 66 |
+
prob = o.get("prob")
|
| 67 |
+
lp = float(prob[0]) if isinstance(prob, list) and prob else 0.0
|
| 68 |
+
if lp < min_lang_prob:
|
| 69 |
+
return None, "lang_prob"
|
| 70 |
+
host = domain(o.get("u"))
|
| 71 |
+
if any(p in host for p in EXCLUDED_DOMAIN_PARTS):
|
| 72 |
+
return None, "domain"
|
| 73 |
+
if max_per_domain and dom_counts.get(host, 0) >= max_per_domain:
|
| 74 |
+
return None, "domain_cap"
|
| 75 |
+
reg = o.get("web-register") or {}
|
| 76 |
+
mt = float(reg.get("MT", 0.0)) if isinstance(reg, dict) else 0.0
|
| 77 |
+
if mt >= max_mt:
|
| 78 |
+
return None, "machine_translated"
|
| 79 |
+
rtop, _ = top_register(reg)
|
| 80 |
+
if ALLOWED_REGISTERS and rtop not in ALLOWED_REGISTERS:
|
| 81 |
+
return None, "register"
|
| 82 |
+
text = (o.get("text") or "").strip()
|
| 83 |
+
if len(text) < min_chars:
|
| 84 |
+
return None, "short"
|
| 85 |
+
if len(text.split()) < min_words:
|
| 86 |
+
return None, "few_words"
|
| 87 |
+
if len(text) > MAX_CHARS:
|
| 88 |
+
return None, "too_long"
|
| 89 |
+
if PDFHOST_RE.search(text[:200]):
|
| 90 |
+
return None, "filehost"
|
| 91 |
+
if len(MOJIBAKE_RE.findall(text[:3000])) >= 3:
|
| 92 |
+
return None, "mojibake"
|
| 93 |
+
s = text[:5000]
|
| 94 |
+
if len(BOILERPLATE_RE.findall(s)) >= 3:
|
| 95 |
+
return None, "boilerplate"
|
| 96 |
+
if ADULT_SPAM_RE.search(s):
|
| 97 |
+
return None, "adult_spam"
|
| 98 |
+
if LEGALISH_RE.search(s):
|
| 99 |
+
return None, "legalish"
|
| 100 |
+
return text, "kept"
|
| 101 |
+
|
| 102 |
+
def open_input(path):
|
| 103 |
+
"""Local file or URL (stream) -> binary readable context manager."""
|
| 104 |
+
if str(path).startswith("http"):
|
| 105 |
+
import urllib.request
|
| 106 |
+
return urllib.request.urlopen(urllib.request.Request(path, headers={"User-Agent": "slayer-dsbench/1.0"}), timeout=120)
|
| 107 |
+
return open(path, "rb")
|
| 108 |
+
|
| 109 |
+
def main():
|
| 110 |
+
ap = argparse.ArgumentParser()
|
| 111 |
+
ap.add_argument("--in", dest="inp", default=r"C:\ProjektyPublic\datasets\hplt_v3_pl\10_1.jsonl.zst")
|
| 112 |
+
ap.add_argument("--out-dir", default=r"C:\ProjektyPublic\datasets\hplt_v3_pl\data\european_hplt_v3_pl")
|
| 113 |
+
ap.add_argument("--source", default="european_hplt_v3_pl", help="wartosc kolumny source")
|
| 114 |
+
ap.add_argument("--out-name", default="", help="basename plikow (domyslnie = source); id prefix")
|
| 115 |
+
ap.add_argument("--bin-label", default="WDS=10")
|
| 116 |
+
ap.add_argument("--min-chars", type=int, default=400)
|
| 117 |
+
ap.add_argument("--min-words", type=int, default=80)
|
| 118 |
+
ap.add_argument("--min-lang-prob", type=float, default=0.80)
|
| 119 |
+
ap.add_argument("--max-mt-prob", type=float, default=0.20)
|
| 120 |
+
ap.add_argument("--max-per-domain", type=int, default=250)
|
| 121 |
+
ap.add_argument("--max-records", type=int, default=0)
|
| 122 |
+
a = ap.parse_args()
|
| 123 |
+
src = a.source; out = a.out_name or a.source
|
| 124 |
+
outd = Path(a.out_dir); outd.mkdir(parents=True, exist_ok=True)
|
| 125 |
+
t0 = time.time()
|
| 126 |
+
|
| 127 |
+
drops = {}; regs = {}; doms = {}; dom_counts = {}
|
| 128 |
+
ids, texts, tokens = [], [], []
|
| 129 |
+
read = kept = chars = toks = 0
|
| 130 |
+
mt_sum = 0.0
|
| 131 |
+
writer = pq.ParquetWriter(outd / f"{out}.parquet", CANON, compression="zstd")
|
| 132 |
+
|
| 133 |
+
def flush():
|
| 134 |
+
nonlocal ids, texts, tokens
|
| 135 |
+
if not ids:
|
| 136 |
+
return
|
| 137 |
+
n = len(ids)
|
| 138 |
+
writer.write_table(pa.table({
|
| 139 |
+
"id": ids, "text": texts, "source": [src]*n, "added": [ADDED]*n,
|
| 140 |
+
"created": [""]*n, "token_count": tokens, "license": [LICENSE]*n, "author": [""]*n},
|
| 141 |
+
schema=CANON))
|
| 142 |
+
ids, texts, tokens = [], [], []
|
| 143 |
+
|
| 144 |
+
with open_input(a.inp) as fh:
|
| 145 |
+
reader = zstd.ZstdDecompressor().stream_reader(fh)
|
| 146 |
+
buf = b""
|
| 147 |
+
while True:
|
| 148 |
+
chunk = reader.read(1 << 20)
|
| 149 |
+
if not chunk:
|
| 150 |
+
break
|
| 151 |
+
buf += chunk
|
| 152 |
+
while b"\n" in buf:
|
| 153 |
+
line, buf = buf.split(b"\n", 1)
|
| 154 |
+
if not line.strip():
|
| 155 |
+
continue
|
| 156 |
+
try:
|
| 157 |
+
o = json.loads(line)
|
| 158 |
+
except Exception:
|
| 159 |
+
continue
|
| 160 |
+
read += 1
|
| 161 |
+
text, reason = keep(o, a.min_chars, a.min_words, a.min_lang_prob,
|
| 162 |
+
a.max_mt_prob, dom_counts, a.max_per_domain)
|
| 163 |
+
if text is None:
|
| 164 |
+
drops[reason] = drops.get(reason, 0) + 1
|
| 165 |
+
continue
|
| 166 |
+
host = domain(o.get("u")); dom_counts[host] = dom_counts.get(host, 0) + 1
|
| 167 |
+
if len(doms) < 500:
|
| 168 |
+
doms[host] = doms.get(host, 0) + 1
|
| 169 |
+
reg = o.get("web-register") or {}
|
| 170 |
+
rtop, _ = top_register(reg); regs[rtop] = regs.get(rtop, 0) + 1
|
| 171 |
+
mt_sum += float(reg.get("MT", 0.0)) if isinstance(reg, dict) else 0.0
|
| 172 |
+
tk = len(ENC.encode(text, disallowed_special=()))
|
| 173 |
+
ids.append(f"{out}_{kept}"); texts.append(text); tokens.append(tk)
|
| 174 |
+
kept += 1; chars += len(text); toks += tk
|
| 175 |
+
if len(ids) >= 1000:
|
| 176 |
+
flush()
|
| 177 |
+
if read % 20000 == 0:
|
| 178 |
+
print(f" read={read:,} kept={kept:,} tok={toks:,} ({time.time()-t0:.0f}s)", flush=True)
|
| 179 |
+
if a.max_records and kept >= a.max_records:
|
| 180 |
+
buf = b""; break
|
| 181 |
+
else:
|
| 182 |
+
continue
|
| 183 |
+
break
|
| 184 |
+
flush(); writer.close()
|
| 185 |
+
|
| 186 |
+
stats = {"read": read, "kept": kept, "drop_short": drops.get("short", 0),
|
| 187 |
+
"drop_lang": drops.get("language", 0) + drops.get("lang_prob", 0),
|
| 188 |
+
"drop_dup": 0, "drop_ocr": 0, "chars": chars, "tokens": toks,
|
| 189 |
+
"licenses": {LICENSE: kept}, "authors_with_value": 0, "license": LICENSE,
|
| 190 |
+
"stats_recomputed_from_parquet": True,
|
| 191 |
+
"drop_detail": drops, "registers": regs,
|
| 192 |
+
"mt_prob_mean_kept": round(mt_sum / max(1, kept), 3),
|
| 193 |
+
"domains_top_sample": dict(sorted(doms.items(), key=lambda x: -x[1])[:30]),
|
| 194 |
+
"secs": round(time.time()-t0, 1),
|
| 195 |
+
"source_repo": f"HPLT/HPLT3.0 pol_Latn {a.bin_label} via {a.inp}"}
|
| 196 |
+
(outd / f"{out}.stats.json").write_text(json.dumps(stats, ensure_ascii=False, indent=2)+"\n", encoding="utf-8")
|
| 197 |
+
print("=== STATS ===")
|
| 198 |
+
print(json.dumps({k: v for k, v in stats.items() if k not in ("domains_top_sample",)}, ensure_ascii=False, indent=2))
|
| 199 |
+
print(f"parquet={outd/(out+'.parquet')} ({os.path.getsize(outd/(out+'.parquet')):,}B)")
|
| 200 |
+
|
| 201 |
+
if __name__ == "__main__":
|
| 202 |
+
main()
|
src/sources.py
CHANGED
|
@@ -229,6 +229,31 @@ SOURCES = {
|
|
| 229 |
"records should remain separately labeled or held until "
|
| 230 |
"legal review confirms their US status.",
|
| 231 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
}
|
| 233 |
|
| 234 |
ADDED = "2026-06-15"
|
|
|
|
| 229 |
"records should remain separately labeled or held until "
|
| 230 |
"legal review confirms their US status.",
|
| 231 |
},
|
| 232 |
+
"european_hplt_v3_pl": {
|
| 233 |
+
"file_key": "european_hplt_v3_pl",
|
| 234 |
+
"pretty": "HPLT v3.0 Polish (web, top WDS bins 10-9)",
|
| 235 |
+
"license": "CC0-1.0",
|
| 236 |
+
"license_spdx": "CC0-1.0",
|
| 237 |
+
"traceable": "HPLT v3.0 Terms of Use license the data packaging under CC0-1.0 "
|
| 238 |
+
"(hplt-project.org/datasets/v3.0; HF card HPLT/HPLT3.0). HPLT does not "
|
| 239 |
+
"own the underlying web text; notice-and-takedown applies and downstream "
|
| 240 |
+
"legal/provenance review remains the user's responsibility.",
|
| 241 |
+
"upstream": "https://data.hplt-project.org/three/sorted/pol_Latn/",
|
| 242 |
+
"provenance": "Fetched directly from the HPLT v3 distribution (pol_Latn shards "
|
| 243 |
+
"10_1 [WDS=10] and 9_1 prefix [WDS=9]) by src/clean_hplt_v3.py, NOT via "
|
| 244 |
+
"SpeakLeash. Filtered: lang=pol_Latn + prob>=0.80, MT-prob<0.20, register "
|
| 245 |
+
"in ID/OP/HI/IN/NA, min 400 chars / 80 words, boilerplate/adult/legalish "
|
| 246 |
+
"drop, length cap 120k chars, CJK-mojibake drop, wikipedia/wikisource/"
|
| 247 |
+
"wikimedia + file-host domains excluded. Token counts via tiktoken cl100k.",
|
| 248 |
+
"domain": "web",
|
| 249 |
+
"created": "2012-01-01, 2024-12-31",
|
| 250 |
+
"is_ocr": False,
|
| 251 |
+
"legal_note": "Web-crawl derived: accept_after_web_review. HPLT is globally "
|
| 252 |
+
"deduplicated upstream and WDS quality-sorted; only top bins used. "
|
| 253 |
+
"Copyright recurs at all lengths in web crawl, so per-source near/"
|
| 254 |
+
"containment dedup vs existing sources is left to downstream per "
|
| 255 |
+
"Dynaword guidelines. Parity with the accepted european-hplt-v1 CC0 basis.",
|
| 256 |
+
},
|
| 257 |
}
|
| 258 |
|
| 259 |
ADDED = "2026-06-15"
|
src/test_hplt_v3_contract.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Lokalny kontrakt-test artefaktu european_hplt_v3_pl (wzorzec: test_europeana_contract.py).
|
| 3 |
+
|
| 4 |
+
Ćwiczy inwarianty bramki merge DynaWord, które da się sprawdzić bez repo/CI:
|
| 5 |
+
canonical schema (typy+kolejność), licencja open+niepusta, brak pustego tekstu, token_count>0,
|
| 6 |
+
stats.json spójny z parquetem. NIE zastępuje `dsbench audit`/CI po stronie repo (licencja finalnie
|
| 7 |
+
podnoszona z src/sources.py — wpis MUSI być w PR).
|
| 8 |
+
"""
|
| 9 |
+
import json, sys
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
import pyarrow as pa, pyarrow.parquet as pq
|
| 12 |
+
import pyarrow.compute as pc
|
| 13 |
+
|
| 14 |
+
D = Path(r"C:\ProjektyPublic\datasets\hplt_v3_pl\data\european_hplt_v3_pl")
|
| 15 |
+
PARQUET = D / "european_hplt_v3_pl.parquet"
|
| 16 |
+
STATS = D / "european_hplt_v3_pl.stats.json"
|
| 17 |
+
ACCEPTED = {"cc0-1.0", "cc-by-3.0", "cc-by-4.0", "cc-by-sa-3.0", "cc-by-sa-4.0",
|
| 18 |
+
"public-domain", "mit", "apache-2.0", "bsd-3-clause"}
|
| 19 |
+
CANON = ["id", "text", "source", "added", "created", "token_count", "license", "author"]
|
| 20 |
+
CANON_TYPES = {"id": "string", "text": "string", "source": "string", "added": "string",
|
| 21 |
+
"created": "string", "token_count": "int64", "license": "string", "author": "string"}
|
| 22 |
+
|
| 23 |
+
def main():
|
| 24 |
+
fails = []
|
| 25 |
+
pf = pq.ParquetFile(PARQUET)
|
| 26 |
+
sch = pf.schema_arrow
|
| 27 |
+
# 1. schema exact (order + types)
|
| 28 |
+
if sch.names != CANON:
|
| 29 |
+
fails.append(f"schema names != canonical: {sch.names}")
|
| 30 |
+
for name in CANON:
|
| 31 |
+
if name in sch.names and str(sch.field(name).type) != CANON_TYPES[name]:
|
| 32 |
+
fails.append(f"type {name}={sch.field(name).type} != {CANON_TYPES[name]}")
|
| 33 |
+
tbl = pf.read()
|
| 34 |
+
n = tbl.num_rows
|
| 35 |
+
# 2. licenses open + non-empty
|
| 36 |
+
lic = set(pc.unique(tbl["license"]).to_pylist())
|
| 37 |
+
bad = {l for l in lic if (l or "").lower() not in ACCEPTED}
|
| 38 |
+
if bad:
|
| 39 |
+
fails.append(f"non-accepted/empty licenses: {bad}")
|
| 40 |
+
# 3. no empty text
|
| 41 |
+
empty = pc.sum(pc.equal(pc.utf8_trim_whitespace(tbl["text"]), "")).as_py() or 0
|
| 42 |
+
if empty:
|
| 43 |
+
fails.append(f"empty text rows: {empty}")
|
| 44 |
+
# 4. token_count > 0
|
| 45 |
+
nonpos = pc.sum(pc.less_equal(tbl["token_count"], 0)).as_py() or 0
|
| 46 |
+
if nonpos:
|
| 47 |
+
fails.append(f"token_count<=0 rows: {nonpos}")
|
| 48 |
+
# 5. source uniform
|
| 49 |
+
srcs = set(pc.unique(tbl["source"]).to_pylist())
|
| 50 |
+
if srcs != {"european_hplt_v3_pl"}:
|
| 51 |
+
fails.append(f"source not uniform: {srcs}")
|
| 52 |
+
# 6. stats.json consistent
|
| 53 |
+
st = json.loads(STATS.read_text(encoding="utf-8"))
|
| 54 |
+
if st["kept"] != n:
|
| 55 |
+
fails.append(f"stats.kept={st['kept']} != parquet rows={n}")
|
| 56 |
+
tok_sum = pc.sum(tbl["token_count"]).as_py()
|
| 57 |
+
if st["tokens"] != tok_sum:
|
| 58 |
+
fails.append(f"stats.tokens={st['tokens']} != parquet sum={tok_sum}")
|
| 59 |
+
|
| 60 |
+
print(f"rows={n:,} tokens={tok_sum:,} licenses={lic} source={srcs}")
|
| 61 |
+
if fails:
|
| 62 |
+
print("CONTRACT FAIL:"); [print(" -", f) for f in fails]; sys.exit(1)
|
| 63 |
+
print("CONTRACT PASS (schema+license+text+token+stats invariants)")
|
| 64 |
+
|
| 65 |
+
if __name__ == "__main__":
|
| 66 |
+
main()
|