kardosdrur commited on
Commit
14fbdc9
1 Parent(s): 3dcfa84

Added dataset creation script

Browse files
Files changed (1) hide show
  1. build_dataset.py +20 -0
build_dataset.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import xml.etree.ElementTree as ET
2
+
3
+ from datasets import Dataset
4
+
5
+ print("Parsing alignment file.")
6
+ tree = ET.parse("./nb-nn.tmx")
7
+
8
+
9
+ records = []
10
+ pairs = tree.findall(".//tu")
11
+ for pair in pairs:
12
+ nb = pair.find("./tuv[@{http://www.w3.org/XML/1998/namespace}lang = 'nb']/seg").text
13
+ nn = pair.find("./tuv[@{http://www.w3.org/XML/1998/namespace}lang = 'nn']/seg").text
14
+ records.append(dict(nb=nb, nn=nn))
15
+
16
+ ds = Dataset.from_list(records)
17
+ ds = ds.shuffle(seed=42)
18
+ ds = ds.train_test_split(seed=42, test_size=0.2)
19
+
20
+ ds.push_to_hub("kardosdrur/norwegian-courts")