-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdatasets_info.py
139 lines (105 loc) · 3.19 KB
/
datasets_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
"""
currently outputs:
"""
from tabulate import tabulate
import pickle
import os
import argparse
long_names = {
'kinnews': 'KinyarwandaNews',
'kirnews': 'KirundiNews',
'filipino': 'DengueFilipino',
'swahili': 'SwahiliNews',
}
def percent(f):
return "%0.1f%%" % (100.0 * f)
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'--datadir',
help = "reads files datadir/$name.pkl")
args = parser.parse_args()
indir = args.datadir
tab = []
table2 = []
for name in (
"AG_NEWS",
"DBpedia",
"YahooAnswers",
"20News",
"ohsumed",
"R8",
"R52",
'kinnews',
'kirnews',
'filipino',
'swahili',
"SogouNews",
):
print(name)
infile = os.path.join(indir,name+".pkl")
if not os.path.isfile(infile):
print("WARNING: MISSING: " + repr(infile))
continue
ds = pickle.load(open(infile,'rb'))
n_train = len(ds['train_data'])
n_test = len(ds['test_data'])
assert(ds['train_labels'].shape == (n_train,))
assert(ds['test_labels'].shape == (n_test,))
train_tuples = [(t,l) for (t,l) in zip(ds['train_data'],ds['train_labels'])]
test_tuples = [(t,l) for (t,l) in zip(ds['test_data'],ds['test_labels'])]
train_set = set(train_tuples)
test_set = set(test_tuples)
train_dups = n_train - len(train_set)
test_dups = n_test - len(test_set)
n_overlap = len(train_set.intersection(test_set))
info = {
'n_train': n_train,
'n_test' : n_test,
}
tab.append((
long_names.get(name,name),
info['n_train'],
len(train_set),
percent(train_dups / n_train),
info['n_test'],
len(test_set),
percent(test_dups / n_test),
n_overlap,
percent(n_overlap / len(test_set))
))
n = 0
for item in ds['train_data']:
n += len(item)
for item in ds['test_data']:
n += len(item)
table2.append((
long_names.get(name,name),
info['n_train'] / 1e3,
info['n_test'] / 1e3,
os.stat(infile).st_size / (2**20),
(info['n_train'] * info['n_test'] * 8) / (2**30),
n / (info['n_train'] + info['n_test']),
))
headers = [
"name",
"tr","uniq","%dup",
"te","uniq","%dup",
"tr+te",
"%",
]
print(tabulate(tab,
headers = headers))
print("")
print("")
print(tabulate(table2,
headers = [
"name",
"train(K)",
"test(K)",
"len pkl(MB)",
"len dist mat(GB)",
"ave len data",
]))
if __name__ == "__main__":
main()