Skip to content

Kategorie, blueprinty, odpowiedzi na pisma, trasa general i bramki bezpieczeństwa - #4

Merged
empios merged 91 commits into
mainfrom
detect/burstiness-and-profile
Nov 17, 2026
Merged

empios merged 91 commits into
mainfrom
detect/burstiness-and-profile

Conversation

@empios

@empios empios commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Zakres

88 commitów od 7815d41. Najważniejsze obszary:

  • Kategorie i blueprinty: nowe kategorie dokumentów, szablony Layout IR (data/templates/) i ogólne dokumenty do wypełnienia per kategoria; rozpoznawanie sekcji po kształcie, stron po formułach wprowadzających, miejsca i daty, wniosków procesowych; formularze apelacji, zażaleń, odpowiedzi na pozew i na wezwanie do zapłaty.
  • Odpowiedzi na pisma (replies/): odczyt pism przychodzących, lista dopuszczalnych odpowiedzi, liczenie terminów (ostatni dzień), adresat odpowiedzi, odrzucanie środków wyłączonych przez prawomocne rozstrzygnięcie.
  • Bezpieczeństwo: modalność w każdej formie fleksyjnej (w tym „można”, „trzeba”), bramka negacji, zamiana ról i nazw stron, zmiana czynności prawnej, słowa spoza polszczyzny; jednoprzebiegowa ochrona bez zagnieżdżonych placeholderów.
  • Reguły: strona bierna, „na podstawie”, „w celu”, czasowniki lekkie, dzielenie długich zdań tylko przy orzeczeniu, porównanie kotwic po lemacie.
  • LLM / trasa general: przepisywanie całych akapitów tekstu nieprawniczego (wybór użytkownika), ogrodzenie fragmentu, jedna poprawka po odrzuceniu, limity z .env, wyłączanie „thinking”, ponowny przebieg reguł po akceptacji.
  • NLI: model trenowany na polskim, wzajemna implikacja, dzielenie zbyt długich par.
  • Detekcja i ewaluacja: FOG-PL przed/po, próg przeglądu na bieżących modelach, burstiness, profil saos_train_1804, baseline eval dla struktury i jakości przepisania.
  • Narzędzia: pobieranie otwarcie licencjonowanych zbiorów (dyskusje Wikipedii, opinie Allegro, CC BY-SA) z obsługą limitów.
  • DOCX I/O: edycje w obrębie runów, tabulatory i łamania wierszy zachowane.

Anonimizacja

Przed wypchnięciem przeskanowano diff pod PESEL, NIP, KRS, IBAN, telefony, e-maile, adresy, nazwiska, sygnatury i ścieżki lokalne. Jedyny konkretny adres pochodzący z dokumentu źródłowego (szablon umowy odśnieżania) zastąpiono polem do wypełnienia (type: address) z przepisaniem historii. Pozostałe dane w testach i fixture'ach są fikcyjne (Jan Kowalski, NIP 525-123-45-67 itp.).

Scalenie z main

Gałąź rozeszła się z origin/main (PR #3, 68 commitów: drafting brakujących sekcji, rhythm, nli.py, wspólny flow/CLI, kontrolki prywatności w UI). Zgodnie z decyzją, że lokalny main jest źródłem prawdy, origin/main scalono strategią ours: te commity zostają w historii, ale ich zmiany nie wchodzą do kodu. Po scaleniu tego PR kod main będzie równy tej gałęzi.

Testy

  • ruff check .: czysto
  • pytest -q: 628 passed

🤖 Generated with Claude Code

empios and others added 30 commits September 29, 2026 09:30
…egory

Add layout_ir (extract/fill/evaluate), precise templates under data/templates,
and a general 'document' section in each category blueprint. Check runs the
general blueprint first, then the matched template.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Candidates that reversed polarity passed every check: "odpowiada" ->
"nie odpowiada", "bez wypowiedzenia" -> "z zachowaniem wypowiedzenia",
"nie zabrania się" -> "zabrania się". The new negation_preserved check
counts nie/brak/bez before and after; the double-negation rule
legal_style:ma_granice is exempt.

Modal detection: negated "należy" forbids, a negated prohibition permits,
"wolno" counts as permission, and a conjunction or "nie tylko" ends the
reach of "nie". Code abbreviations (k.c., k.p.c., ...) join the legal
reference inventory.

Reports looked the deontic check up as "normativity_preserved", a name
nothing emits, so its label never showed and normativity_changes_blocked
was always 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Patterns ran one after another, so a quote holding a reference or name
got a placeholder whose stored value contained another placeholder.
restore() then left "__PROTECTED_0000__" in skipped-sentence and
rejection reports, and every candidate in such a sentence failed the
placeholder-leak check. The final text was clean only because restore
ran twice.

All patterns now match in one pass: the leftmost match wins, so a quote
takes the references inside it, and placeholders follow text order.

re_protect() mapped every occurrence of a repeated fragment ("art. 5"
twice) to the first placeholder, so agreement repairs in such sentences
failed the numbers check. The n-th occurrence now gets the n-th
placeholder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three checks rejected sound edits:
- balanced_punctuation counted marks in the candidate alone, so inline
  lists ("1) ..., 2) ...") and „...“ quotes failed every candidate. It
  now rejects only an imbalance the candidate adds.
- The validator and the Stanza gate split sentences at every ". ", so
  "2024 r. w Krakowie" or "art. 471 k.c. do szkody" left a verbless
  fragment and failed the finite-verb check. Both now use the
  pipeline's splitter.
- Protector patterns for "§ 5", "10%", "2024 r." and "Dz. U." never
  matched (a \b next to a non-word character). They now do; the period
  after "r" stays outside the placeholder so sentence ends stay
  visible. Amounts also cover "10 000 zł", "1.000,00 zł" and "złotych",
  and the inventory tracks the same values plus standalone "§".

On the blueprint/template corpus (107 files) rejections fall from 248
to 66. Some unblocked edits come from rules that were only stopped by
accident: passive_to_impersonal with a preceding subject ("Umowa
sporządzono"), "w oparciu o" -> "na podstawie" without the genitive,
and cleanup_spacing gluing "w ......" blanks. Those rules make the same
errors on main and need their own fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Measured on the blueprint/template corpus, three rules produced broken
Polish on main:

- passive_to_impersonal took the word after the participle for the
  subject. With the subject before the verb that left it nominative
  ("Umowa sporządzono", "Uchwała podjęto"), it read "poza" as a noun
  ("pozę lokalem"), and Morfeusz's adjective reading of "umowa" kept it
  out of the accusative ("Zawarto umowa"). The subject is now the run of
  nominatives agreeing with the auxiliary, headed by its last possible
  noun; a subject before the verb is kept only when it reads the same in
  the accusative ("raport sporządzono", "co potwierdzono"). Clauses with
  an agent ("przez") or coordination are left alone, and without
  Morfeusz the rule no longer fires ("Przeprowadzono analiza").
  accusative_form_for_noun now finds masculine personal accusatives
  tagged gen.acc ("prezesa").
- "w oparciu o" -> "na podstawie" kept the accusative ("na podstawie
  przepisy"). The noun phrase is now put in the genitive with Morfeusz,
  a protected reference is kept as is, and the rewrite is skipped when
  the phrase cannot be inflected or the clause coordinates.
- cleanup_spacing turned non-breaking spaces into plain ones, collapsed
  tabs and alignment runs in signature lines, glued fill-in blanks to
  the previous word ("w......") and split "12:00" into "12: 00". It now
  collapses only 2-3 space typos and leaves blanks, tabs and NBSP alone.

Corpus (107 files): accepted edits 979 -> 577, rejected 66 -> 21,
passive rewrites 53 -> 1 (the one grammatical case). Benchmark: 91 -> 90.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The detector lists "w znacznym stopniu" among AI style frames, so the
rewrite turned an unflagged phrase into a flagged one. On the benchmark
it fired 6 times and pushed ai_legal_07_pozew_zaplate over the
style-compliance limit (AI signal 0.93 -> 0.97), which made
`make release-check` fail. Without it that document scores 0.80 and
the release check passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
legal_anchor_terms stemmed words only when five letters remained, so
"umowa"/"umowę"/"umowie", "sąd"/"sądu" or "kara"/"karę" were different
anchors and any rewrite changing their case lost one. On the template
corpus that rejected 5 correct passive rewrites ("Zawarto umowę
następującej treści"). Anchors are now keyed by Morfeusz lemma, with the
old stem as fallback.

MONEY_DATE_PATTERN had a \b after "r." and "%", so "2024 r." and "10%"
never counted toward legal_risk_score.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without a final ".!?" the rule appended a period: "umowa najmu:" became
"umowę najmu:." and "(... umowa)" became "(... umowę).".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Any two capitalised words counted as a party name, so "Niniejsza Umowa",
"Niniejszy Regulamin" or "Ponadto Strona" at the start of a sentence
were names, and "Niniejsza Umowa" -> "Ta Umowa" failed the inventory
check. At a sentence start the first word is now dropped when Morfeusz
knows it only as a common word; "Jan", "Anna" or "Róża" have proper-noun
readings and stay. On the template corpus party-name rejections fall
from 13 to 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reductions that delete a complement noun left its dependents behind:
"dokonać zmiany umowy" -> "zmienić umowy", "przeprowadzić analizę
prawną" -> "przeanalizować prawną", "sprawuje nadzór nad spółką" ->
"nadzoruje nad spółką". The Stanza checks only looked for genitive
noun dependents and the regex fallbacks used without Stanza had no
check at all; tests asserted outputs such as "przeanalizować
dokumentów". Both paths now skip a reduction when the deleted noun has
any dependent: with Stanza from the parse, without it through
dependents_follow (a nominal or abbreviation next, or "nad"/"o"/"do";
other prepositions and conjunctions start a new phrase).

"w celu GER" -> "aby INF" kept the gerund's genitive object ("aby
sprawować opieki", "aby zapewnić właściwego poziomu"), dropped the comma
"aby" needs, and fronted "Aby ..." without a closing comma. It now
rewrites only after a main clause, as ", aby ...", and skips a gerund
followed by a possible genitive, an agent ("przez") or coordination.

Template corpus: 25 ungrammatical nominalization edits gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fragment, previous and next paragraphs and the outline were each
protected on their own, so "__PROTECTED_0000__" named a different value
in every section of the prompt. Context placeholders now continue the
fragment's numbering; one a model copies into its proposal cannot be
restored and fails the placeholder-leak check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three faults in replace_unit_text and the text it edits:
- Paragraph text joined only w:t nodes, so tabs and line breaks
  vanished and words around them were glued ("Jan KowalskiNajemca:").
  Tabs now read as "\t" and line breaks as "\v"; edits may not change
  them.
- Edits were merged into one span from the first change to the last
  and written into the first run, so unchanged text between them moved
  across runs, breaks and formatting. In a signature block one spacing
  fix moved "Najemca:" to the line above. Each diff region is now
  applied to the runs it touches; one that would straddle a tab, line
  break, hyperlink edge, footnote mark or drawing leaves the paragraph
  unchanged, and the caller reports it.
- Edited w:t nodes got edge spaces without xml:space="preserve", which
  Word drops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
process_paragraph rejoined sentences with a single space, so a tab, line
break or double space between two sentences changed even when no rule
fired ("§ 2.\t ZOBOWIĄZANIA" -> "§ 2. ZOBOWIĄZANIA", reported as a
change with no entry). In DOCX, where a line break now reads as "\v",
it also made every edit in such a paragraph fail the run guard.
Sentences are now rejoined with their original separators.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
", a także o wszelkich planowanych zmianach, które mogą ..." was split
into "... Ponadto o wszelkich planowanych zmianach, które mogą ...": the
right half joins a second object to the same verb, and its only finite
verb sat in a relative clause, which satisfied the check. The new
sentence now needs a finite verb before its first comma.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Found by reviewing every accepted edit on the template and test corpora:

- drop_tautological_adj_pair used every Słowosieć synset pair, so
  polysemy made doublets of "zielony"/"szary" and cut "jasny" from the
  GDPR formula "w sposób jasny i zrozumiały". Standard mode now uses
  only the curated formulas (konieczny/niezbędny and całkowity/zupełny
  added); the synset pairs stay for strong mode.
- drop_repeated_opening dropped any opening the previous sentence
  merely mentioned, and guessed verbs from suffixes: "Kwotę proszę
  wpłacić" lost the amount, "Osiemdziesiąt rubli! – powtórzyła" became
  "! – powtórzyła", "Można było" became "Było". It now drops only the
  words the previous sentence opened with, when their head can be a
  nominative subject (no pred or particle reading) and Morfeusz finds a
  third-person predicate after them.
- drop_wlasnie capitalised mid-sentence: "Nogi, to właśnie" -> "Nogi, To".
- split_long_sentence split "ale jednak" into "..., ale. Jednak"; a
  connector now splits only after a comma.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The deontic profile matched surface forms, mostly present tense, so
past and other forms were invisible on both sides of a comparison: a
rewrite "Najemca mógł wypowiedzieć" -> "Najemca musiał wypowiedzieć"
(may -> must) passed. "jest obowiązany", "obowiązku", "zobowiązanym",
"zabronione" or "zalecane" were not counted either.

With Morfeusz, one-word markers are now found by lemma and part of
speech (the predicative "wolno", not the adverb; not the gerund
"zobowiązania", a debt), negated participles count as negated, and
"należy do", "należy się" and "być może" are not modals. Phrases keep
their patterns, and the surface patterns remain the fallback without
Morfeusz. Rule output on the template corpus and the benchmark is
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"Najemca zapłaci Wynajmującemu" -> "Wynajmujący zapłaci Najemcy" kept
every number, anchor, modal and negation, so it passed. The new
party_roles_preserved check finds the parties (masculine-personal
nouns, and capitalised words inside a sentence with such a reading,
which covers "Zamawiający"), marks the ones that can be the subject (a
nominative whose number matches a finite verb, so "Najemcy" is not the
plural subject of "zapłaci"), and rejects a candidate in which one
party loses that role while another, present in both texts, gains it.
Passive/active rewrites only add or drop a subject and pass, as do
reordered clauses. No false rejection across the template and test
corpora in either mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fill is only called by check, with values. The drop and text_overrides
paths had no caller and were unsafe if one appeared: _set_text put the
new text in the first run but left the paragraph's tabs and line breaks
in place, and dropping a paragraph inside a table cell could leave the
cell without the paragraph OOXML requires. DOCX filling lives in
document-studio.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
humanize-pl-eval measures category accuracy on the shipped documents (also
with the title removed), rulings wrongly given a category, checklist blocks
on documents of their own category, template matching with paragraphs
dropped, the ratio of edits on AI text to edits on rulings, and unsafe
outputs. Gated metrics fail release-check when they move the wrong way;
ruling metrics are skipped, with a warning, without the local SAOS corpus.
Adds a GitHub Actions workflow running lint, tests, benchmark and eval.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A ruling quotes contracts, claims and powers of attorney and carries all
their vocabulary, so half of the SAOS holdout rulings were given a document
category (a loan contract for any ruling about a loan). Seven court-voice
phrases ("zważył, co następuje", "ustalił następujący stan faktyczny"...),
chosen on the SAOS train split and absent from every template and AI
document, now leave such a text unspecified. Rulings given a category drop
from 50% to 17%; template and AI document accuracy are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…son unspecified

A text whose verbs are mostly past tense (over 60%) and which never speaks
in the first person present ("wnoszę", "wzywam") narrates events instead of
performing an act. Rulings run at a median of 66% past-tense verbs; no
shipped template or AI document goes above 50%, and filings that narrate
their facts keep their category through their first-person petitum. Uses
Morfeusz2 and is skipped without it, including in the standalone copy that
document-studio bundles. Rulings given a category drop from 17% to 5%; all
template and AI document metrics are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The categories added on 28.09 gated on topic stems ("pożyczk", "remont",
"zamian", "pośrednictw", "pełnomocnictwa", "popełnienia przestępstwa"), so a
single mention decided the category: any ruling about a loan was a loan
contract. Contracts now require a formula of conclusion or their title in
the nominative ("umowa pożyczki"; rulings write "umowę pożyczki"); the
stems stay as ordinary signals.

Rulings given a category: holdout 5.3% -> 0.7%, train 79 -> 39 of 1804.
Templates 73 -> 74 of 107. Accepted trade-off: templates with their title
removed 50 -> 45 (3 now unspecified, 2 in another category), since a body
without its title or a formula of conclusion no longer names its kind; the
nearest-template classifier is meant to win these back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
drop_repetitive_transition removed every sentence-initial "Ponadto", "Co
więcej" or "Dodatkowo", including the only one in a text, where it adds an
argument or a cumulative condition ("Dodatkowo powinni udowodnić, że...").
The rule now sees the paragraph's earlier sentences and drops an opener
only when one of them already opened the same way, which is the overuse it
is named for. On court rulings it fell from 0.43 to 0.04 edits per 1000
words; on AI documents it did not fire before either.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An audit of the edits made on 400 SAOS rulings found:

- "co do zasady" -> "zasadniczo" turned a term of art ("uznał roszczenie co
  do zasady": the claim's basis, not its amount) into "mostly"; removed.
  "w odniesieniu do" -> "w przypadku" changed the meaning; now "co do".
- Passive to impersonal: under negation the object needs the genitive ("nie
  wykonano prac", not "prace"); a modifier after the subject ("umowa,
  nazwana ...") stayed nominative; "powód został skierowany" became "powód
  skierowano" because "powód" as a reason reads the same in the accusative.
  All three now keep the passive; the accusative check holds in every
  gender the word can have.
- Sentence splits inside a subordinate clause moved a party's reason into
  the writer's voice ("podnosząc, że A. Wynika to z tego, że B") or cut a
  condition from its consequence ("Skoro A. Ponadto B, to C"). A split now
  needs a left half with no complementizer or relative pronoun (Morfeusz).
- "w celu" + gerund left a transitive verb without its object ("aby
  przywłaszczyć na szkodę K.") and broke coordinated purposes ("korzyści i,
  aby uzyskać"). A verb with a passive participle is taken as transitive.

Substantive edits on rulings: 2.71 -> 2.13 per 1000 words; AI documents
30.3 -> 28.9 (the "co do zasady" swaps); no unsafe outputs in either mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A document sharing at least half of its word pairs with a shipped template
takes that template's category whatever its vocabulary suggests; one that
no signal recognises takes the category of the closest template when they
share at least a quarter. Court rulings stay under 0.08 and freely written
AI drafts under 0.2, so neither is affected. The ranking is shared with
match_template through blueprint._ranked and exposed as nearest_template,
with leave_out so a template's own text can be placed as a new document.

The eval now classifies each template with its own entry left out, so the
numbers say how unseen documents fare: templates 74 -> 80 of 107, family
95 -> 99, untitled templates 45 -> 67; AI documents 15/15 and rulings given
a category (0.7%) unchanged. Skipped in the standalone categories module
that document-studio bundles, which has no templates to search.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dence

A winner within 2 points of a runner-up that is itself a finding (at least
MIN_SCORE) was right a third of the time on the shipped templates. Such a
document is now left unspecified, with "niepewne: A albo B" as evidence,
since a wrong checklist costs more than none. A runner-up below MIN_SCORE is
incidental vocabulary and does not hold the winner back.

Confidence was a formula that said 0.98 for guesses right 77% of the time.
It is now the measured, smoothed share of right guesses for the way the
category was decided: 0.92 for signals scoring 9 or more (35/37), 0.63 for
weaker ones (55/87), 0.98 for a template sharing half the word pairs
(52/52), 0.81 for one sharing a quarter to a half (16/19).

The eval gains gated wrong-category rates and counts a document's family
only when a category was named. Wrong categories on templates 24% -> 14%
(untitled 26% -> 21%), at the cost of right ones 74.8% -> 73.8% (untitled
62.6% -> 60.7%); AI documents 15/15 and rulings unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
For each section the checklist finds in a template, the lines from its
match up to the next found section are removed and the template checked
again. Only 42% of removals are noticed: generic phrases ("dnia" in "ustawy
z dnia", "zawarta", "przedmiot", " r.") keep the section "present". Rules
on where a phrase sits (line start, short lines) or on section order lose
true sections as fast as they drop false hits, so the fix belongs in the
blueprints' phrases; this metric gates that work. It is approximate: a
section is tied to the first line any of its phrases matches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
empios and others added 29 commits November 17, 2026 14:58
The style score barely tells today's AI drafts from human templates
(AUC 0.56) and its threshold catches almost none of them, yet it opened
every report. The PDF headline, the flow CLI and the web UI now lead with
what holds whoever wrote the text: whether each item kept its numbers,
dates, amounts, references and names, then findings before and after,
automatic edits and items to review. The score follows, marked as
indicative; the PDF moves its scale bar to the section that explains it.
The batch summary counts content_kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"Pentan-1-ol (C5H11OH) to organiczny związek chemiczny" and "Umowa to
dokument" are full sentences, but the finite-verb check saw no predicate
and refused them: 208 of 1 500 human paragraphs failed on sentences like
these. The copula "to" now counts when it is not the sentence's first
word, does not follow a conjunction, preposition or pronoun, and a noun or
adjective comes right after; "wszystko to w ramach umowy" stays a
fragment. Rule edits over 7475 blueprint, template and sample texts are
unchanged in standard and strong mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On the general route a verbless sentence ("Cena adekwatna do
świadczonych usług."), a sentence split after "oraz" and a paragraph
without contract terms are ordinary writing, but the finite-verb,
sentence-split and legal-anchor checks refused them. Across 1573 pairs of
an AI draft and the human original, 721 now pass instead of 479, with the
same refusals for values, modality and negation. The hosted model's
proposals for general text are validated under GENERAL_TEXT_RULE, which
skips those three checks and does not report them as passed; every fact
check and NLI still apply, and the legal families are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The hosted model's fragments are validated on several threads, and the
general route loads the NLI check by default. Two concurrent calls into
the shared pipeline on the GPU crashed the process in Metal ("A command
encoder is already encoding to this command buffer") during an
evaluation at concurrency 2. Inference now holds a module-level lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
General text asks for a rewrite, and a proposal that repeats its source
passes every check while doing nothing. On the general route it is now
sent back once with "Ta propozycja niczego nie zmienia…", like a failed
check; the legal families still take an unchanged answer as the model's
verdict. On 24 emails a fine-tuned editor went from 38 to 44 of 86
paragraphs accepted; most retried answers changed, but many came back as
invalid JSON, a model-side weakness.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HUMANIZE_PL_LLM_MAX_TOKENS sends max_tokens with every request. mlx_lm's
server otherwise stops at 512 tokens, and an answer echoes its fragment
before rewriting it: the longest paragraph of 24 test emails took 511, so
a longer one would be cut mid-JSON. Unset, nothing is sent and the
server's default applies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A fragment spanning several lines came back with real line breaks inside
the JSON strings instead of \n escapes, which strict JSON refuses: 14 of
29 unreadable answers from a fine-tuned editor on 24 emails. The reply is
now parsed with strict=False. Parsing only: the echoed source, the
fragment id and every check still decide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The NLI model reads a pair of up to 512 tokens, and a whole paragraph with
its rewrite can run past that: the end went unread. On 20 long rewrites
(518-713 tokens, joined from accepted general-route edits) a sentence
invented at the end was caught in 4. A pair that does not fit is now
checked in parts: the premise cut into the fewest runs of sentences that
fit, the hypothesis cut where its words best follow each run, as rewrites
merge and split sentences. Every part must hold. Invented sentences caught:
19 of 20 at the end, 18 in the middle; good rewrites accepted 17 of 20
instead of 19. Pairs that fit are checked as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The echoed source only proves the model answered this fragment; the
proposal is checked against the true source whatever the echo says. Of
14 echoes the 9B model got wrong on 49 test documents, 11 dropped a
comma, "fixed" a typo or added a space, and the proposal was discarded
before any check ran. An echo now counts when every placeholder is intact
and the text is at least 95% alike; a garbled placeholder still fails.
On the 49 documents: echo failures 10 -> 4, accepted 178 -> 182 of 282,
documents keeping every fact unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A model rewrite could drop diacritics or misspell a verb and pass every
check: the humanizer wrote "prosze", "dotyczace", and the 9B model
"objmie", "wznowiamy", "uiszczyłem". Morfeusz now has to know every word
a candidate adds; the source's own words pass, inflected too, as do
acronyms, dotless abbreviations and capitalised names mid-sentence.

The repair names the word; told only to write correct Polish, the 9B
model repeated it. Measured on MTPLX, 49 texts: the gate fired on 6
paragraphs, all real non-words, and 4 of them had been accepted before;
naming the word fixed 3 repairs. Rule edits on the eval corpora are
unchanged (28.88 / 2.13 / 2.03 per 1000 words).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The general route was measured only on emails Claude wrote. Two open
sources of people's own writing, kept local like the SAOS corpus:
messages Polish Wikipedia users wrote to each other (opening message of
each talk-page section, form letters and markup dropped) and the KLEJ
Allegro reviews, both CC BY-SA 4.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Measured on people's own writing (155 Wikipedia talk messages, 40 Allegro
reviews), three checks refused good rewrites:

- Punctuation balance counted the ")" of ";)" as a bracket, and refused a
  rewrite that closed what its source left open: 30 rejections, 2 of them
  real. Emoticons are no longer counted, and only an imbalance the
  candidate adds fails.
- The spelling gate missed source words in another form: "wikipedysta",
  "wikipedystów"; "Yanosiku", "Yanosik". Words may now part at the last
  letter of the source word, but not by a letter that lost its mark.
- NLI read a long, number-dense paragraph as "neutral" even against
  itself (entailment 0.09). Only the span that changed is judged now;
  a sentence only added or dropped is still judged against the whole.

On MTPLX: real texts 99 -> 123 of 262 paragraphs accepted, all 195 texts
keeping their facts; the 49 test texts 178 -> 182 of 282, 48 of 49
keeping their facts as before. Rule edits on the eval corpora unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Polish editor in humanize-pl-trainer learns from people's messages;
its training set must not contain the 155 messages the general route is
tested on. --pages-per-letter widens the fetch, --exclude skips the
mailboxes of an earlier output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The 6000-message talk fetch and the Allegro train split both stopped on
HTTP 429. Talk pages now come 20 to a request, with a user agent that
names the project as Wikimedia asks; the rows API calls retry with the
wait the server gives. The default talk fetch still returns the same
155 held-out messages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A slot of type `content` (position, duties, subject of services, aims)
may be drafted from the request's subject; every other type takes only
facts the user gave. 50 slots in 20 blueprints and templates are marked
by hand; lists with ready items keep their extra blanks as `text`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Burstiness runs from -1 to 1 and court reasoning has a negative median
(-0.113 on the 1 804-document SAOS profile). _exceedance_low returns 0
whenever the median is not positive, so the signal scored 0 for every
document while its weight 1.0 still entered the denominator and lowered
every calibrated score by 1/20. The shipped default profile carries no
burstiness baseline and is unaffected; profiles built with the current
tooling were.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The manuscript reports results computed at 65a8ec7 against a profile
built from docs_tests/corpus/saos_train.jsonl (1 804 judgments,
5 496 973 words). That corpus is not in git, so the profile itself was
the missing piece for reproducing the numbers. It holds distribution
statistics only, no text. It is loaded by name; DEFAULT_PROFILE is
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`humanize_pl.replies.analyze` reads any letter by its form: the act from its
title and ruling words, the sender from its head, the procedure from cited
codes or the sender. The catalogue in `data/replies.yaml` maps them to
replies with a goal, template category, term and legal basis per procedure.

A remedy named in the letter's instruction leads, with its term, addressee
and forwarding body; a term that differs from the statute is reported, not
replaced. Sensitive replies carry warnings (e.g. czynny żal, art. 16 § 5
k.k.s.), and facts a reply must quote are returned verbatim. A letter nothing
recognises gets only the general reply and a request to restore a term.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With a delivery date every term counted from delivery or receipt gets its
last day: the delivery day is not counted, week and month terms end on the
same weekday or date (or the month's last day), and an end on a Saturday or
a statutory holiday moves to the next working day under the procedure's own
rule (holiday_rule in the catalogue). When a term has passed, the request to
restore it leads the list.

The analysis also returns sender_name, the head line in which the sender
names itself, so a reply goes back to that office; a court's division is
named together with the court on the line above it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The most common replies to an official or court letter now have their own
forms. General: appeal against a decision (the ZUS appeal moves to a
specific template), a letter to an office or court, interlocutory appeal
(zażalenie), appeal (apelacja), complaint to the administrative court,
answer to a claim, and a request in pending proceedings. Specific:
objection to a payment order and to a default judgment, requests to restore
or extend a term and for written reasons of a judgment, complaint about a
bailiff's action, and appeal against a notice of termination.

General forms name no particular court or office, and their fields avoid
wording that would make the model inflect a name ("Postanowienie wydał …"
rather than "na postanowienie … z dnia"). Category signals take the new
openings, so each form is classified to its own category.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A candidate's addressee and via are now only the names the letter's
instruction gives. Where it gives none, the catalogue describes the body:
filed_via for a remedy filed through whoever ruled (now also the
interlocutory appeal and the appeal against a judgment, art. 395 § 1 and
369 § 1 k.p.c., art. 428 § 1 k.p.k., art. 144 w zw. z art. 129 § 1 k.p.a.),
and the new filed_with for a reply that goes to someone other than the
sender: a complaint about a bailiff to the district court, an appeal against
a notice of termination to the labour court, and a request to set aside a
fine to the court of the district where it was imposed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A new category, odpowiedź na wezwanie do zapłaty, with its checklist and a
general form: the demand it answers, what the debtor does not acknowledge and
why, what they ask for, and the evidence. The form never acknowledges the
debt, since acknowledgement interrupts limitation (art. 123 § 1 pkt 2 k.c.).
Its own openings outweigh the demand's wording it quotes, so a demand and a
reply to it are told apart. The reply catalogue points the reply here instead
of the lawyer-to-client letter category, which has no form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ith the closing

"Z poważaniem" closes a letter; below it there is only a handwritten
signature. As a phrase in `matches` it was taken for a heading that titles
the signature section, which then needed four words under it, so the
request to set aside a fine, and any real letter ending "Z poważaniem / Jan
Kowalski", was blocked as having an empty section. Seven blueprints now find
it with a pattern, which only shows the section is there.

The procedural-request category gains the openings of the requests to
change a hearing date and to set aside a fine, which no signal recognised,
and "na podstawie art." becomes a weak signal for official letters: nearly
every filing cites a provision, so it pulled other categories' requests in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Category accuracy on templates rises to 0.869 (0.746 without titles), false
checklist blocks fall to 0.016, the gapped-text match rises to 0.934 and the
checklist notices 0.66 of removed sections. Wrong categories for drafts of
different models fall to 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An editor's note whose bracket is never closed ("(dalej należy opisać powód
…") was read as body text, so a filled document printed it. It is now a
hint for the paragraph above, and a note left open on a colon ("…, np.:")
takes the list of examples under it, which would otherwise read as grounds
the writer claims. The complaint (reklamacja) blueprint and the request to
change a hearing date are rewritten with those notes as hints.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… marks

A remedy the instruction names only to deny it ("decyzja jest ostateczna",
"nie przysługuje odwołanie") is no longer offered: the catalogue's new
ruled_out phrases cover the appeal (art. 16 § 1 k.p.a., art. 128 o.p.) and
the interlocutory appeal. The request to restore a term leads only when a
term the instruction gives has passed, if it gives any, so a final SKO
decision now leads with the complaint to the administrative court.

A file mark after its label may have a short prefix apart from the number
("Sygn. akt KM 1207/26"), and marks the letter labels come before court
references it only cites, so a bailiff's notice no longer takes the
enforced payment order's reference for its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Local main is the source of truth. origin/main's 68 commits (PR #3:
drafting of missing sections, rhythm, nli.py, unified flow/CLI, UI
privacy controls) stay in history but none of their changes are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CI installs dev, morfeusz, xlsx and pdf only. Stanza-backed tests and
the UI label test now skip without their extras, as test_ui.py does.
Typer forces ANSI styling on GitHub Actions, so --help checks compare
plain text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replacing a street address with a blank in the snow-clearing template
changed the human side of detector_auc_drafts from 0.5752 to 0.5748.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@empios
empios merged commit e9392ee into main Nov 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant