Share one Polish-language gate (diacritic ratio, then langid vote); exempt plwiki and plwikivoyage (v2#77)

#85
by ppuzio - opened
Fabryka AI org

Fixes the non-Polish filter (slayerlabs/polish-dynaword-v2#77). This is one tooling PR, an approved exception to one-source-per-PR. It changes no parquet or card. The new gate takes effect at the rebuild after NERGAL (v2#60).

What changes

  • src/language_gate.py: the shared gate. It checks the diacritic ratio first (≥ 0.005 keeps the text without a langid call). A text below the ratio needs a three-window langid vote (first, middle and last 30k chars) that says pl. The vote runs over pl, en, de, cs, sk, uk and ru: with cs/sk left out, Czech and Slovak text scored as Polish.
  • build_dynaword.py and clean_samorzad_gov_pl.py call is_polish. stats.json records the gate in lang_gate.
  • wikipedia and wikivoyage are polish_by_origin in sources.py and skip the gate. The plwiki pages the old gate dropped are Polish articles: a Polish lead, then a list of foreign titles, names or species. Langid labels the list, not the article. That held in every sampled bucket, en/en/en and de/de/de included. The new gate would still drop 2,476 of the 5,564.
  • fetch_njkp.py keeps the diacritic ratio alone, because data/nkjp1m/ATTRIBUTION.md, agreed with IPI PAN, describes the filter that way. It now imports the ratio from the shared module.
  • The six copies of language_vote (nonsa, plwiki_talk, plwiki_usertalk, uzp_orzeczenia, wiadomosci_statystyczne, open_icm) import the shared one. The single-window classifiers in edukacja, kultura, open_agh, ted_pl and rock_pollub are unchanged: they classify one window, so their semantics differ.
  • Card bullet: make_docs.py and fetch_wikimedia.py word it with card_line(stats). Stats without lang_gate render the old (diacritic ratio) bullet, so cards are unchanged until the rebuild. The six template datasheets render byte-identical to the old code. wiktionary_examples already differed from its committed card before this change.

Effect on the old gate's drops (local inputs)

source old drops new gate keeps dropped by label
wikipedia 5,564 all (exempt) –
wikivoyage 9 all (exempt) –
wikibooks 531 121 en 171, ru 97, sk 56, uk 44, cs 29, de 13
govpl 24 6 uk 10, en 8
wikinews 6 2 en 3, de 1

Hand check

  • govpl: all 24 decisions are correct. The 6 kept are Polish notices: PDF lists, concessions, a road investment. The 18 dropped are English or Ukrainian translations.
  • wikinews: the 2 kept are Polish "Link do indeksu" markup stubs. The 4 dropped are cycling result tables with a Polish header and foreign rider and team names. Wikinews is on hold (lawyer question E3).
  • wikibooks:
    • Kept: 23 Polish lists (species, spreadsheet function names, Finnish–Polish country names, a prime factor table), 12 code pages and 86 Unicode code charts (Polish column headers over CJK, Hangul and other characters).
    • Dropped: 109 code pages (mostly Dive Into Python), German grammar exercises, one Czech dialogue, and 253 code charts.
    • Langid splits the 339 code charts between pl, sk, cs, ru, uk and en more or less at random. Whether they belong in the corpus is a quality question, not a language one, and is out of scope here.

Not measured

The inputs for biblioteka_nauki (925 old drops), samorzad_gov_pl, studia_bas and nkjp1m aren't local, and downloading them needs permission. The rebuild will show their counts.

Card text at the rebuild

  • Generated cards follow the stats. In wikivoyage the bullet becomes - drop non-Polish: not applied (Polish by origin). In wikibooks, wikinews and the six make_docs template cards it becomes - drop non-Polish (diacritic ratio, then langid vote): **N**.
  • The hand-written cards need a manual edit at the rebuild:
    • wikipedia: the gate isn't applied;
    • biblioteka_nauki, govpl and sejm_interpellations: the new gate wording;
    • nkjp1m: stays on the diacritic ratio.

Tests

  • pytest from the repo root: the 18 new tests in src/test_language_gate.py pass. They cover the ratio boundary, real langid labels, the vote's tie and dedup, the card bullet, the polish_by_origin set, and build_source writing lang_gate.
  • 67 tests fail or error both with and without this change. They are parquet contract tests, and the worktree has LFS pointers instead of the parquet files.

Sample (src/render_sample.py over the hand-checked rows)

wikibooks

id: wikibooks_59564
gate: drop
langid_votes: de/de/de

Übungen 

 Imperfekt (Präteritum)

 Ergänze die Verbformen im Präteritum und Perfekt:
 Beispiel:
  tragen      trug        getragen

{
|type="{}"}
fahren { fuhr } { gefahren }
graben { grub } { gegraben }
laden { lud } { geladen }
schaffen { schuf } { […]
id: wikibooks_40591
gate: keep
langid_votes: pl/pl/pl

Agrestowate (Grossulariaceae)
__NOTOC__

 Porzeczka (Ribes) 
 Porzeczka alpejska (Ribes alpinum L.) 

 Porzeczka czarna (Ribes nigrum L.) 

 Porzeczka skalna (Ribes petraeum Wulfen) 

 Porzeczka zwyczajna (Ribes rubrum L.) 

 Porzeczka czerwona (Ribes […]
id: wikibooks_44998
gate: keep
langid_votes: pl/pl/pl

Suomi - Finlandia

Puola - Polska

Saksa - Niemcy

Tšekki - Czechy

Kroatia - Chorwacja

Marokko - Maroko

Angolaa - Angola

Kiina - Chiny

Thaimaa - Tajlandia

Yhdysvallat - Stany Zjednoczone

Meksiko - Meksyk

Brasilia - Brazylia
id: wikibooks_47401
gate: keep
langid_votes: pl/pl/pl

Znak  DEC  HEX  UTF-8  Nazwa  Grupa ∀  8704  2200  0xE2 0x88 0x80  FOR ALL  Operatory matematyczne ∁  8705  2201  0xE2 0x88 0x81  COMPLEMENT  Operatory matematyczne ∂  8706  2202  0xE2 0x88 0x82  PARTIAL DIFFERENTIAL  Operatory matematyczne ∃  8707  2203 […]
id: wikibooks_31450
gate: keep
langid_votes: pl/pl/pl

C
#include <stdio.h>
#include <math.h>

const int MAX_SIZE = 1000;
bool mask0[MAX_SIZE], mask1[MAX_SIZE];

void maskStep(int step, int n)
{
    int i = step;
    while (i < n)
    {
        mask0[i] = true;
        i += step;
    }
}

void factor(const int n)
{
    int x = n;
    for (int […]
id: wikibooks_11928
gate: drop
langid_votes: en/en/en

"""Unit test for apihelper.py

This program is part of "Dive Into Python", a free Python book for
experienced programmers.  Visit http://diveintopython.org/ for the
latest version.
"""

__author__ = "Mark Pilgrim (mark@diveintopython.org)"
__version__ = […]
id: wikibooks_31312
gate: keep
langid_votes: pl/pl/uk

Tablica rozkładów na czynniki pierwsze dla liczb od 2 do 3000
Liczba
Czynniki pierwsze
2Liczba pierwsza nr 1
3Liczba pierwsza nr 2
4=2×2
5Liczba pierwsza nr 3
6=2×3
7Liczba pierwsza nr 4
8=2×2×2
9=3×3
10=2×5
11Liczba pierwsza nr 5
12=2×2×3
13Liczba pierwsza […]
id: wikibooks_47747
gate: drop
langid_votes: en/en/en

Znak  DEC  HEX  UTF-8  Nazwa  Grupa 쐀  50176  C400  0xEC 0x90 0x80    Sylaby hangyl 쐁  50177  C401  0xEC 0x90 0x81    Sylaby hangyl 쐂  50178  C402  0xEC 0x90 0x82    Sylaby hangyl 쐃  50179  C403  0xEC 0x90 0x83    Sylaby hangyl 쐄  50180  C404  0xEC 0x90 0x84 […]
id: wikibooks_6885
gate: drop
langid_votes: cs/cs/cs

W sklepie (V obchodu):

Tekst (text)
Jiří: Nevíš, kde je čaj nebo káva? 
Alena: Čaj už nemáme, včera jsem použila poslední sáček. 
Jiří: Ale kávu taky nemůžu najít. 
Alena: Ta už taky došla. 
Jiří: Co budeme večeřet? 
Alena: Ještě nevím, podívám se do […]

wikinews

id: wikinews_19355
gate: drop
langid_votes: en/en/en

Lista startowa tegorocznego Giro d’Italia

 LPR – L.P.R. Brakes –  
 Zawodnicy Koszulka1. Danilo Di Luca (1976 )
2. Paolo Bailetti (1980 )
3. Gabriele Bosisio (1980 )
4. Riccardo Chiarini (1984 )
5. Giairo Ermeti (1981 )
6. Jure Golcer (1977 )
7. Daniele […]
id: wikinews_54422
gate: keep
langid_votes: pl/pl/pl

Link do indeksu […]

govpl

id: govpl_drop_12
gate: drop
langid_votes: uk/uk/uk

Допомога громадянам України - Гаряча лінія 19524

Однією з таких інституцій є Інформаційно-консультаційний центр Центрів зайнятості «Зелена лінія». Це сучасний онлайн-уряд праці, відкритий для всіх, у будь-який час. Це інтернет-портал і гаряча лінія, де можна […]
id: govpl_drop_9
gate: keep
langid_votes: pl/pl/pl

ZRiD dla odcinka drogi wojewódzkiej nr 812

Ta inwestycja zwiększy poziom bezpieczeństwa wszystkich uczestników ruchu, w szczególności tych niechronionych: pieszych i rowerzystów - dzięki budowie ścieżek pieszo rowerowych i rowerowych oraz […]
id: govpl_drop_23
gate: keep
langid_votes: pl/pl/pl

Nowe stacje radiowe w Sandomierzu, Stalowej Woli i Tarnobrzegu

W Sandomierzu 99,7 MHz dla Radio Rekord FM S.A. na rozpowszechnianie programu: Radio Rekord Sandomierz.

W Stalowej Woli 105,0 MHz dla International Communication Sp. z o.o. na rozpowszechnianie […]
id: govpl_drop_1
gate: drop
langid_votes: en/en/en

Joint declaration of prime ministers of the State of Israel and the Republic of Poland

1. Over the last thirty years, the contacts between our countries and societies have been based on a well-grounded trust and understanding. Israel and Poland are devoted, […]

🤖 Generated with Claude Code

ppuzio changed pull request status to open
ppuzio changed pull request status to merged
ppuzio deleted the refs/pr/85 ref

Sign up or log in to comment