norwegian-courts / build_dataset.py
kardosdrur's picture
Added dataset creation script
14fbdc9 verified
raw
history blame contribute delete
565 Bytes
import xml.etree.ElementTree as ET
from datasets import Dataset
print("Parsing alignment file.")
tree = ET.parse("./nb-nn.tmx")
records = []
pairs = tree.findall(".//tu")
for pair in pairs:
nb = pair.find("./tuv[@{http://www.w3.org/XML/1998/namespace}lang = 'nb']/seg").text
nn = pair.find("./tuv[@{http://www.w3.org/XML/1998/namespace}lang = 'nn']/seg").text
records.append(dict(nb=nb, nn=nn))
ds = Dataset.from_list(records)
ds = ds.shuffle(seed=42)
ds = ds.train_test_split(seed=42, test_size=0.2)
ds.push_to_hub("kardosdrur/norwegian-courts")