Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/corpus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Corpus run

# Sends every corpus case to the model and grades the answers.
# One full run costs about 8 USD in API credits, so it runs only by hand:
# Actions > Corpus run > Run workflow. Run it before a release that changes
# SKILL.md, references/ or prompts/.
on:
workflow_dispatch:
inputs:
variant:
description: "skill (SKILL.md) or prompt (prompts/system-prompt.md)"
type: choice
options: [skill, prompt]
default: skill
runs:
description: "Answers per case"
default: "3"
cases:
description: "Only these cases, comma-separated (empty: all)"
default: ""

permissions:
contents: read

concurrency:
group: corpus-${{ github.ref }}
cancel-in-progress: true

jobs:
corpus:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: "3.12"
- name: Install uv
run: python3 -m pip install --quiet uv==0.11.32
- name: Run the corpus
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
VARIANT: ${{ inputs.variant || 'skill' }}
RUNS: ${{ inputs.runs || '3' }}
CASES: ${{ inputs.cases }}
run: >-
uv run --no-project --with anthropic==2.3.0 python tests/run_corpus.py
--variant "$VARIANT" --runs "$RUNS" --case "$CASES"
--print-failed
- name: Keep the answers
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: corpus-results
path: corpus-results/
if-no-files-found: ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ __pycache__/
*.zip
*.skill
humanizer21-prompt.md
corpus-results/
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ humanizer21 is an agent skill written in Markdown, with one Python checker and a
- **Facts.** Examples in the references must never add a fact in the "after" text that the "before" text lacks.
- **Checker.** Every new check in `barla.py` gets a test in `tests/test_barla.py`, including a test that correct text stays clean.
- **Corpus.** When a rewrite goes wrong in a way the rules should have prevented, add the text to `tests/corpus/` as a new case with `input.txt`, `expected.json` and a corrected `reference.txt`. Run `python3 tests/grade.py` on the skill's next answer before releasing a fix.
- **Model run.** `tests/run_corpus.py` sends every corpus case to the model and grades the answers with `grade.py`; run it by hand in GitHub Actions (`Corpus run` > Run workflow); one full run costs about 8 USD. Run it before and after a change to `SKILL.md`, `references/` or `prompts/`, and do not merge a change that makes a case fail that passed before. Locally: `uv run --no-project --with anthropic==2.3.0 python tests/run_corpus.py --runs 1`.
- **History.** Add a `CHANGELOG.md` note for any change in behavior.

## Checks before publishing
Expand Down
2 changes: 1 addition & 1 deletion tests/corpus/hasabat-yazgysy/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"täze sahypa",
"Umyt edýärin",
"Başga soraglaryňyz",
"için",
"re:\\bi[cç]in\\b",
"daha",
"abilir",
"YouTube'da",
Expand Down
2 changes: 1 addition & 1 deletion tests/corpus/kitaphana-habary/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"must_not": [
"Elbetde",
"için",
"re:\\bi[cç]in\\b",
"Şuny bellemek",
"rol oýna",
"täze sahypa",
Expand Down
2 changes: 1 addition & 1 deletion tests/corpus/olimpiada-habary/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"çäklerinde",
"öz içine",
"rol oýna",
"için",
"re:\\bi[cç]in\\b",
"daha",
"önemli",
"yeňijilere",
Expand Down
2 changes: 1 addition & 1 deletion tests/corpus/sanly-mekdep-makala/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"Platforma barada gürrüň",
"Elimdäki",
"million",
"için",
"re:\\bi[cç]in\\b",
"daha",
"sadece",
"olarak",
Expand Down
2 changes: 1 addition & 1 deletion tests/corpus/uly-hasabat/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"must_not": [
"Elbetde",
"Umyt edýärin",
"için",
"re:\\bi[cç]in\\b",
"daha",
"ösebilir",
"Türkmenistanyn",
Expand Down
2 changes: 1 addition & 1 deletion tests/corpus/welosiped-post/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"Elbetde",
"Geliň",
"**",
"için",
"re:\\bi[cç]in\\b",
"peydaly",
"2026-nji",
"velosipedler",
Expand Down
2 changes: 1 addition & 1 deletion tests/corpus/yoremek-post/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Gowy sorag",
"Geliň",
"**",
"için",
"re:\\bi[cç]in\\b",
"daha",
"durum",
"Hakykatdan",
Expand Down
34 changes: 31 additions & 3 deletions tests/grade.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,53 @@
python3 tests/grade.py tests/corpus/olimpiada-habary result.txt

Prints one line per check and exits with code 1 if any check fails.
The checks are plain substring tests from the case's expected.json:
The checks are substring tests from the case's expected.json:
must_keep lists facts and protected text that have to survive the edit,
must_not lists tells, errors and invented details that must be gone.

Two allowances keep the checks from failing correct Turkmen:
- in must_keep, a count from 2 to 9 may be written in digits or in words,
with or without `sany` (`3 sany täze seýilgäh`, `üç täze seýilgäh`);
- an entry that starts with `re:` is a regular expression, for a word that
must not match inside a longer one (`re:\\bi[cç]in\\b` is the Turkish
`için`, not the Turkmen `içinde`).
"""

import json
import re
import os
import sys

HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(HERE, "..", "scripts"))
import barla # noqa: E402

UNITS = {"2": "iki", "3": "üç", "4": "dört", "5": "bäş", "6": "alty", "7": "ýedi", "8": "sekiz", "9": "dokuz"}
WORDS = {w: d for d, w in UNITS.items()}
COUNT = re.compile(r"^(\d|%s)( sany)? (.+)$" % "|".join(UNITS.values()))


def variants(entry):
"""Equally correct spellings of a must_keep entry: 3 / üç, with or without sany."""
m = COUNT.match(entry)
if not m or (m.group(1).isdigit() and m.group(1) not in UNITS):
return [entry]
n, rest = m.group(1), m.group(3)
forms = {n, UNITS.get(n, WORDS.get(n))}
return sorted("%s%s %s" % (f, s, rest) for f in forms for s in ("", " sany"))


def found(entry, text):
if entry.startswith("re:"):
return re.search(entry[3:], text) is not None
return any(v in text for v in variants(entry))


def grade(case_dir, text):
with open(os.path.join(case_dir, "expected.json"), encoding="utf-8") as fh:
exp = json.load(fh)
results = [("keeps %r" % k, k in text) for k in exp["must_keep"]]
results += [("has no %r" % k, k not in text) for k in exp["must_not"]]
results = [("keeps %r" % k, found(k, text)) for k in exp["must_keep"]]
results += [("has no %r" % k, not found(k, text)) for k in exp["must_not"]]
# Quotes and table rows of a Turkmen source must survive unchanged.
if exp.get("source_language", "tk") == "tk":
with open(os.path.join(case_dir, "input.txt"), encoding="utf-8") as fh:
Expand Down
Loading
Loading