File size: 640 Bytes
d68916b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#!/usr/bin/env python
# sacrebleu format to jsonlines
import io
import json
import re
src_lang, tgt_lang = ["en", "ro"]
for split in ["train", "val", "test"]:
recs = []
fout = f"{split}.json"
with io.open(fout, "w", encoding="utf-8") as f:
for type in ["source", "target"]:
fin = f"{split}.{type}"
recs.append([line.strip() for line in open(fin)])
for src, tgt in zip(*recs):
out = {"translation": { src_lang: src, tgt_lang: tgt } }
x = json.dumps(out, indent=0, ensure_ascii=False)
x = re.sub(r'\n', ' ', x, 0, re.M)
f.write(x + "\n")
|