pere commited on
Commit
6514cc3
1 Parent(s): 26a7be4
create_dataset_from_tsv.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import xmltodict
3
+ from sklearn.model_selection import train_test_split
4
+ import glob
5
+ import sys
6
+ import os
7
+
8
+ filelist = glob.glob('tsv_source_target/*.tsv')
9
+
10
+ data = pd.DataFrame()
11
+
12
+ for tsvfile in filelist:
13
+ tmp = pd.read_csv(tsvfile, sep='\t')
14
+ tmp.columns=['source','target']
15
+ tmp['rev_source'] = tmp['target']
16
+ tmp['rev_target'] = tmp['source']
17
+
18
+
19
+ path = tsvfile.split("/")
20
+ source = path[1][0:3]
21
+ target = path[1][3:6]
22
+
23
+ prefix = f"{source}_{target}: "
24
+ tmp['source'] = prefix + tmp['source']
25
+
26
+ rev_prefix = f"{target}_{source}: "
27
+ tmp['rev_source'] = rev_prefix + tmp['rev_source']
28
+
29
+ data = pd.concat([data,tmp])
30
+
31
+
32
+ #Shuffle
33
+ data = data.sample(frac=1).reset_index(drop=True)
34
+
35
+ # Add both directions
36
+ original = data[['source','target']]
37
+ reverse = data[['rev_source','rev_target']]
38
+ reverse.columns=['source','target']
39
+
40
+ data = pd.concat([original,reverse])
41
+ data = data.sample(frac=1).reset_index(drop=True)
42
+
43
+ # Train - test - dev
44
+ train, test = train_test_split(data, test_size=0.2)
45
+ test, dev = train_test_split(test, test_size=0.5)
46
+
47
+ # Write the datasets to disk
48
+ train.to_csv('tsv_all_source_target/train.tsv', index=False, header=False, sep='\t')
49
+ test.to_csv('tsv_all_source_target/test.tsv', index=False, header=False, sep='\t')
50
+ dev.to_csv('tsv_all_source_target/dev.tsv', index=False, header=False, sep='\t')
51
+
52
+
53
+ print("Finished")
tmx2cvs.py → tmx2tsv.py RENAMED
File without changes
tsv_all_source_target/dev.tsv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f5de7e7fc05d9697ff9863f4846364878492e847d236c33d4e55495c66b3c2ae
3
+ size 25212526
tsv_all_source_target/test.tsv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:53096012b9e502826ee0028367316aa624d6a1b847eb255f173b09d9475af4ce
3
+ size 25054929
tsv_all_source_target/train.tsv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1f28b52818b79814f12c32e2ddf11f434e52439497a11bb8f251a89d682ac91e
3
+ size 201104421