Edward J. Schwartz
commited on
Commit
•
65df539
1
Parent(s):
f57ae1a
Add bylibrary
Browse files- oo-method-test-split.py +52 -5
oo-method-test-split.py
CHANGED
@@ -2,11 +2,19 @@
|
|
2 |
|
3 |
import datasets
|
4 |
|
|
|
|
|
|
|
|
|
5 |
import pyarrow as pa
|
6 |
import pyarrow.parquet as pq
|
7 |
|
8 |
BASE_DATASET = "ejschwartz/oo-method-test"
|
9 |
|
|
|
|
|
|
|
|
|
10 |
class OOMethodTestDataset(datasets.ArrowBasedBuilder):
|
11 |
|
12 |
BUILDER_CONFIGS = [
|
@@ -24,6 +32,11 @@ class OOMethodTestDataset(datasets.ArrowBasedBuilder):
|
|
24 |
name="byfuncname",
|
25 |
version=datasets.Version("1.0.0"),
|
26 |
description="Split by function name",
|
|
|
|
|
|
|
|
|
|
|
27 |
)
|
28 |
|
29 |
]
|
@@ -35,25 +48,28 @@ class OOMethodTestDataset(datasets.ArrowBasedBuilder):
|
|
35 |
return datasets.DatasetInfo()
|
36 |
|
37 |
def _split_generators(self, dl_manager):
|
38 |
-
ds = datasets.load_dataset(BASE_DATASET)
|
39 |
|
40 |
#print(files)
|
41 |
#print(downloaded_files)
|
42 |
|
|
|
|
|
|
|
43 |
if self.config.name == "combined":
|
44 |
|
45 |
return [
|
46 |
datasets.SplitGenerator(
|
47 |
name="combined",
|
48 |
gen_kwargs={
|
49 |
-
"ds": ds
|
50 |
},
|
51 |
),
|
52 |
]
|
53 |
|
54 |
elif self.config.name == "byrow":
|
55 |
|
56 |
-
ds = ds
|
57 |
#print(ds)
|
58 |
|
59 |
return [
|
@@ -74,8 +90,6 @@ class OOMethodTestDataset(datasets.ArrowBasedBuilder):
|
|
74 |
|
75 |
elif self.config.name == "byfuncname":
|
76 |
|
77 |
-
ds = ds['combined']
|
78 |
-
|
79 |
unique_names = ds.unique('Name')
|
80 |
nameds = datasets.Dataset.from_dict({'Name': unique_names})
|
81 |
|
@@ -100,6 +114,39 @@ class OOMethodTestDataset(datasets.ArrowBasedBuilder):
|
|
100 |
),
|
101 |
|
102 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
else:
|
105 |
assert False
|
|
|
2 |
|
3 |
import datasets
|
4 |
|
5 |
+
import itertools
|
6 |
+
|
7 |
+
import os
|
8 |
+
|
9 |
import pyarrow as pa
|
10 |
import pyarrow.parquet as pq
|
11 |
|
12 |
BASE_DATASET = "ejschwartz/oo-method-test"
|
13 |
|
14 |
+
def setexe(r):
|
15 |
+
r['Dirname'], r['Exename'] = os.path.split(r['Binary'])
|
16 |
+
return r
|
17 |
+
|
18 |
class OOMethodTestDataset(datasets.ArrowBasedBuilder):
|
19 |
|
20 |
BUILDER_CONFIGS = [
|
|
|
32 |
name="byfuncname",
|
33 |
version=datasets.Version("1.0.0"),
|
34 |
description="Split by function name",
|
35 |
+
),
|
36 |
+
datasets.BuilderConfig(
|
37 |
+
name="bylibrary",
|
38 |
+
version=datasets.Version("1.0.0"),
|
39 |
+
description="Split so that library functions (those appearing in >1 exe) are used for training, and non-library functions are used for testing",
|
40 |
)
|
41 |
|
42 |
]
|
|
|
48 |
return datasets.DatasetInfo()
|
49 |
|
50 |
def _split_generators(self, dl_manager):
|
51 |
+
ds = datasets.load_dataset(BASE_DATASET)['combined']
|
52 |
|
53 |
#print(files)
|
54 |
#print(downloaded_files)
|
55 |
|
56 |
+
|
57 |
+
ds = ds.map(setexe, batched=False)
|
58 |
+
|
59 |
if self.config.name == "combined":
|
60 |
|
61 |
return [
|
62 |
datasets.SplitGenerator(
|
63 |
name="combined",
|
64 |
gen_kwargs={
|
65 |
+
"ds": ds,
|
66 |
},
|
67 |
),
|
68 |
]
|
69 |
|
70 |
elif self.config.name == "byrow":
|
71 |
|
72 |
+
ds = ds.train_test_split(test_size=0.1, seed=42)
|
73 |
#print(ds)
|
74 |
|
75 |
return [
|
|
|
90 |
|
91 |
elif self.config.name == "byfuncname":
|
92 |
|
|
|
|
|
93 |
unique_names = ds.unique('Name')
|
94 |
nameds = datasets.Dataset.from_dict({'Name': unique_names})
|
95 |
|
|
|
114 |
),
|
115 |
|
116 |
]
|
117 |
+
|
118 |
+
elif self.config.name == "bylibrary":
|
119 |
+
# A function (name) is a library function if it appears in more than one Exename
|
120 |
+
|
121 |
+
# this is (('func', 'oo.exe'): 123)
|
122 |
+
testcount = set(zip(ds['Name'], ds['Exename']))
|
123 |
+
|
124 |
+
# sorted pairs by function name
|
125 |
+
testcount = sorted(testcount, key=lambda x: x[0])
|
126 |
+
|
127 |
+
# group by function name
|
128 |
+
grouped = itertools.groupby(testcount, lambda t: t[0])
|
129 |
+
|
130 |
+
grouped = {k: [b for _,b in g] for k, g in grouped}
|
131 |
+
|
132 |
+
library_func_names = {f for f, exes in grouped.items() if len(exes) > 1}
|
133 |
+
nonlibrary_func_names = {f for f, exes in grouped.items() if len(exes) == 1}
|
134 |
+
|
135 |
+
return [
|
136 |
+
datasets.SplitGenerator(
|
137 |
+
name="train",
|
138 |
+
gen_kwargs={
|
139 |
+
"ds": ds.filter(lambda r: r['Name'] in library_func_names),
|
140 |
+
},
|
141 |
+
),
|
142 |
+
datasets.SplitGenerator(
|
143 |
+
name="test",
|
144 |
+
gen_kwargs={
|
145 |
+
"ds": ds.filter(lambda r: r['Name'] in nonlibrary_func_names),
|
146 |
+
},
|
147 |
+
),
|
148 |
+
|
149 |
+
]
|
150 |
|
151 |
else:
|
152 |
assert False
|