File size: 565 Bytes
14fbdc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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")