Datasets:
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") | |