Add hardened swedish-proofreading subset: 84 train, 24 eval, language sv
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/environment/Dockerfile +3 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/environment/workdir/documents.json +26 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/environment/workdir/lexicon.json +54 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/environment/workdir/style.md +6 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/instruction.md +5 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/solution/oracle.py +22 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/solution/solve.sh +4 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/task.toml +26 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/tests/checks.json +164 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/tests/test.sh +3 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/tests/validators.py +38 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/tests/verify.py +116 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/environment/Dockerfile +3 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/environment/workdir/documents.json +26 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/environment/workdir/lexicon.json +54 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/environment/workdir/style.md +6 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/instruction.md +5 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/solution/oracle.py +22 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/solution/solve.sh +4 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/task.toml +26 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/tests/checks.json +164 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/tests/test.sh +3 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/tests/validators.py +38 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/tests/verify.py +116 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/environment/Dockerfile +3 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/environment/workdir/documents.json +26 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/environment/workdir/lexicon.json +54 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/environment/workdir/style.md +6 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/instruction.md +5 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/solution/oracle.py +22 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/solution/solve.sh +4 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/task.toml +26 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/tests/checks.json +164 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/tests/test.sh +3 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/tests/validators.py +38 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/tests/verify.py +116 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/environment/Dockerfile +3 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/environment/workdir/documents.json +26 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/environment/workdir/lexicon.json +54 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/environment/workdir/style.md +6 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/instruction.md +5 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/solution/oracle.py +22 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/solution/solve.sh +4 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/task.toml +26 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/tests/checks.json +164 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/tests/test.sh +3 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/tests/validators.py +38 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/tests/verify.py +116 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0024/environment/Dockerfile +3 -0
- tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0024/environment/workdir/documents.json +26 -0
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY workdir/ /app/
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/environment/workdir/documents.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"id": "D1",
|
| 4 |
+
"text": "Här finns ett tydligt broschyr. Vidar behöver inte betala 32 kronor i dag."
|
| 5 |
+
},
|
| 6 |
+
{
|
| 7 |
+
"id": "D2",
|
| 8 |
+
"text": "Här finns ett tydligt skylt. Malte behöver inte betala 69 kronor i dag."
|
| 9 |
+
},
|
| 10 |
+
{
|
| 11 |
+
"id": "D3",
|
| 12 |
+
"text": "Här finns ett tydligt broschyr. Malte behöver inte betala 41 kronor i dag."
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"id": "D4",
|
| 16 |
+
"text": "Här finns ett tydligt plan. Hedda behöver inte betala 45 kronor i dag."
|
| 17 |
+
},
|
| 18 |
+
{
|
| 19 |
+
"id": "D5",
|
| 20 |
+
"text": "Här finns ett tydligt skylt. Siri behöver inte betala 76 kronor i dag."
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"id": "D6",
|
| 24 |
+
"text": "Här finns en tydlig avtal. Hedda behöver inte betala 87 kronor i dag."
|
| 25 |
+
}
|
| 26 |
+
]
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/environment/workdir/lexicon.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"compounds": [
|
| 3 |
+
{
|
| 4 |
+
"correct": "bokningsbekräftelsen",
|
| 5 |
+
"split": "boknings bekräftelsen"
|
| 6 |
+
},
|
| 7 |
+
{
|
| 8 |
+
"correct": "bibliotekskatalogen",
|
| 9 |
+
"split": "biblioteks katalogen"
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"correct": "kundtjänsten",
|
| 13 |
+
"split": "kund tjänsten"
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"correct": "mötesrummet",
|
| 17 |
+
"split": "mötes rummet"
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"correct": "ansökningstiden",
|
| 21 |
+
"split": "ansöknings tiden"
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"correct": "leveransdatumet",
|
| 25 |
+
"split": "leverans datumet"
|
| 26 |
+
}
|
| 27 |
+
],
|
| 28 |
+
"nouns": [
|
| 29 |
+
{
|
| 30 |
+
"word": "schema",
|
| 31 |
+
"gender": "ett"
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"word": "avtal",
|
| 35 |
+
"gender": "ett"
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"word": "förslag",
|
| 39 |
+
"gender": "ett"
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"word": "skylt",
|
| 43 |
+
"gender": "en"
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"word": "broschyr",
|
| 47 |
+
"gender": "en"
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"word": "plan",
|
| 51 |
+
"gender": "en"
|
| 52 |
+
}
|
| 53 |
+
]
|
| 54 |
+
}
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/environment/workdir/style.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Redaktionell instruktion
|
| 2 |
+
Rätta bara språkfel. Behåll varje faktauppgift, namn, tal, negation och redan korrekt mening.
|
| 3 |
+
Sammansatta substantiv skrivs ihop. Skriv däremot "i dag" i två ord.
|
| 4 |
+
Använd en/ett och tydlig/tydligt efter substantivets genus i ordlistan.
|
| 5 |
+
De är subjekt; dem är objekt. Efter inledningen "I dag" kommer det finita verbet före subjektet.
|
| 6 |
+
Lägg inte till förklaringar eller alternativa svar. Ordlistan är en språkresurs, inte ett facit till dokumenten.
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/instruction.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Korrekturläsning på svenska
|
| 2 |
+
|
| 3 |
+
Rätta dokumenten i `documents.json` enligt `style.md`. `lexicon.json` anger sammansättningar och genus. Rätta alla och endast de inplanterade språkfelen. Behåll dokumentens uppgifter och meningar som redan är korrekta.
|
| 4 |
+
|
| 5 |
+
Skriv `answer.json` med exakt nyckeln `documents`: ett objekt där varje dokument-id är nyckel och värdet är hela den rättade texten. Alla sex dokument måste finnas med. Normala blankstegsvariationer godtas, men ord, tecken, versaler och fakta bedöms. Varje rättad felplats ger delpoäng endast om resten av dokumentet är oförändrat. Extra påståenden, ändrad negation, ändrade tal eller överrättning ger noll för dokumentet. Oförändrad felaktig text ger ingen poäng.
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/solution/oracle.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Independent rule-based proofreader, operating only on supplied files."""
|
| 2 |
+
import json,re
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
def solve():
|
| 6 |
+
lex=json.loads(Path('lexicon.json').read_text());result={}
|
| 7 |
+
nouns={n['word']:n['gender'] for n in lex['nouns']}
|
| 8 |
+
def agreement(m):
|
| 9 |
+
gender=nouns.get(m.group(3))
|
| 10 |
+
if not gender:return m.group(0)
|
| 11 |
+
return gender+' '+('tydligt' if gender=='ett' else 'tydlig')+' '+m.group(3)
|
| 12 |
+
for doc in json.loads(Path('documents.json').read_text()):
|
| 13 |
+
text=doc['text']
|
| 14 |
+
for pair in lex['compounds']:text=re.sub(r'\b'+re.escape(pair['split'])+r'\b',pair['correct'],text)
|
| 15 |
+
text=re.sub(r'\b(en|ett) (tydlig|tydligt) (\w+)\b',agreement,text)
|
| 16 |
+
text=text.replace('I dag de granskar','I dag granskar de')
|
| 17 |
+
text=re.sub(r'\bDem visar\b','De visar',text)
|
| 18 |
+
text=re.sub(r'\bhjälper de efter\b','hjälper dem efter',text)
|
| 19 |
+
result[doc['id']]=text
|
| 20 |
+
return {'documents':result}
|
| 21 |
+
|
| 22 |
+
if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve(),ensure_ascii=False))
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
cd /app
|
| 4 |
+
python3 /solution/oracle.py
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/task.toml
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[metadata]
|
| 4 |
+
author_name = "Renaissance Labs"
|
| 5 |
+
author_email = "unknown"
|
| 6 |
+
difficulty = "easy"
|
| 7 |
+
category = "swedish-proofreading"
|
| 8 |
+
tags = ["swedish-proofreading", "agreement", "isced-0232", "eval", "language-sv"]
|
| 9 |
+
isced_f = "0232"
|
| 10 |
+
family = "agreement"
|
| 11 |
+
split = "eval"
|
| 12 |
+
seed = 10000
|
| 13 |
+
languages = ["sv"]
|
| 14 |
+
|
| 15 |
+
[verifier]
|
| 16 |
+
timeout_sec = 120.0
|
| 17 |
+
|
| 18 |
+
[agent]
|
| 19 |
+
timeout_sec = 900.0
|
| 20 |
+
|
| 21 |
+
[environment]
|
| 22 |
+
build_timeout_sec = 600.0
|
| 23 |
+
cpus = 1
|
| 24 |
+
memory_mb = 1024
|
| 25 |
+
storage_mb = 2048
|
| 26 |
+
allow_internet = false
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/tests/checks.json
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"type": "custom",
|
| 4 |
+
"name": "edit_quality",
|
| 5 |
+
"args": {
|
| 6 |
+
"id": "D1",
|
| 7 |
+
"ids": [
|
| 8 |
+
"D1",
|
| 9 |
+
"D2",
|
| 10 |
+
"D3",
|
| 11 |
+
"D4",
|
| 12 |
+
"D5",
|
| 13 |
+
"D6"
|
| 14 |
+
],
|
| 15 |
+
"segments": [
|
| 16 |
+
"H\u00e4r finns ",
|
| 17 |
+
{
|
| 18 |
+
"bad": "ett tydligt",
|
| 19 |
+
"good": [
|
| 20 |
+
"en tydlig"
|
| 21 |
+
]
|
| 22 |
+
},
|
| 23 |
+
" broschyr.",
|
| 24 |
+
" Vidar beh\u00f6ver inte betala 32 kronor i dag."
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
"weight": 1.0
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"type": "custom",
|
| 31 |
+
"name": "edit_quality",
|
| 32 |
+
"args": {
|
| 33 |
+
"id": "D2",
|
| 34 |
+
"ids": [
|
| 35 |
+
"D1",
|
| 36 |
+
"D2",
|
| 37 |
+
"D3",
|
| 38 |
+
"D4",
|
| 39 |
+
"D5",
|
| 40 |
+
"D6"
|
| 41 |
+
],
|
| 42 |
+
"segments": [
|
| 43 |
+
"H\u00e4r finns ",
|
| 44 |
+
{
|
| 45 |
+
"bad": "ett tydligt",
|
| 46 |
+
"good": [
|
| 47 |
+
"en tydlig"
|
| 48 |
+
]
|
| 49 |
+
},
|
| 50 |
+
" skylt.",
|
| 51 |
+
" Malte beh\u00f6ver inte betala 69 kronor i dag."
|
| 52 |
+
]
|
| 53 |
+
},
|
| 54 |
+
"weight": 1.0
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"type": "custom",
|
| 58 |
+
"name": "edit_quality",
|
| 59 |
+
"args": {
|
| 60 |
+
"id": "D3",
|
| 61 |
+
"ids": [
|
| 62 |
+
"D1",
|
| 63 |
+
"D2",
|
| 64 |
+
"D3",
|
| 65 |
+
"D4",
|
| 66 |
+
"D5",
|
| 67 |
+
"D6"
|
| 68 |
+
],
|
| 69 |
+
"segments": [
|
| 70 |
+
"H\u00e4r finns ",
|
| 71 |
+
{
|
| 72 |
+
"bad": "ett tydligt",
|
| 73 |
+
"good": [
|
| 74 |
+
"en tydlig"
|
| 75 |
+
]
|
| 76 |
+
},
|
| 77 |
+
" broschyr.",
|
| 78 |
+
" Malte beh\u00f6ver inte betala 41 kronor i dag."
|
| 79 |
+
]
|
| 80 |
+
},
|
| 81 |
+
"weight": 1.0
|
| 82 |
+
},
|
| 83 |
+
{
|
| 84 |
+
"type": "custom",
|
| 85 |
+
"name": "edit_quality",
|
| 86 |
+
"args": {
|
| 87 |
+
"id": "D4",
|
| 88 |
+
"ids": [
|
| 89 |
+
"D1",
|
| 90 |
+
"D2",
|
| 91 |
+
"D3",
|
| 92 |
+
"D4",
|
| 93 |
+
"D5",
|
| 94 |
+
"D6"
|
| 95 |
+
],
|
| 96 |
+
"segments": [
|
| 97 |
+
"H\u00e4r finns ",
|
| 98 |
+
{
|
| 99 |
+
"bad": "ett tydligt",
|
| 100 |
+
"good": [
|
| 101 |
+
"en tydlig"
|
| 102 |
+
]
|
| 103 |
+
},
|
| 104 |
+
" plan.",
|
| 105 |
+
" Hedda beh\u00f6ver inte betala 45 kronor i dag."
|
| 106 |
+
]
|
| 107 |
+
},
|
| 108 |
+
"weight": 1.0
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"type": "custom",
|
| 112 |
+
"name": "edit_quality",
|
| 113 |
+
"args": {
|
| 114 |
+
"id": "D5",
|
| 115 |
+
"ids": [
|
| 116 |
+
"D1",
|
| 117 |
+
"D2",
|
| 118 |
+
"D3",
|
| 119 |
+
"D4",
|
| 120 |
+
"D5",
|
| 121 |
+
"D6"
|
| 122 |
+
],
|
| 123 |
+
"segments": [
|
| 124 |
+
"H\u00e4r finns ",
|
| 125 |
+
{
|
| 126 |
+
"bad": "ett tydligt",
|
| 127 |
+
"good": [
|
| 128 |
+
"en tydlig"
|
| 129 |
+
]
|
| 130 |
+
},
|
| 131 |
+
" skylt.",
|
| 132 |
+
" Siri beh\u00f6ver inte betala 76 kronor i dag."
|
| 133 |
+
]
|
| 134 |
+
},
|
| 135 |
+
"weight": 1.0
|
| 136 |
+
},
|
| 137 |
+
{
|
| 138 |
+
"type": "custom",
|
| 139 |
+
"name": "edit_quality",
|
| 140 |
+
"args": {
|
| 141 |
+
"id": "D6",
|
| 142 |
+
"ids": [
|
| 143 |
+
"D1",
|
| 144 |
+
"D2",
|
| 145 |
+
"D3",
|
| 146 |
+
"D4",
|
| 147 |
+
"D5",
|
| 148 |
+
"D6"
|
| 149 |
+
],
|
| 150 |
+
"segments": [
|
| 151 |
+
"H\u00e4r finns ",
|
| 152 |
+
{
|
| 153 |
+
"bad": "en tydlig",
|
| 154 |
+
"good": [
|
| 155 |
+
"ett tydligt"
|
| 156 |
+
]
|
| 157 |
+
},
|
| 158 |
+
" avtal.",
|
| 159 |
+
" Hedda beh\u00f6ver inte betala 87 kronor i dag."
|
| 160 |
+
]
|
| 161 |
+
},
|
| 162 |
+
"weight": 1.0
|
| 163 |
+
}
|
| 164 |
+
]
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/tests/test.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/tests/validators.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Bounded edit lattice: preserve all literal context, accept multiple local repairs.
|
| 2 |
+
No word-count, readability or keyword reward. Unicode NFC and whitespace are normalised;
|
| 3 |
+
capitalisation, punctuation, words and all facts remain significant.
|
| 4 |
+
"""
|
| 5 |
+
import re,unicodedata
|
| 6 |
+
|
| 7 |
+
def tokens(text):
|
| 8 |
+
if not isinstance(text,str):return None
|
| 9 |
+
return tuple(re.findall(r'\w+|[^\w\s]',unicodedata.normalize('NFC',text),re.UNICODE))
|
| 10 |
+
|
| 11 |
+
def lattice(text,segments,allow_source=True):
|
| 12 |
+
got=tokens(text)
|
| 13 |
+
if got is None or len(got)>3000:return 0.0
|
| 14 |
+
# Position -> best number of corrected slots at that position. Dynamic programming
|
| 15 |
+
# avoids regex backtracking and handles alternatives with overlapping prefixes.
|
| 16 |
+
states={0:0};count=0
|
| 17 |
+
for segment in segments:
|
| 18 |
+
if isinstance(segment,str):options=[(tokens(segment),0)]
|
| 19 |
+
else:
|
| 20 |
+
count+=1;options=[(tokens(v),1) for v in segment['good']]
|
| 21 |
+
if allow_source and 'bad' in segment:options.append((tokens(segment['bad']),0))
|
| 22 |
+
nxt={}
|
| 23 |
+
for pos,score in states.items():
|
| 24 |
+
for seq,credit in options:
|
| 25 |
+
end=pos+len(seq)
|
| 26 |
+
if got[pos:end]==seq:nxt[end]=max(nxt.get(end,-1),score+credit)
|
| 27 |
+
states=nxt
|
| 28 |
+
if not states:return 0.0
|
| 29 |
+
return states.get(len(got),0)/count if count else float(len(got) in states)
|
| 30 |
+
|
| 31 |
+
def edit_quality(answer,args):
|
| 32 |
+
try:
|
| 33 |
+
if not isinstance(answer,dict) or set(answer)!={'documents'}:return 0.0
|
| 34 |
+
docs=answer['documents']
|
| 35 |
+
if not isinstance(docs,dict) or set(docs)!=set(args['ids']):return 0.0
|
| 36 |
+
if any(not isinstance(v,str) for v in docs.values()):return 0.0
|
| 37 |
+
return lattice(docs[args['id']],args['segments'])
|
| 38 |
+
except (KeyError,TypeError,ValueError,AttributeError):return 0.0
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0000/tests/verify.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Verifier for Renaissance Labs practice environments. Standard library only.
|
| 3 |
+
|
| 4 |
+
Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
|
| 5 |
+
The reward is the weighted share of checks that pass. A missing, unreadable or non-object
|
| 6 |
+
answer scores 0. Each check addresses one value in the answer by a dotted path.
|
| 7 |
+
|
| 8 |
+
Check types
|
| 9 |
+
int exact integer (a float with integral value is accepted; booleans are not)
|
| 10 |
+
number within abs_tol of value (default 1e-9); booleans and strings are rejected
|
| 11 |
+
str equal after trimming and case-folding
|
| 12 |
+
bool exact boolean
|
| 13 |
+
list ordered list; items compared as int/number/str according to "item" (default str)
|
| 14 |
+
set unordered collection of distinct strings (or ints)
|
| 15 |
+
custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
|
| 16 |
+
"""
|
| 17 |
+
import argparse, json, math, os, sys
|
| 18 |
+
|
| 19 |
+
MISSING = object()
|
| 20 |
+
|
| 21 |
+
def lookup(obj, path):
|
| 22 |
+
cur = obj
|
| 23 |
+
for part in path.split("."):
|
| 24 |
+
if isinstance(cur, dict):
|
| 25 |
+
if part not in cur: return MISSING
|
| 26 |
+
cur = cur[part]
|
| 27 |
+
elif isinstance(cur, list):
|
| 28 |
+
try: cur = cur[int(part)]
|
| 29 |
+
except (ValueError, IndexError): return MISSING
|
| 30 |
+
else:
|
| 31 |
+
return MISSING
|
| 32 |
+
return cur
|
| 33 |
+
|
| 34 |
+
def is_num(x):
|
| 35 |
+
return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
|
| 36 |
+
|
| 37 |
+
def eq_int(got, want):
|
| 38 |
+
return is_num(got) and float(got) == float(int(got)) and int(got) == want
|
| 39 |
+
|
| 40 |
+
def eq_num(got, want, tol):
|
| 41 |
+
return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
|
| 42 |
+
|
| 43 |
+
def eq_str(got, want):
|
| 44 |
+
return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
|
| 45 |
+
|
| 46 |
+
def eq_item(got, want, kind, tol):
|
| 47 |
+
if kind == "int": return eq_int(got, want)
|
| 48 |
+
if kind == "number": return eq_num(got, want, tol)
|
| 49 |
+
return eq_str(got, want)
|
| 50 |
+
|
| 51 |
+
def run_check(answer, chk, validators):
|
| 52 |
+
t = chk["type"]
|
| 53 |
+
if t == "custom":
|
| 54 |
+
fn = getattr(validators, chk["name"], None) if validators else None
|
| 55 |
+
if fn is None: return 0.0
|
| 56 |
+
try: r = fn(answer, chk.get("args", {}))
|
| 57 |
+
except Exception: return 0.0
|
| 58 |
+
if r is True: return 1.0
|
| 59 |
+
if r is False or r is None: return 0.0
|
| 60 |
+
return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
|
| 61 |
+
got = lookup(answer, chk["path"])
|
| 62 |
+
if got is MISSING: return 0.0
|
| 63 |
+
want, tol = chk["value"], chk.get("abs_tol", 1e-9)
|
| 64 |
+
if t == "int": ok = eq_int(got, want)
|
| 65 |
+
elif t == "number": ok = eq_num(got, want, tol)
|
| 66 |
+
elif t == "str": ok = eq_str(got, want)
|
| 67 |
+
elif t == "bool": ok = isinstance(got, bool) and got is want
|
| 68 |
+
elif t == "list":
|
| 69 |
+
ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
|
| 70 |
+
elif t == "set":
|
| 71 |
+
kind = chk.get("item", "str")
|
| 72 |
+
if not isinstance(got, list): ok = False
|
| 73 |
+
else:
|
| 74 |
+
norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
|
| 75 |
+
g = [norm(x) for x in got]; w = [norm(x) for x in want]
|
| 76 |
+
ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
|
| 77 |
+
else: ok = False
|
| 78 |
+
return 1.0 if ok else 0.0
|
| 79 |
+
|
| 80 |
+
def grade(answer, checks, validators=None):
|
| 81 |
+
"""Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
|
| 82 |
+
if not isinstance(answer, dict):
|
| 83 |
+
return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
|
| 84 |
+
total = sum(c.get("weight", 1.0) for c in checks)
|
| 85 |
+
got, details = 0.0, []
|
| 86 |
+
for c in checks:
|
| 87 |
+
s = run_check(answer, c, validators)
|
| 88 |
+
got += s * c.get("weight", 1.0)
|
| 89 |
+
details.append({"check": c.get("path", c.get("name")), "score": s})
|
| 90 |
+
return (round(got / total, 6) if total else 0.0), details
|
| 91 |
+
|
| 92 |
+
def main():
|
| 93 |
+
ap = argparse.ArgumentParser()
|
| 94 |
+
ap.add_argument("--answer", default="/app/answer.json")
|
| 95 |
+
ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
|
| 96 |
+
ap.add_argument("--out", default="/logs/verifier")
|
| 97 |
+
a = ap.parse_args()
|
| 98 |
+
checks = json.load(open(a.checks))
|
| 99 |
+
try:
|
| 100 |
+
with open(a.answer) as f: answer = json.load(f)
|
| 101 |
+
except Exception:
|
| 102 |
+
answer = None
|
| 103 |
+
validators = None
|
| 104 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 105 |
+
if os.path.exists(os.path.join(here, "validators.py")):
|
| 106 |
+
sys.path.insert(0, here)
|
| 107 |
+
import validators # noqa
|
| 108 |
+
reward, details = grade(answer, checks, validators)
|
| 109 |
+
os.makedirs(a.out, exist_ok=True)
|
| 110 |
+
with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
|
| 111 |
+
with open(os.path.join(a.out, "reward.json"), "w") as f:
|
| 112 |
+
json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
|
| 113 |
+
print("reward", reward)
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
main()
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY workdir/ /app/
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/environment/workdir/documents.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"id": "D1",
|
| 4 |
+
"text": "Här finns en tydlig förslag. Vidar behöver inte betala 16 kronor i dag."
|
| 5 |
+
},
|
| 6 |
+
{
|
| 7 |
+
"id": "D2",
|
| 8 |
+
"text": "Här finns en tydlig förslag. Malte behöver inte betala 49 kronor i dag."
|
| 9 |
+
},
|
| 10 |
+
{
|
| 11 |
+
"id": "D3",
|
| 12 |
+
"text": "Här finns en tydlig förslag. Siri behöver inte betala 53 kronor i dag."
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"id": "D4",
|
| 16 |
+
"text": "Här finns en tydlig förslag. Hedda behöver inte betala 77 kronor i dag."
|
| 17 |
+
},
|
| 18 |
+
{
|
| 19 |
+
"id": "D5",
|
| 20 |
+
"text": "Här finns en tydlig förslag. Vidar behöver inte betala 82 kronor i dag."
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"id": "D6",
|
| 24 |
+
"text": "Här finns en tydlig förslag. Malte behöver inte betala 57 kronor i dag."
|
| 25 |
+
}
|
| 26 |
+
]
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/environment/workdir/lexicon.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"compounds": [
|
| 3 |
+
{
|
| 4 |
+
"correct": "bokningsbekräftelsen",
|
| 5 |
+
"split": "boknings bekräftelsen"
|
| 6 |
+
},
|
| 7 |
+
{
|
| 8 |
+
"correct": "bibliotekskatalogen",
|
| 9 |
+
"split": "biblioteks katalogen"
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"correct": "kundtjänsten",
|
| 13 |
+
"split": "kund tjänsten"
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"correct": "mötesrummet",
|
| 17 |
+
"split": "mötes rummet"
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"correct": "ansökningstiden",
|
| 21 |
+
"split": "ansöknings tiden"
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"correct": "leveransdatumet",
|
| 25 |
+
"split": "leverans datumet"
|
| 26 |
+
}
|
| 27 |
+
],
|
| 28 |
+
"nouns": [
|
| 29 |
+
{
|
| 30 |
+
"word": "schema",
|
| 31 |
+
"gender": "ett"
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"word": "avtal",
|
| 35 |
+
"gender": "ett"
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"word": "förslag",
|
| 39 |
+
"gender": "ett"
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"word": "skylt",
|
| 43 |
+
"gender": "en"
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"word": "broschyr",
|
| 47 |
+
"gender": "en"
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"word": "plan",
|
| 51 |
+
"gender": "en"
|
| 52 |
+
}
|
| 53 |
+
]
|
| 54 |
+
}
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/environment/workdir/style.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Redaktionell instruktion
|
| 2 |
+
Rätta bara språkfel. Behåll varje faktauppgift, namn, tal, negation och redan korrekt mening.
|
| 3 |
+
Sammansatta substantiv skrivs ihop. Skriv däremot "i dag" i två ord.
|
| 4 |
+
Använd en/ett och tydlig/tydligt efter substantivets genus i ordlistan.
|
| 5 |
+
De är subjekt; dem är objekt. Efter inledningen "I dag" kommer det finita verbet före subjektet.
|
| 6 |
+
Lägg inte till förklaringar eller alternativa svar. Ordlistan är en språkresurs, inte ett facit till dokumenten.
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/instruction.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Korrekturläsning på svenska
|
| 2 |
+
|
| 3 |
+
Rätta dokumenten i `documents.json` enligt `style.md`. `lexicon.json` anger sammansättningar och genus. Rätta alla och endast de inplanterade språkfelen. Behåll dokumentens uppgifter och meningar som redan är korrekta.
|
| 4 |
+
|
| 5 |
+
Skriv `answer.json` med exakt nyckeln `documents`: ett objekt där varje dokument-id är nyckel och värdet är hela den rättade texten. Alla sex dokument måste finnas med. Normala blankstegsvariationer godtas, men ord, tecken, versaler och fakta bedöms. Varje rättad felplats ger delpoäng endast om resten av dokumentet är oförändrat. Extra påståenden, ändrad negation, ändrade tal eller överrättning ger noll för dokumentet. Oförändrad felaktig text ger ingen poäng.
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/solution/oracle.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Independent rule-based proofreader, operating only on supplied files."""
|
| 2 |
+
import json,re
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
def solve():
|
| 6 |
+
lex=json.loads(Path('lexicon.json').read_text());result={}
|
| 7 |
+
nouns={n['word']:n['gender'] for n in lex['nouns']}
|
| 8 |
+
def agreement(m):
|
| 9 |
+
gender=nouns.get(m.group(3))
|
| 10 |
+
if not gender:return m.group(0)
|
| 11 |
+
return gender+' '+('tydligt' if gender=='ett' else 'tydlig')+' '+m.group(3)
|
| 12 |
+
for doc in json.loads(Path('documents.json').read_text()):
|
| 13 |
+
text=doc['text']
|
| 14 |
+
for pair in lex['compounds']:text=re.sub(r'\b'+re.escape(pair['split'])+r'\b',pair['correct'],text)
|
| 15 |
+
text=re.sub(r'\b(en|ett) (tydlig|tydligt) (\w+)\b',agreement,text)
|
| 16 |
+
text=text.replace('I dag de granskar','I dag granskar de')
|
| 17 |
+
text=re.sub(r'\bDem visar\b','De visar',text)
|
| 18 |
+
text=re.sub(r'\bhjälper de efter\b','hjälper dem efter',text)
|
| 19 |
+
result[doc['id']]=text
|
| 20 |
+
return {'documents':result}
|
| 21 |
+
|
| 22 |
+
if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve(),ensure_ascii=False))
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
cd /app
|
| 4 |
+
python3 /solution/oracle.py
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/task.toml
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[metadata]
|
| 4 |
+
author_name = "Renaissance Labs"
|
| 5 |
+
author_email = "unknown"
|
| 6 |
+
difficulty = "easy"
|
| 7 |
+
category = "swedish-proofreading"
|
| 8 |
+
tags = ["swedish-proofreading", "agreement", "isced-0232", "eval", "language-sv"]
|
| 9 |
+
isced_f = "0232"
|
| 10 |
+
family = "agreement"
|
| 11 |
+
split = "eval"
|
| 12 |
+
seed = 10012
|
| 13 |
+
languages = ["sv"]
|
| 14 |
+
|
| 15 |
+
[verifier]
|
| 16 |
+
timeout_sec = 120.0
|
| 17 |
+
|
| 18 |
+
[agent]
|
| 19 |
+
timeout_sec = 900.0
|
| 20 |
+
|
| 21 |
+
[environment]
|
| 22 |
+
build_timeout_sec = 600.0
|
| 23 |
+
cpus = 1
|
| 24 |
+
memory_mb = 1024
|
| 25 |
+
storage_mb = 2048
|
| 26 |
+
allow_internet = false
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/tests/checks.json
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"type": "custom",
|
| 4 |
+
"name": "edit_quality",
|
| 5 |
+
"args": {
|
| 6 |
+
"id": "D1",
|
| 7 |
+
"ids": [
|
| 8 |
+
"D1",
|
| 9 |
+
"D2",
|
| 10 |
+
"D3",
|
| 11 |
+
"D4",
|
| 12 |
+
"D5",
|
| 13 |
+
"D6"
|
| 14 |
+
],
|
| 15 |
+
"segments": [
|
| 16 |
+
"H\u00e4r finns ",
|
| 17 |
+
{
|
| 18 |
+
"bad": "en tydlig",
|
| 19 |
+
"good": [
|
| 20 |
+
"ett tydligt"
|
| 21 |
+
]
|
| 22 |
+
},
|
| 23 |
+
" f\u00f6rslag.",
|
| 24 |
+
" Vidar beh\u00f6ver inte betala 16 kronor i dag."
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
"weight": 1.0
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"type": "custom",
|
| 31 |
+
"name": "edit_quality",
|
| 32 |
+
"args": {
|
| 33 |
+
"id": "D2",
|
| 34 |
+
"ids": [
|
| 35 |
+
"D1",
|
| 36 |
+
"D2",
|
| 37 |
+
"D3",
|
| 38 |
+
"D4",
|
| 39 |
+
"D5",
|
| 40 |
+
"D6"
|
| 41 |
+
],
|
| 42 |
+
"segments": [
|
| 43 |
+
"H\u00e4r finns ",
|
| 44 |
+
{
|
| 45 |
+
"bad": "en tydlig",
|
| 46 |
+
"good": [
|
| 47 |
+
"ett tydligt"
|
| 48 |
+
]
|
| 49 |
+
},
|
| 50 |
+
" f\u00f6rslag.",
|
| 51 |
+
" Malte beh\u00f6ver inte betala 49 kronor i dag."
|
| 52 |
+
]
|
| 53 |
+
},
|
| 54 |
+
"weight": 1.0
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"type": "custom",
|
| 58 |
+
"name": "edit_quality",
|
| 59 |
+
"args": {
|
| 60 |
+
"id": "D3",
|
| 61 |
+
"ids": [
|
| 62 |
+
"D1",
|
| 63 |
+
"D2",
|
| 64 |
+
"D3",
|
| 65 |
+
"D4",
|
| 66 |
+
"D5",
|
| 67 |
+
"D6"
|
| 68 |
+
],
|
| 69 |
+
"segments": [
|
| 70 |
+
"H\u00e4r finns ",
|
| 71 |
+
{
|
| 72 |
+
"bad": "en tydlig",
|
| 73 |
+
"good": [
|
| 74 |
+
"ett tydligt"
|
| 75 |
+
]
|
| 76 |
+
},
|
| 77 |
+
" f\u00f6rslag.",
|
| 78 |
+
" Siri beh\u00f6ver inte betala 53 kronor i dag."
|
| 79 |
+
]
|
| 80 |
+
},
|
| 81 |
+
"weight": 1.0
|
| 82 |
+
},
|
| 83 |
+
{
|
| 84 |
+
"type": "custom",
|
| 85 |
+
"name": "edit_quality",
|
| 86 |
+
"args": {
|
| 87 |
+
"id": "D4",
|
| 88 |
+
"ids": [
|
| 89 |
+
"D1",
|
| 90 |
+
"D2",
|
| 91 |
+
"D3",
|
| 92 |
+
"D4",
|
| 93 |
+
"D5",
|
| 94 |
+
"D6"
|
| 95 |
+
],
|
| 96 |
+
"segments": [
|
| 97 |
+
"H\u00e4r finns ",
|
| 98 |
+
{
|
| 99 |
+
"bad": "en tydlig",
|
| 100 |
+
"good": [
|
| 101 |
+
"ett tydligt"
|
| 102 |
+
]
|
| 103 |
+
},
|
| 104 |
+
" f\u00f6rslag.",
|
| 105 |
+
" Hedda beh\u00f6ver inte betala 77 kronor i dag."
|
| 106 |
+
]
|
| 107 |
+
},
|
| 108 |
+
"weight": 1.0
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"type": "custom",
|
| 112 |
+
"name": "edit_quality",
|
| 113 |
+
"args": {
|
| 114 |
+
"id": "D5",
|
| 115 |
+
"ids": [
|
| 116 |
+
"D1",
|
| 117 |
+
"D2",
|
| 118 |
+
"D3",
|
| 119 |
+
"D4",
|
| 120 |
+
"D5",
|
| 121 |
+
"D6"
|
| 122 |
+
],
|
| 123 |
+
"segments": [
|
| 124 |
+
"H\u00e4r finns ",
|
| 125 |
+
{
|
| 126 |
+
"bad": "en tydlig",
|
| 127 |
+
"good": [
|
| 128 |
+
"ett tydligt"
|
| 129 |
+
]
|
| 130 |
+
},
|
| 131 |
+
" f\u00f6rslag.",
|
| 132 |
+
" Vidar beh\u00f6ver inte betala 82 kronor i dag."
|
| 133 |
+
]
|
| 134 |
+
},
|
| 135 |
+
"weight": 1.0
|
| 136 |
+
},
|
| 137 |
+
{
|
| 138 |
+
"type": "custom",
|
| 139 |
+
"name": "edit_quality",
|
| 140 |
+
"args": {
|
| 141 |
+
"id": "D6",
|
| 142 |
+
"ids": [
|
| 143 |
+
"D1",
|
| 144 |
+
"D2",
|
| 145 |
+
"D3",
|
| 146 |
+
"D4",
|
| 147 |
+
"D5",
|
| 148 |
+
"D6"
|
| 149 |
+
],
|
| 150 |
+
"segments": [
|
| 151 |
+
"H\u00e4r finns ",
|
| 152 |
+
{
|
| 153 |
+
"bad": "en tydlig",
|
| 154 |
+
"good": [
|
| 155 |
+
"ett tydligt"
|
| 156 |
+
]
|
| 157 |
+
},
|
| 158 |
+
" f\u00f6rslag.",
|
| 159 |
+
" Malte beh\u00f6ver inte betala 57 kronor i dag."
|
| 160 |
+
]
|
| 161 |
+
},
|
| 162 |
+
"weight": 1.0
|
| 163 |
+
}
|
| 164 |
+
]
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/tests/test.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/tests/validators.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Bounded edit lattice: preserve all literal context, accept multiple local repairs.
|
| 2 |
+
No word-count, readability or keyword reward. Unicode NFC and whitespace are normalised;
|
| 3 |
+
capitalisation, punctuation, words and all facts remain significant.
|
| 4 |
+
"""
|
| 5 |
+
import re,unicodedata
|
| 6 |
+
|
| 7 |
+
def tokens(text):
|
| 8 |
+
if not isinstance(text,str):return None
|
| 9 |
+
return tuple(re.findall(r'\w+|[^\w\s]',unicodedata.normalize('NFC',text),re.UNICODE))
|
| 10 |
+
|
| 11 |
+
def lattice(text,segments,allow_source=True):
|
| 12 |
+
got=tokens(text)
|
| 13 |
+
if got is None or len(got)>3000:return 0.0
|
| 14 |
+
# Position -> best number of corrected slots at that position. Dynamic programming
|
| 15 |
+
# avoids regex backtracking and handles alternatives with overlapping prefixes.
|
| 16 |
+
states={0:0};count=0
|
| 17 |
+
for segment in segments:
|
| 18 |
+
if isinstance(segment,str):options=[(tokens(segment),0)]
|
| 19 |
+
else:
|
| 20 |
+
count+=1;options=[(tokens(v),1) for v in segment['good']]
|
| 21 |
+
if allow_source and 'bad' in segment:options.append((tokens(segment['bad']),0))
|
| 22 |
+
nxt={}
|
| 23 |
+
for pos,score in states.items():
|
| 24 |
+
for seq,credit in options:
|
| 25 |
+
end=pos+len(seq)
|
| 26 |
+
if got[pos:end]==seq:nxt[end]=max(nxt.get(end,-1),score+credit)
|
| 27 |
+
states=nxt
|
| 28 |
+
if not states:return 0.0
|
| 29 |
+
return states.get(len(got),0)/count if count else float(len(got) in states)
|
| 30 |
+
|
| 31 |
+
def edit_quality(answer,args):
|
| 32 |
+
try:
|
| 33 |
+
if not isinstance(answer,dict) or set(answer)!={'documents'}:return 0.0
|
| 34 |
+
docs=answer['documents']
|
| 35 |
+
if not isinstance(docs,dict) or set(docs)!=set(args['ids']):return 0.0
|
| 36 |
+
if any(not isinstance(v,str) for v in docs.values()):return 0.0
|
| 37 |
+
return lattice(docs[args['id']],args['segments'])
|
| 38 |
+
except (KeyError,TypeError,ValueError,AttributeError):return 0.0
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-e0012/tests/verify.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Verifier for Renaissance Labs practice environments. Standard library only.
|
| 3 |
+
|
| 4 |
+
Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
|
| 5 |
+
The reward is the weighted share of checks that pass. A missing, unreadable or non-object
|
| 6 |
+
answer scores 0. Each check addresses one value in the answer by a dotted path.
|
| 7 |
+
|
| 8 |
+
Check types
|
| 9 |
+
int exact integer (a float with integral value is accepted; booleans are not)
|
| 10 |
+
number within abs_tol of value (default 1e-9); booleans and strings are rejected
|
| 11 |
+
str equal after trimming and case-folding
|
| 12 |
+
bool exact boolean
|
| 13 |
+
list ordered list; items compared as int/number/str according to "item" (default str)
|
| 14 |
+
set unordered collection of distinct strings (or ints)
|
| 15 |
+
custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
|
| 16 |
+
"""
|
| 17 |
+
import argparse, json, math, os, sys
|
| 18 |
+
|
| 19 |
+
MISSING = object()
|
| 20 |
+
|
| 21 |
+
def lookup(obj, path):
|
| 22 |
+
cur = obj
|
| 23 |
+
for part in path.split("."):
|
| 24 |
+
if isinstance(cur, dict):
|
| 25 |
+
if part not in cur: return MISSING
|
| 26 |
+
cur = cur[part]
|
| 27 |
+
elif isinstance(cur, list):
|
| 28 |
+
try: cur = cur[int(part)]
|
| 29 |
+
except (ValueError, IndexError): return MISSING
|
| 30 |
+
else:
|
| 31 |
+
return MISSING
|
| 32 |
+
return cur
|
| 33 |
+
|
| 34 |
+
def is_num(x):
|
| 35 |
+
return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
|
| 36 |
+
|
| 37 |
+
def eq_int(got, want):
|
| 38 |
+
return is_num(got) and float(got) == float(int(got)) and int(got) == want
|
| 39 |
+
|
| 40 |
+
def eq_num(got, want, tol):
|
| 41 |
+
return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
|
| 42 |
+
|
| 43 |
+
def eq_str(got, want):
|
| 44 |
+
return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
|
| 45 |
+
|
| 46 |
+
def eq_item(got, want, kind, tol):
|
| 47 |
+
if kind == "int": return eq_int(got, want)
|
| 48 |
+
if kind == "number": return eq_num(got, want, tol)
|
| 49 |
+
return eq_str(got, want)
|
| 50 |
+
|
| 51 |
+
def run_check(answer, chk, validators):
|
| 52 |
+
t = chk["type"]
|
| 53 |
+
if t == "custom":
|
| 54 |
+
fn = getattr(validators, chk["name"], None) if validators else None
|
| 55 |
+
if fn is None: return 0.0
|
| 56 |
+
try: r = fn(answer, chk.get("args", {}))
|
| 57 |
+
except Exception: return 0.0
|
| 58 |
+
if r is True: return 1.0
|
| 59 |
+
if r is False or r is None: return 0.0
|
| 60 |
+
return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
|
| 61 |
+
got = lookup(answer, chk["path"])
|
| 62 |
+
if got is MISSING: return 0.0
|
| 63 |
+
want, tol = chk["value"], chk.get("abs_tol", 1e-9)
|
| 64 |
+
if t == "int": ok = eq_int(got, want)
|
| 65 |
+
elif t == "number": ok = eq_num(got, want, tol)
|
| 66 |
+
elif t == "str": ok = eq_str(got, want)
|
| 67 |
+
elif t == "bool": ok = isinstance(got, bool) and got is want
|
| 68 |
+
elif t == "list":
|
| 69 |
+
ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
|
| 70 |
+
elif t == "set":
|
| 71 |
+
kind = chk.get("item", "str")
|
| 72 |
+
if not isinstance(got, list): ok = False
|
| 73 |
+
else:
|
| 74 |
+
norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
|
| 75 |
+
g = [norm(x) for x in got]; w = [norm(x) for x in want]
|
| 76 |
+
ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
|
| 77 |
+
else: ok = False
|
| 78 |
+
return 1.0 if ok else 0.0
|
| 79 |
+
|
| 80 |
+
def grade(answer, checks, validators=None):
|
| 81 |
+
"""Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
|
| 82 |
+
if not isinstance(answer, dict):
|
| 83 |
+
return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
|
| 84 |
+
total = sum(c.get("weight", 1.0) for c in checks)
|
| 85 |
+
got, details = 0.0, []
|
| 86 |
+
for c in checks:
|
| 87 |
+
s = run_check(answer, c, validators)
|
| 88 |
+
got += s * c.get("weight", 1.0)
|
| 89 |
+
details.append({"check": c.get("path", c.get("name")), "score": s})
|
| 90 |
+
return (round(got / total, 6) if total else 0.0), details
|
| 91 |
+
|
| 92 |
+
def main():
|
| 93 |
+
ap = argparse.ArgumentParser()
|
| 94 |
+
ap.add_argument("--answer", default="/app/answer.json")
|
| 95 |
+
ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
|
| 96 |
+
ap.add_argument("--out", default="/logs/verifier")
|
| 97 |
+
a = ap.parse_args()
|
| 98 |
+
checks = json.load(open(a.checks))
|
| 99 |
+
try:
|
| 100 |
+
with open(a.answer) as f: answer = json.load(f)
|
| 101 |
+
except Exception:
|
| 102 |
+
answer = None
|
| 103 |
+
validators = None
|
| 104 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 105 |
+
if os.path.exists(os.path.join(here, "validators.py")):
|
| 106 |
+
sys.path.insert(0, here)
|
| 107 |
+
import validators # noqa
|
| 108 |
+
reward, details = grade(answer, checks, validators)
|
| 109 |
+
os.makedirs(a.out, exist_ok=True)
|
| 110 |
+
with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
|
| 111 |
+
with open(os.path.join(a.out, "reward.json"), "w") as f:
|
| 112 |
+
json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
|
| 113 |
+
print("reward", reward)
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
main()
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY workdir/ /app/
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/environment/workdir/documents.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"id": "D1",
|
| 4 |
+
"text": "Här finns ett tydligt tidning. Oskar behöver inte betala 82 kronor i dag."
|
| 5 |
+
},
|
| 6 |
+
{
|
| 7 |
+
"id": "D2",
|
| 8 |
+
"text": "Här finns en tydlig bord. Oskar behöver inte betala 66 kronor i dag."
|
| 9 |
+
},
|
| 10 |
+
{
|
| 11 |
+
"id": "D3",
|
| 12 |
+
"text": "Här finns en tydlig bord. Nora behöver inte betala 42 kronor i dag."
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"id": "D4",
|
| 16 |
+
"text": "Här finns en tydlig kvitto. Nora behöver inte betala 36 kronor i dag."
|
| 17 |
+
},
|
| 18 |
+
{
|
| 19 |
+
"id": "D5",
|
| 20 |
+
"text": "Här finns en tydlig kvitto. Nora behöver inte betala 70 kronor i dag."
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"id": "D6",
|
| 24 |
+
"text": "Här finns ett tydligt tidning. Mira behöver inte betala 19 kronor i dag."
|
| 25 |
+
}
|
| 26 |
+
]
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/environment/workdir/lexicon.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"compounds": [
|
| 3 |
+
{
|
| 4 |
+
"correct": "bilnyckeln",
|
| 5 |
+
"split": "bil nyckeln"
|
| 6 |
+
},
|
| 7 |
+
{
|
| 8 |
+
"correct": "personalrummet",
|
| 9 |
+
"split": "personal rummet"
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"correct": "kaffekoppen",
|
| 13 |
+
"split": "kaffe koppen"
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"correct": "arbetsplatsen",
|
| 17 |
+
"split": "arbets platsen"
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"correct": "cykelvägen",
|
| 21 |
+
"split": "cykel vägen"
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"correct": "bokhyllan",
|
| 25 |
+
"split": "bok hyllan"
|
| 26 |
+
}
|
| 27 |
+
],
|
| 28 |
+
"nouns": [
|
| 29 |
+
{
|
| 30 |
+
"word": "kvitto",
|
| 31 |
+
"gender": "ett"
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"word": "brev",
|
| 35 |
+
"gender": "ett"
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"word": "bord",
|
| 39 |
+
"gender": "ett"
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"word": "stol",
|
| 43 |
+
"gender": "en"
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"word": "cykel",
|
| 47 |
+
"gender": "en"
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"word": "tidning",
|
| 51 |
+
"gender": "en"
|
| 52 |
+
}
|
| 53 |
+
]
|
| 54 |
+
}
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/environment/workdir/style.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Redaktionell instruktion
|
| 2 |
+
Rätta bara språkfel. Behåll varje faktauppgift, namn, tal, negation och redan korrekt mening.
|
| 3 |
+
Sammansatta substantiv skrivs ihop. Skriv däremot "i dag" i två ord.
|
| 4 |
+
Använd en/ett och tydlig/tydligt efter substantivets genus i ordlistan.
|
| 5 |
+
De är subjekt; dem är objekt. Efter inledningen "I dag" kommer det finita verbet före subjektet.
|
| 6 |
+
Lägg inte till förklaringar eller alternativa svar. Ordlistan är en språkresurs, inte ett facit till dokumenten.
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/instruction.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Korrekturläsning på svenska
|
| 2 |
+
|
| 3 |
+
Rätta dokumenten i `documents.json` enligt `style.md`. `lexicon.json` anger sammansättningar och genus. Rätta alla och endast de inplanterade språkfelen. Behåll dokumentens uppgifter och meningar som redan är korrekta.
|
| 4 |
+
|
| 5 |
+
Skriv `answer.json` med exakt nyckeln `documents`: ett objekt där varje dokument-id är nyckel och värdet är hela den rättade texten. Alla sex dokument måste finnas med. Normala blankstegsvariationer godtas, men ord, tecken, versaler och fakta bedöms. Varje rättad felplats ger delpoäng endast om resten av dokumentet är oförändrat. Extra påståenden, ändrad negation, ändrade tal eller överrättning ger noll för dokumentet. Oförändrad felaktig text ger ingen poäng.
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/solution/oracle.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Independent rule-based proofreader, operating only on supplied files."""
|
| 2 |
+
import json,re
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
def solve():
|
| 6 |
+
lex=json.loads(Path('lexicon.json').read_text());result={}
|
| 7 |
+
nouns={n['word']:n['gender'] for n in lex['nouns']}
|
| 8 |
+
def agreement(m):
|
| 9 |
+
gender=nouns.get(m.group(3))
|
| 10 |
+
if not gender:return m.group(0)
|
| 11 |
+
return gender+' '+('tydligt' if gender=='ett' else 'tydlig')+' '+m.group(3)
|
| 12 |
+
for doc in json.loads(Path('documents.json').read_text()):
|
| 13 |
+
text=doc['text']
|
| 14 |
+
for pair in lex['compounds']:text=re.sub(r'\b'+re.escape(pair['split'])+r'\b',pair['correct'],text)
|
| 15 |
+
text=re.sub(r'\b(en|ett) (tydlig|tydligt) (\w+)\b',agreement,text)
|
| 16 |
+
text=text.replace('I dag de granskar','I dag granskar de')
|
| 17 |
+
text=re.sub(r'\bDem visar\b','De visar',text)
|
| 18 |
+
text=re.sub(r'\bhjälper de efter\b','hjälper dem efter',text)
|
| 19 |
+
result[doc['id']]=text
|
| 20 |
+
return {'documents':result}
|
| 21 |
+
|
| 22 |
+
if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve(),ensure_ascii=False))
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
cd /app
|
| 4 |
+
python3 /solution/oracle.py
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/task.toml
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[metadata]
|
| 4 |
+
author_name = "Renaissance Labs"
|
| 5 |
+
author_email = "unknown"
|
| 6 |
+
difficulty = "easy"
|
| 7 |
+
category = "swedish-proofreading"
|
| 8 |
+
tags = ["swedish-proofreading", "agreement", "isced-0232", "train", "language-sv"]
|
| 9 |
+
isced_f = "0232"
|
| 10 |
+
family = "agreement"
|
| 11 |
+
split = "train"
|
| 12 |
+
seed = 0
|
| 13 |
+
languages = ["sv"]
|
| 14 |
+
|
| 15 |
+
[verifier]
|
| 16 |
+
timeout_sec = 120.0
|
| 17 |
+
|
| 18 |
+
[agent]
|
| 19 |
+
timeout_sec = 900.0
|
| 20 |
+
|
| 21 |
+
[environment]
|
| 22 |
+
build_timeout_sec = 600.0
|
| 23 |
+
cpus = 1
|
| 24 |
+
memory_mb = 1024
|
| 25 |
+
storage_mb = 2048
|
| 26 |
+
allow_internet = false
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/tests/checks.json
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"type": "custom",
|
| 4 |
+
"name": "edit_quality",
|
| 5 |
+
"args": {
|
| 6 |
+
"id": "D1",
|
| 7 |
+
"ids": [
|
| 8 |
+
"D1",
|
| 9 |
+
"D2",
|
| 10 |
+
"D3",
|
| 11 |
+
"D4",
|
| 12 |
+
"D5",
|
| 13 |
+
"D6"
|
| 14 |
+
],
|
| 15 |
+
"segments": [
|
| 16 |
+
"H\u00e4r finns ",
|
| 17 |
+
{
|
| 18 |
+
"bad": "ett tydligt",
|
| 19 |
+
"good": [
|
| 20 |
+
"en tydlig"
|
| 21 |
+
]
|
| 22 |
+
},
|
| 23 |
+
" tidning.",
|
| 24 |
+
" Oskar beh\u00f6ver inte betala 82 kronor i dag."
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
"weight": 1.0
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"type": "custom",
|
| 31 |
+
"name": "edit_quality",
|
| 32 |
+
"args": {
|
| 33 |
+
"id": "D2",
|
| 34 |
+
"ids": [
|
| 35 |
+
"D1",
|
| 36 |
+
"D2",
|
| 37 |
+
"D3",
|
| 38 |
+
"D4",
|
| 39 |
+
"D5",
|
| 40 |
+
"D6"
|
| 41 |
+
],
|
| 42 |
+
"segments": [
|
| 43 |
+
"H\u00e4r finns ",
|
| 44 |
+
{
|
| 45 |
+
"bad": "en tydlig",
|
| 46 |
+
"good": [
|
| 47 |
+
"ett tydligt"
|
| 48 |
+
]
|
| 49 |
+
},
|
| 50 |
+
" bord.",
|
| 51 |
+
" Oskar beh\u00f6ver inte betala 66 kronor i dag."
|
| 52 |
+
]
|
| 53 |
+
},
|
| 54 |
+
"weight": 1.0
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"type": "custom",
|
| 58 |
+
"name": "edit_quality",
|
| 59 |
+
"args": {
|
| 60 |
+
"id": "D3",
|
| 61 |
+
"ids": [
|
| 62 |
+
"D1",
|
| 63 |
+
"D2",
|
| 64 |
+
"D3",
|
| 65 |
+
"D4",
|
| 66 |
+
"D5",
|
| 67 |
+
"D6"
|
| 68 |
+
],
|
| 69 |
+
"segments": [
|
| 70 |
+
"H\u00e4r finns ",
|
| 71 |
+
{
|
| 72 |
+
"bad": "en tydlig",
|
| 73 |
+
"good": [
|
| 74 |
+
"ett tydligt"
|
| 75 |
+
]
|
| 76 |
+
},
|
| 77 |
+
" bord.",
|
| 78 |
+
" Nora beh\u00f6ver inte betala 42 kronor i dag."
|
| 79 |
+
]
|
| 80 |
+
},
|
| 81 |
+
"weight": 1.0
|
| 82 |
+
},
|
| 83 |
+
{
|
| 84 |
+
"type": "custom",
|
| 85 |
+
"name": "edit_quality",
|
| 86 |
+
"args": {
|
| 87 |
+
"id": "D4",
|
| 88 |
+
"ids": [
|
| 89 |
+
"D1",
|
| 90 |
+
"D2",
|
| 91 |
+
"D3",
|
| 92 |
+
"D4",
|
| 93 |
+
"D5",
|
| 94 |
+
"D6"
|
| 95 |
+
],
|
| 96 |
+
"segments": [
|
| 97 |
+
"H\u00e4r finns ",
|
| 98 |
+
{
|
| 99 |
+
"bad": "en tydlig",
|
| 100 |
+
"good": [
|
| 101 |
+
"ett tydligt"
|
| 102 |
+
]
|
| 103 |
+
},
|
| 104 |
+
" kvitto.",
|
| 105 |
+
" Nora beh\u00f6ver inte betala 36 kronor i dag."
|
| 106 |
+
]
|
| 107 |
+
},
|
| 108 |
+
"weight": 1.0
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"type": "custom",
|
| 112 |
+
"name": "edit_quality",
|
| 113 |
+
"args": {
|
| 114 |
+
"id": "D5",
|
| 115 |
+
"ids": [
|
| 116 |
+
"D1",
|
| 117 |
+
"D2",
|
| 118 |
+
"D3",
|
| 119 |
+
"D4",
|
| 120 |
+
"D5",
|
| 121 |
+
"D6"
|
| 122 |
+
],
|
| 123 |
+
"segments": [
|
| 124 |
+
"H\u00e4r finns ",
|
| 125 |
+
{
|
| 126 |
+
"bad": "en tydlig",
|
| 127 |
+
"good": [
|
| 128 |
+
"ett tydligt"
|
| 129 |
+
]
|
| 130 |
+
},
|
| 131 |
+
" kvitto.",
|
| 132 |
+
" Nora beh\u00f6ver inte betala 70 kronor i dag."
|
| 133 |
+
]
|
| 134 |
+
},
|
| 135 |
+
"weight": 1.0
|
| 136 |
+
},
|
| 137 |
+
{
|
| 138 |
+
"type": "custom",
|
| 139 |
+
"name": "edit_quality",
|
| 140 |
+
"args": {
|
| 141 |
+
"id": "D6",
|
| 142 |
+
"ids": [
|
| 143 |
+
"D1",
|
| 144 |
+
"D2",
|
| 145 |
+
"D3",
|
| 146 |
+
"D4",
|
| 147 |
+
"D5",
|
| 148 |
+
"D6"
|
| 149 |
+
],
|
| 150 |
+
"segments": [
|
| 151 |
+
"H\u00e4r finns ",
|
| 152 |
+
{
|
| 153 |
+
"bad": "ett tydligt",
|
| 154 |
+
"good": [
|
| 155 |
+
"en tydlig"
|
| 156 |
+
]
|
| 157 |
+
},
|
| 158 |
+
" tidning.",
|
| 159 |
+
" Mira beh\u00f6ver inte betala 19 kronor i dag."
|
| 160 |
+
]
|
| 161 |
+
},
|
| 162 |
+
"weight": 1.0
|
| 163 |
+
}
|
| 164 |
+
]
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/tests/test.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/tests/validators.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Bounded edit lattice: preserve all literal context, accept multiple local repairs.
|
| 2 |
+
No word-count, readability or keyword reward. Unicode NFC and whitespace are normalised;
|
| 3 |
+
capitalisation, punctuation, words and all facts remain significant.
|
| 4 |
+
"""
|
| 5 |
+
import re,unicodedata
|
| 6 |
+
|
| 7 |
+
def tokens(text):
|
| 8 |
+
if not isinstance(text,str):return None
|
| 9 |
+
return tuple(re.findall(r'\w+|[^\w\s]',unicodedata.normalize('NFC',text),re.UNICODE))
|
| 10 |
+
|
| 11 |
+
def lattice(text,segments,allow_source=True):
|
| 12 |
+
got=tokens(text)
|
| 13 |
+
if got is None or len(got)>3000:return 0.0
|
| 14 |
+
# Position -> best number of corrected slots at that position. Dynamic programming
|
| 15 |
+
# avoids regex backtracking and handles alternatives with overlapping prefixes.
|
| 16 |
+
states={0:0};count=0
|
| 17 |
+
for segment in segments:
|
| 18 |
+
if isinstance(segment,str):options=[(tokens(segment),0)]
|
| 19 |
+
else:
|
| 20 |
+
count+=1;options=[(tokens(v),1) for v in segment['good']]
|
| 21 |
+
if allow_source and 'bad' in segment:options.append((tokens(segment['bad']),0))
|
| 22 |
+
nxt={}
|
| 23 |
+
for pos,score in states.items():
|
| 24 |
+
for seq,credit in options:
|
| 25 |
+
end=pos+len(seq)
|
| 26 |
+
if got[pos:end]==seq:nxt[end]=max(nxt.get(end,-1),score+credit)
|
| 27 |
+
states=nxt
|
| 28 |
+
if not states:return 0.0
|
| 29 |
+
return states.get(len(got),0)/count if count else float(len(got) in states)
|
| 30 |
+
|
| 31 |
+
def edit_quality(answer,args):
|
| 32 |
+
try:
|
| 33 |
+
if not isinstance(answer,dict) or set(answer)!={'documents'}:return 0.0
|
| 34 |
+
docs=answer['documents']
|
| 35 |
+
if not isinstance(docs,dict) or set(docs)!=set(args['ids']):return 0.0
|
| 36 |
+
if any(not isinstance(v,str) for v in docs.values()):return 0.0
|
| 37 |
+
return lattice(docs[args['id']],args['segments'])
|
| 38 |
+
except (KeyError,TypeError,ValueError,AttributeError):return 0.0
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0000/tests/verify.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Verifier for Renaissance Labs practice environments. Standard library only.
|
| 3 |
+
|
| 4 |
+
Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
|
| 5 |
+
The reward is the weighted share of checks that pass. A missing, unreadable or non-object
|
| 6 |
+
answer scores 0. Each check addresses one value in the answer by a dotted path.
|
| 7 |
+
|
| 8 |
+
Check types
|
| 9 |
+
int exact integer (a float with integral value is accepted; booleans are not)
|
| 10 |
+
number within abs_tol of value (default 1e-9); booleans and strings are rejected
|
| 11 |
+
str equal after trimming and case-folding
|
| 12 |
+
bool exact boolean
|
| 13 |
+
list ordered list; items compared as int/number/str according to "item" (default str)
|
| 14 |
+
set unordered collection of distinct strings (or ints)
|
| 15 |
+
custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
|
| 16 |
+
"""
|
| 17 |
+
import argparse, json, math, os, sys
|
| 18 |
+
|
| 19 |
+
MISSING = object()
|
| 20 |
+
|
| 21 |
+
def lookup(obj, path):
|
| 22 |
+
cur = obj
|
| 23 |
+
for part in path.split("."):
|
| 24 |
+
if isinstance(cur, dict):
|
| 25 |
+
if part not in cur: return MISSING
|
| 26 |
+
cur = cur[part]
|
| 27 |
+
elif isinstance(cur, list):
|
| 28 |
+
try: cur = cur[int(part)]
|
| 29 |
+
except (ValueError, IndexError): return MISSING
|
| 30 |
+
else:
|
| 31 |
+
return MISSING
|
| 32 |
+
return cur
|
| 33 |
+
|
| 34 |
+
def is_num(x):
|
| 35 |
+
return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
|
| 36 |
+
|
| 37 |
+
def eq_int(got, want):
|
| 38 |
+
return is_num(got) and float(got) == float(int(got)) and int(got) == want
|
| 39 |
+
|
| 40 |
+
def eq_num(got, want, tol):
|
| 41 |
+
return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
|
| 42 |
+
|
| 43 |
+
def eq_str(got, want):
|
| 44 |
+
return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
|
| 45 |
+
|
| 46 |
+
def eq_item(got, want, kind, tol):
|
| 47 |
+
if kind == "int": return eq_int(got, want)
|
| 48 |
+
if kind == "number": return eq_num(got, want, tol)
|
| 49 |
+
return eq_str(got, want)
|
| 50 |
+
|
| 51 |
+
def run_check(answer, chk, validators):
|
| 52 |
+
t = chk["type"]
|
| 53 |
+
if t == "custom":
|
| 54 |
+
fn = getattr(validators, chk["name"], None) if validators else None
|
| 55 |
+
if fn is None: return 0.0
|
| 56 |
+
try: r = fn(answer, chk.get("args", {}))
|
| 57 |
+
except Exception: return 0.0
|
| 58 |
+
if r is True: return 1.0
|
| 59 |
+
if r is False or r is None: return 0.0
|
| 60 |
+
return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
|
| 61 |
+
got = lookup(answer, chk["path"])
|
| 62 |
+
if got is MISSING: return 0.0
|
| 63 |
+
want, tol = chk["value"], chk.get("abs_tol", 1e-9)
|
| 64 |
+
if t == "int": ok = eq_int(got, want)
|
| 65 |
+
elif t == "number": ok = eq_num(got, want, tol)
|
| 66 |
+
elif t == "str": ok = eq_str(got, want)
|
| 67 |
+
elif t == "bool": ok = isinstance(got, bool) and got is want
|
| 68 |
+
elif t == "list":
|
| 69 |
+
ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
|
| 70 |
+
elif t == "set":
|
| 71 |
+
kind = chk.get("item", "str")
|
| 72 |
+
if not isinstance(got, list): ok = False
|
| 73 |
+
else:
|
| 74 |
+
norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
|
| 75 |
+
g = [norm(x) for x in got]; w = [norm(x) for x in want]
|
| 76 |
+
ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
|
| 77 |
+
else: ok = False
|
| 78 |
+
return 1.0 if ok else 0.0
|
| 79 |
+
|
| 80 |
+
def grade(answer, checks, validators=None):
|
| 81 |
+
"""Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
|
| 82 |
+
if not isinstance(answer, dict):
|
| 83 |
+
return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
|
| 84 |
+
total = sum(c.get("weight", 1.0) for c in checks)
|
| 85 |
+
got, details = 0.0, []
|
| 86 |
+
for c in checks:
|
| 87 |
+
s = run_check(answer, c, validators)
|
| 88 |
+
got += s * c.get("weight", 1.0)
|
| 89 |
+
details.append({"check": c.get("path", c.get("name")), "score": s})
|
| 90 |
+
return (round(got / total, 6) if total else 0.0), details
|
| 91 |
+
|
| 92 |
+
def main():
|
| 93 |
+
ap = argparse.ArgumentParser()
|
| 94 |
+
ap.add_argument("--answer", default="/app/answer.json")
|
| 95 |
+
ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
|
| 96 |
+
ap.add_argument("--out", default="/logs/verifier")
|
| 97 |
+
a = ap.parse_args()
|
| 98 |
+
checks = json.load(open(a.checks))
|
| 99 |
+
try:
|
| 100 |
+
with open(a.answer) as f: answer = json.load(f)
|
| 101 |
+
except Exception:
|
| 102 |
+
answer = None
|
| 103 |
+
validators = None
|
| 104 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 105 |
+
if os.path.exists(os.path.join(here, "validators.py")):
|
| 106 |
+
sys.path.insert(0, here)
|
| 107 |
+
import validators # noqa
|
| 108 |
+
reward, details = grade(answer, checks, validators)
|
| 109 |
+
os.makedirs(a.out, exist_ok=True)
|
| 110 |
+
with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
|
| 111 |
+
with open(os.path.join(a.out, "reward.json"), "w") as f:
|
| 112 |
+
json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
|
| 113 |
+
print("reward", reward)
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
main()
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY workdir/ /app/
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/environment/workdir/documents.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"id": "D1",
|
| 4 |
+
"text": "Här finns en tydlig bord. Alva behöver inte betala 27 kronor i dag."
|
| 5 |
+
},
|
| 6 |
+
{
|
| 7 |
+
"id": "D2",
|
| 8 |
+
"text": "Här finns en tydlig brev. Oskar behöver inte betala 44 kronor i dag."
|
| 9 |
+
},
|
| 10 |
+
{
|
| 11 |
+
"id": "D3",
|
| 12 |
+
"text": "Här finns en tydlig kvitto. Alva behöver inte betala 60 kronor i dag."
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"id": "D4",
|
| 16 |
+
"text": "Här finns ett tydligt tidning. Nora behöver inte betala 63 kronor i dag."
|
| 17 |
+
},
|
| 18 |
+
{
|
| 19 |
+
"id": "D5",
|
| 20 |
+
"text": "Här finns en tydlig bord. Mira behöver inte betala 20 kronor i dag."
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"id": "D6",
|
| 24 |
+
"text": "Här finns en tydlig kvitto. Mira behöver inte betala 60 kronor i dag."
|
| 25 |
+
}
|
| 26 |
+
]
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/environment/workdir/lexicon.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"compounds": [
|
| 3 |
+
{
|
| 4 |
+
"correct": "bilnyckeln",
|
| 5 |
+
"split": "bil nyckeln"
|
| 6 |
+
},
|
| 7 |
+
{
|
| 8 |
+
"correct": "personalrummet",
|
| 9 |
+
"split": "personal rummet"
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"correct": "kaffekoppen",
|
| 13 |
+
"split": "kaffe koppen"
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"correct": "arbetsplatsen",
|
| 17 |
+
"split": "arbets platsen"
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"correct": "cykelvägen",
|
| 21 |
+
"split": "cykel vägen"
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"correct": "bokhyllan",
|
| 25 |
+
"split": "bok hyllan"
|
| 26 |
+
}
|
| 27 |
+
],
|
| 28 |
+
"nouns": [
|
| 29 |
+
{
|
| 30 |
+
"word": "kvitto",
|
| 31 |
+
"gender": "ett"
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"word": "brev",
|
| 35 |
+
"gender": "ett"
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"word": "bord",
|
| 39 |
+
"gender": "ett"
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"word": "stol",
|
| 43 |
+
"gender": "en"
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"word": "cykel",
|
| 47 |
+
"gender": "en"
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"word": "tidning",
|
| 51 |
+
"gender": "en"
|
| 52 |
+
}
|
| 53 |
+
]
|
| 54 |
+
}
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/environment/workdir/style.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Redaktionell instruktion
|
| 2 |
+
Rätta bara språkfel. Behåll varje faktauppgift, namn, tal, negation och redan korrekt mening.
|
| 3 |
+
Sammansatta substantiv skrivs ihop. Skriv däremot "i dag" i två ord.
|
| 4 |
+
Använd en/ett och tydlig/tydligt efter substantivets genus i ordlistan.
|
| 5 |
+
De är subjekt; dem är objekt. Efter inledningen "I dag" kommer det finita verbet före subjektet.
|
| 6 |
+
Lägg inte till förklaringar eller alternativa svar. Ordlistan är en språkresurs, inte ett facit till dokumenten.
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/instruction.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Korrekturläsning på svenska
|
| 2 |
+
|
| 3 |
+
Rätta dokumenten i `documents.json` enligt `style.md`. `lexicon.json` anger sammansättningar och genus. Rätta alla och endast de inplanterade språkfelen. Behåll dokumentens uppgifter och meningar som redan är korrekta.
|
| 4 |
+
|
| 5 |
+
Skriv `answer.json` med exakt nyckeln `documents`: ett objekt där varje dokument-id är nyckel och värdet är hela den rättade texten. Alla sex dokument måste finnas med. Normala blankstegsvariationer godtas, men ord, tecken, versaler och fakta bedöms. Varje rättad felplats ger delpoäng endast om resten av dokumentet är oförändrat. Extra påståenden, ändrad negation, ändrade tal eller överrättning ger noll för dokumentet. Oförändrad felaktig text ger ingen poäng.
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/solution/oracle.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Independent rule-based proofreader, operating only on supplied files."""
|
| 2 |
+
import json,re
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
def solve():
|
| 6 |
+
lex=json.loads(Path('lexicon.json').read_text());result={}
|
| 7 |
+
nouns={n['word']:n['gender'] for n in lex['nouns']}
|
| 8 |
+
def agreement(m):
|
| 9 |
+
gender=nouns.get(m.group(3))
|
| 10 |
+
if not gender:return m.group(0)
|
| 11 |
+
return gender+' '+('tydligt' if gender=='ett' else 'tydlig')+' '+m.group(3)
|
| 12 |
+
for doc in json.loads(Path('documents.json').read_text()):
|
| 13 |
+
text=doc['text']
|
| 14 |
+
for pair in lex['compounds']:text=re.sub(r'\b'+re.escape(pair['split'])+r'\b',pair['correct'],text)
|
| 15 |
+
text=re.sub(r'\b(en|ett) (tydlig|tydligt) (\w+)\b',agreement,text)
|
| 16 |
+
text=text.replace('I dag de granskar','I dag granskar de')
|
| 17 |
+
text=re.sub(r'\bDem visar\b','De visar',text)
|
| 18 |
+
text=re.sub(r'\bhjälper de efter\b','hjälper dem efter',text)
|
| 19 |
+
result[doc['id']]=text
|
| 20 |
+
return {'documents':result}
|
| 21 |
+
|
| 22 |
+
if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve(),ensure_ascii=False))
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
cd /app
|
| 4 |
+
python3 /solution/oracle.py
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/task.toml
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[metadata]
|
| 4 |
+
author_name = "Renaissance Labs"
|
| 5 |
+
author_email = "unknown"
|
| 6 |
+
difficulty = "easy"
|
| 7 |
+
category = "swedish-proofreading"
|
| 8 |
+
tags = ["swedish-proofreading", "agreement", "isced-0232", "train", "language-sv"]
|
| 9 |
+
isced_f = "0232"
|
| 10 |
+
family = "agreement"
|
| 11 |
+
split = "train"
|
| 12 |
+
seed = 12
|
| 13 |
+
languages = ["sv"]
|
| 14 |
+
|
| 15 |
+
[verifier]
|
| 16 |
+
timeout_sec = 120.0
|
| 17 |
+
|
| 18 |
+
[agent]
|
| 19 |
+
timeout_sec = 900.0
|
| 20 |
+
|
| 21 |
+
[environment]
|
| 22 |
+
build_timeout_sec = 600.0
|
| 23 |
+
cpus = 1
|
| 24 |
+
memory_mb = 1024
|
| 25 |
+
storage_mb = 2048
|
| 26 |
+
allow_internet = false
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/tests/checks.json
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"type": "custom",
|
| 4 |
+
"name": "edit_quality",
|
| 5 |
+
"args": {
|
| 6 |
+
"id": "D1",
|
| 7 |
+
"ids": [
|
| 8 |
+
"D1",
|
| 9 |
+
"D2",
|
| 10 |
+
"D3",
|
| 11 |
+
"D4",
|
| 12 |
+
"D5",
|
| 13 |
+
"D6"
|
| 14 |
+
],
|
| 15 |
+
"segments": [
|
| 16 |
+
"H\u00e4r finns ",
|
| 17 |
+
{
|
| 18 |
+
"bad": "en tydlig",
|
| 19 |
+
"good": [
|
| 20 |
+
"ett tydligt"
|
| 21 |
+
]
|
| 22 |
+
},
|
| 23 |
+
" bord.",
|
| 24 |
+
" Alva beh\u00f6ver inte betala 27 kronor i dag."
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
"weight": 1.0
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"type": "custom",
|
| 31 |
+
"name": "edit_quality",
|
| 32 |
+
"args": {
|
| 33 |
+
"id": "D2",
|
| 34 |
+
"ids": [
|
| 35 |
+
"D1",
|
| 36 |
+
"D2",
|
| 37 |
+
"D3",
|
| 38 |
+
"D4",
|
| 39 |
+
"D5",
|
| 40 |
+
"D6"
|
| 41 |
+
],
|
| 42 |
+
"segments": [
|
| 43 |
+
"H\u00e4r finns ",
|
| 44 |
+
{
|
| 45 |
+
"bad": "en tydlig",
|
| 46 |
+
"good": [
|
| 47 |
+
"ett tydligt"
|
| 48 |
+
]
|
| 49 |
+
},
|
| 50 |
+
" brev.",
|
| 51 |
+
" Oskar beh\u00f6ver inte betala 44 kronor i dag."
|
| 52 |
+
]
|
| 53 |
+
},
|
| 54 |
+
"weight": 1.0
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"type": "custom",
|
| 58 |
+
"name": "edit_quality",
|
| 59 |
+
"args": {
|
| 60 |
+
"id": "D3",
|
| 61 |
+
"ids": [
|
| 62 |
+
"D1",
|
| 63 |
+
"D2",
|
| 64 |
+
"D3",
|
| 65 |
+
"D4",
|
| 66 |
+
"D5",
|
| 67 |
+
"D6"
|
| 68 |
+
],
|
| 69 |
+
"segments": [
|
| 70 |
+
"H\u00e4r finns ",
|
| 71 |
+
{
|
| 72 |
+
"bad": "en tydlig",
|
| 73 |
+
"good": [
|
| 74 |
+
"ett tydligt"
|
| 75 |
+
]
|
| 76 |
+
},
|
| 77 |
+
" kvitto.",
|
| 78 |
+
" Alva beh\u00f6ver inte betala 60 kronor i dag."
|
| 79 |
+
]
|
| 80 |
+
},
|
| 81 |
+
"weight": 1.0
|
| 82 |
+
},
|
| 83 |
+
{
|
| 84 |
+
"type": "custom",
|
| 85 |
+
"name": "edit_quality",
|
| 86 |
+
"args": {
|
| 87 |
+
"id": "D4",
|
| 88 |
+
"ids": [
|
| 89 |
+
"D1",
|
| 90 |
+
"D2",
|
| 91 |
+
"D3",
|
| 92 |
+
"D4",
|
| 93 |
+
"D5",
|
| 94 |
+
"D6"
|
| 95 |
+
],
|
| 96 |
+
"segments": [
|
| 97 |
+
"H\u00e4r finns ",
|
| 98 |
+
{
|
| 99 |
+
"bad": "ett tydligt",
|
| 100 |
+
"good": [
|
| 101 |
+
"en tydlig"
|
| 102 |
+
]
|
| 103 |
+
},
|
| 104 |
+
" tidning.",
|
| 105 |
+
" Nora beh\u00f6ver inte betala 63 kronor i dag."
|
| 106 |
+
]
|
| 107 |
+
},
|
| 108 |
+
"weight": 1.0
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"type": "custom",
|
| 112 |
+
"name": "edit_quality",
|
| 113 |
+
"args": {
|
| 114 |
+
"id": "D5",
|
| 115 |
+
"ids": [
|
| 116 |
+
"D1",
|
| 117 |
+
"D2",
|
| 118 |
+
"D3",
|
| 119 |
+
"D4",
|
| 120 |
+
"D5",
|
| 121 |
+
"D6"
|
| 122 |
+
],
|
| 123 |
+
"segments": [
|
| 124 |
+
"H\u00e4r finns ",
|
| 125 |
+
{
|
| 126 |
+
"bad": "en tydlig",
|
| 127 |
+
"good": [
|
| 128 |
+
"ett tydligt"
|
| 129 |
+
]
|
| 130 |
+
},
|
| 131 |
+
" bord.",
|
| 132 |
+
" Mira beh\u00f6ver inte betala 20 kronor i dag."
|
| 133 |
+
]
|
| 134 |
+
},
|
| 135 |
+
"weight": 1.0
|
| 136 |
+
},
|
| 137 |
+
{
|
| 138 |
+
"type": "custom",
|
| 139 |
+
"name": "edit_quality",
|
| 140 |
+
"args": {
|
| 141 |
+
"id": "D6",
|
| 142 |
+
"ids": [
|
| 143 |
+
"D1",
|
| 144 |
+
"D2",
|
| 145 |
+
"D3",
|
| 146 |
+
"D4",
|
| 147 |
+
"D5",
|
| 148 |
+
"D6"
|
| 149 |
+
],
|
| 150 |
+
"segments": [
|
| 151 |
+
"H\u00e4r finns ",
|
| 152 |
+
{
|
| 153 |
+
"bad": "en tydlig",
|
| 154 |
+
"good": [
|
| 155 |
+
"ett tydligt"
|
| 156 |
+
]
|
| 157 |
+
},
|
| 158 |
+
" kvitto.",
|
| 159 |
+
" Mira beh\u00f6ver inte betala 60 kronor i dag."
|
| 160 |
+
]
|
| 161 |
+
},
|
| 162 |
+
"weight": 1.0
|
| 163 |
+
}
|
| 164 |
+
]
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/tests/test.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/tests/validators.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Bounded edit lattice: preserve all literal context, accept multiple local repairs.
|
| 2 |
+
No word-count, readability or keyword reward. Unicode NFC and whitespace are normalised;
|
| 3 |
+
capitalisation, punctuation, words and all facts remain significant.
|
| 4 |
+
"""
|
| 5 |
+
import re,unicodedata
|
| 6 |
+
|
| 7 |
+
def tokens(text):
|
| 8 |
+
if not isinstance(text,str):return None
|
| 9 |
+
return tuple(re.findall(r'\w+|[^\w\s]',unicodedata.normalize('NFC',text),re.UNICODE))
|
| 10 |
+
|
| 11 |
+
def lattice(text,segments,allow_source=True):
|
| 12 |
+
got=tokens(text)
|
| 13 |
+
if got is None or len(got)>3000:return 0.0
|
| 14 |
+
# Position -> best number of corrected slots at that position. Dynamic programming
|
| 15 |
+
# avoids regex backtracking and handles alternatives with overlapping prefixes.
|
| 16 |
+
states={0:0};count=0
|
| 17 |
+
for segment in segments:
|
| 18 |
+
if isinstance(segment,str):options=[(tokens(segment),0)]
|
| 19 |
+
else:
|
| 20 |
+
count+=1;options=[(tokens(v),1) for v in segment['good']]
|
| 21 |
+
if allow_source and 'bad' in segment:options.append((tokens(segment['bad']),0))
|
| 22 |
+
nxt={}
|
| 23 |
+
for pos,score in states.items():
|
| 24 |
+
for seq,credit in options:
|
| 25 |
+
end=pos+len(seq)
|
| 26 |
+
if got[pos:end]==seq:nxt[end]=max(nxt.get(end,-1),score+credit)
|
| 27 |
+
states=nxt
|
| 28 |
+
if not states:return 0.0
|
| 29 |
+
return states.get(len(got),0)/count if count else float(len(got) in states)
|
| 30 |
+
|
| 31 |
+
def edit_quality(answer,args):
|
| 32 |
+
try:
|
| 33 |
+
if not isinstance(answer,dict) or set(answer)!={'documents'}:return 0.0
|
| 34 |
+
docs=answer['documents']
|
| 35 |
+
if not isinstance(docs,dict) or set(docs)!=set(args['ids']):return 0.0
|
| 36 |
+
if any(not isinstance(v,str) for v in docs.values()):return 0.0
|
| 37 |
+
return lattice(docs[args['id']],args['segments'])
|
| 38 |
+
except (KeyError,TypeError,ValueError,AttributeError):return 0.0
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0012/tests/verify.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Verifier for Renaissance Labs practice environments. Standard library only.
|
| 3 |
+
|
| 4 |
+
Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
|
| 5 |
+
The reward is the weighted share of checks that pass. A missing, unreadable or non-object
|
| 6 |
+
answer scores 0. Each check addresses one value in the answer by a dotted path.
|
| 7 |
+
|
| 8 |
+
Check types
|
| 9 |
+
int exact integer (a float with integral value is accepted; booleans are not)
|
| 10 |
+
number within abs_tol of value (default 1e-9); booleans and strings are rejected
|
| 11 |
+
str equal after trimming and case-folding
|
| 12 |
+
bool exact boolean
|
| 13 |
+
list ordered list; items compared as int/number/str according to "item" (default str)
|
| 14 |
+
set unordered collection of distinct strings (or ints)
|
| 15 |
+
custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
|
| 16 |
+
"""
|
| 17 |
+
import argparse, json, math, os, sys
|
| 18 |
+
|
| 19 |
+
MISSING = object()
|
| 20 |
+
|
| 21 |
+
def lookup(obj, path):
|
| 22 |
+
cur = obj
|
| 23 |
+
for part in path.split("."):
|
| 24 |
+
if isinstance(cur, dict):
|
| 25 |
+
if part not in cur: return MISSING
|
| 26 |
+
cur = cur[part]
|
| 27 |
+
elif isinstance(cur, list):
|
| 28 |
+
try: cur = cur[int(part)]
|
| 29 |
+
except (ValueError, IndexError): return MISSING
|
| 30 |
+
else:
|
| 31 |
+
return MISSING
|
| 32 |
+
return cur
|
| 33 |
+
|
| 34 |
+
def is_num(x):
|
| 35 |
+
return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
|
| 36 |
+
|
| 37 |
+
def eq_int(got, want):
|
| 38 |
+
return is_num(got) and float(got) == float(int(got)) and int(got) == want
|
| 39 |
+
|
| 40 |
+
def eq_num(got, want, tol):
|
| 41 |
+
return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
|
| 42 |
+
|
| 43 |
+
def eq_str(got, want):
|
| 44 |
+
return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
|
| 45 |
+
|
| 46 |
+
def eq_item(got, want, kind, tol):
|
| 47 |
+
if kind == "int": return eq_int(got, want)
|
| 48 |
+
if kind == "number": return eq_num(got, want, tol)
|
| 49 |
+
return eq_str(got, want)
|
| 50 |
+
|
| 51 |
+
def run_check(answer, chk, validators):
|
| 52 |
+
t = chk["type"]
|
| 53 |
+
if t == "custom":
|
| 54 |
+
fn = getattr(validators, chk["name"], None) if validators else None
|
| 55 |
+
if fn is None: return 0.0
|
| 56 |
+
try: r = fn(answer, chk.get("args", {}))
|
| 57 |
+
except Exception: return 0.0
|
| 58 |
+
if r is True: return 1.0
|
| 59 |
+
if r is False or r is None: return 0.0
|
| 60 |
+
return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
|
| 61 |
+
got = lookup(answer, chk["path"])
|
| 62 |
+
if got is MISSING: return 0.0
|
| 63 |
+
want, tol = chk["value"], chk.get("abs_tol", 1e-9)
|
| 64 |
+
if t == "int": ok = eq_int(got, want)
|
| 65 |
+
elif t == "number": ok = eq_num(got, want, tol)
|
| 66 |
+
elif t == "str": ok = eq_str(got, want)
|
| 67 |
+
elif t == "bool": ok = isinstance(got, bool) and got is want
|
| 68 |
+
elif t == "list":
|
| 69 |
+
ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
|
| 70 |
+
elif t == "set":
|
| 71 |
+
kind = chk.get("item", "str")
|
| 72 |
+
if not isinstance(got, list): ok = False
|
| 73 |
+
else:
|
| 74 |
+
norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
|
| 75 |
+
g = [norm(x) for x in got]; w = [norm(x) for x in want]
|
| 76 |
+
ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
|
| 77 |
+
else: ok = False
|
| 78 |
+
return 1.0 if ok else 0.0
|
| 79 |
+
|
| 80 |
+
def grade(answer, checks, validators=None):
|
| 81 |
+
"""Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
|
| 82 |
+
if not isinstance(answer, dict):
|
| 83 |
+
return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
|
| 84 |
+
total = sum(c.get("weight", 1.0) for c in checks)
|
| 85 |
+
got, details = 0.0, []
|
| 86 |
+
for c in checks:
|
| 87 |
+
s = run_check(answer, c, validators)
|
| 88 |
+
got += s * c.get("weight", 1.0)
|
| 89 |
+
details.append({"check": c.get("path", c.get("name")), "score": s})
|
| 90 |
+
return (round(got / total, 6) if total else 0.0), details
|
| 91 |
+
|
| 92 |
+
def main():
|
| 93 |
+
ap = argparse.ArgumentParser()
|
| 94 |
+
ap.add_argument("--answer", default="/app/answer.json")
|
| 95 |
+
ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
|
| 96 |
+
ap.add_argument("--out", default="/logs/verifier")
|
| 97 |
+
a = ap.parse_args()
|
| 98 |
+
checks = json.load(open(a.checks))
|
| 99 |
+
try:
|
| 100 |
+
with open(a.answer) as f: answer = json.load(f)
|
| 101 |
+
except Exception:
|
| 102 |
+
answer = None
|
| 103 |
+
validators = None
|
| 104 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 105 |
+
if os.path.exists(os.path.join(here, "validators.py")):
|
| 106 |
+
sys.path.insert(0, here)
|
| 107 |
+
import validators # noqa
|
| 108 |
+
reward, details = grade(answer, checks, validators)
|
| 109 |
+
os.makedirs(a.out, exist_ok=True)
|
| 110 |
+
with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
|
| 111 |
+
with open(os.path.join(a.out, "reward.json"), "w") as f:
|
| 112 |
+
json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
|
| 113 |
+
print("reward", reward)
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
main()
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0024/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY workdir/ /app/
|
tasks/swedish-proofreading/swedish-proofreading-agreement-d1-t0024/environment/workdir/documents.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"id": "D1",
|
| 4 |
+
"text": "Här finns ett tydligt stol. Alva behöver inte betala 56 kronor i dag."
|
| 5 |
+
},
|
| 6 |
+
{
|
| 7 |
+
"id": "D2",
|
| 8 |
+
"text": "Här finns ett tydligt tidning. Nora behöver inte betala 89 kronor i dag."
|
| 9 |
+
},
|
| 10 |
+
{
|
| 11 |
+
"id": "D3",
|
| 12 |
+
"text": "Här finns en tydlig brev. Nora behöver inte betala 81 kronor i dag."
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"id": "D4",
|
| 16 |
+
"text": "Här finns ett tydligt cykel. Nora behöver inte betala 17 kronor i dag."
|
| 17 |
+
},
|
| 18 |
+
{
|
| 19 |
+
"id": "D5",
|
| 20 |
+
"text": "Här finns en tydlig kvitto. Oskar behöver inte betala 53 kronor i dag."
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"id": "D6",
|
| 24 |
+
"text": "Här finns ett tydligt tidning. Mira behöver inte betala 39 kronor i dag."
|
| 25 |
+
}
|
| 26 |
+
]
|