Datasets:
Tasks:
Translation
Modalities:
Text
Formats:
json
Languages:
English
Size:
10K - 100K
Tags:
code
License:
Simon Strandgaard
commited on
Commit
•
60611b4
1
Parent(s):
a823519
Removed python files
Browse files- generate_dataset.py +0 -104
- random_data.py +0 -11
- test_random_data.py +0 -21
generate_dataset.py
DELETED
@@ -1,104 +0,0 @@
|
|
1 |
-
from random_data import generate_random_byte_array
|
2 |
-
import json
|
3 |
-
import os
|
4 |
-
import random
|
5 |
-
import base64
|
6 |
-
|
7 |
-
def base64_encode_byte_array(byte_array):
|
8 |
-
return base64.b64encode(byte_array).decode('utf-8')
|
9 |
-
|
10 |
-
def generate_dataset_item(seed):
|
11 |
-
length = random.Random(seed + 1000).randint(0, 127)
|
12 |
-
byte_array = generate_random_byte_array(length=length, seed=seed + 1001)
|
13 |
-
|
14 |
-
output_formats = [
|
15 |
-
'hex',
|
16 |
-
'json'
|
17 |
-
]
|
18 |
-
output_format = random.Random(seed + 1002).choice(output_formats)
|
19 |
-
|
20 |
-
names_hex = [
|
21 |
-
'Hexadecimal',
|
22 |
-
'hexadecimal',
|
23 |
-
'hex',
|
24 |
-
'Hex',
|
25 |
-
'HEX',
|
26 |
-
]
|
27 |
-
names_json = [
|
28 |
-
'Json',
|
29 |
-
'json',
|
30 |
-
'JSON',
|
31 |
-
]
|
32 |
-
|
33 |
-
name_output = None
|
34 |
-
if output_format == 'hex':
|
35 |
-
name_output = random.Random(seed + 1003).choice(names_hex)
|
36 |
-
else:
|
37 |
-
if output_format == 'json':
|
38 |
-
name_output = random.Random(seed + 1004).choice(names_json)
|
39 |
-
|
40 |
-
name_inputs = [
|
41 |
-
'base64',
|
42 |
-
'Base64',
|
43 |
-
'BASE64',
|
44 |
-
]
|
45 |
-
name_input = random.Random(seed + 1005).choice(name_inputs)
|
46 |
-
|
47 |
-
instructions = [
|
48 |
-
f'Decode {name_input} to {name_output}',
|
49 |
-
f'decode {name_input} to {name_output}',
|
50 |
-
f'convert {name_input} to {name_output}',
|
51 |
-
f'Convert {name_input} to {name_output}',
|
52 |
-
f'Transform {name_input} to {name_output}',
|
53 |
-
f'transform {name_input} to {name_output}',
|
54 |
-
f'Change {name_input} to {name_output}',
|
55 |
-
f'change {name_input} to {name_output}',
|
56 |
-
f'{name_input} to {name_output}',
|
57 |
-
f'{name_output} from {name_input}',
|
58 |
-
]
|
59 |
-
|
60 |
-
instruction = random.Random(seed + 1006).choice(instructions)
|
61 |
-
|
62 |
-
input = base64_encode_byte_array(byte_array)
|
63 |
-
|
64 |
-
output = None
|
65 |
-
if output_format == 'hex':
|
66 |
-
output = byte_array.hex()
|
67 |
-
else:
|
68 |
-
if output_format == 'json':
|
69 |
-
output = json.dumps(list(byte_array), separators=(',', ':'))
|
70 |
-
|
71 |
-
dict = {
|
72 |
-
'instruction': instruction,
|
73 |
-
'input': input,
|
74 |
-
'output': output
|
75 |
-
}
|
76 |
-
return dict
|
77 |
-
|
78 |
-
def generate_dataset(max_num_samples=1000, max_byte_size=1024*1024, seed_start=0):
|
79 |
-
dataset = []
|
80 |
-
dataset_byte_size = 0
|
81 |
-
for i in range(max_num_samples):
|
82 |
-
item = generate_dataset_item(seed_start + i)
|
83 |
-
bytes = len(json.dumps(item))
|
84 |
-
if dataset_byte_size + bytes > max_byte_size:
|
85 |
-
break
|
86 |
-
dataset_byte_size += bytes
|
87 |
-
dataset.append(item)
|
88 |
-
return dataset
|
89 |
-
|
90 |
-
dataset = generate_dataset(
|
91 |
-
max_num_samples=50000,
|
92 |
-
max_byte_size=1024*1024*20,
|
93 |
-
)
|
94 |
-
|
95 |
-
# Save dataset to file
|
96 |
-
filename = 'data.jsonl'
|
97 |
-
with open(filename, 'w') as f:
|
98 |
-
for item in dataset:
|
99 |
-
f.write(json.dumps(item) + '\n')
|
100 |
-
|
101 |
-
# Summary
|
102 |
-
file_size = os.path.getsize(filename)
|
103 |
-
print(f"Generated {len(dataset)} samples, saved to {filename}, file size: {file_size} bytes.")
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
random_data.py
DELETED
@@ -1,11 +0,0 @@
|
|
1 |
-
import random
|
2 |
-
|
3 |
-
def generate_random_byte_array(length, seed):
|
4 |
-
random.seed(seed)
|
5 |
-
return bytearray(random.randint(0, 255) for _ in range(length))
|
6 |
-
|
7 |
-
if __name__ == "__main__":
|
8 |
-
length = 10
|
9 |
-
seed = 42
|
10 |
-
byte_array = generate_random_byte_array(length, seed)
|
11 |
-
print(byte_array)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test_random_data.py
DELETED
@@ -1,21 +0,0 @@
|
|
1 |
-
import unittest
|
2 |
-
from random_data import generate_random_byte_array
|
3 |
-
|
4 |
-
class TestRandomData(unittest.TestCase):
|
5 |
-
def test_generate_random_byte_array_empty(self):
|
6 |
-
actual = generate_random_byte_array(length=0, seed=0)
|
7 |
-
expected = bytearray()
|
8 |
-
self.assertEqual(actual, expected)
|
9 |
-
|
10 |
-
def test_generate_random_byte_array_length1(self):
|
11 |
-
actual = generate_random_byte_array(length=1, seed=0)
|
12 |
-
expected = bytearray([0xc5])
|
13 |
-
self.assertEqual(actual, expected)
|
14 |
-
|
15 |
-
def test_generate_random_byte_array_length2(self):
|
16 |
-
actual = generate_random_byte_array(length=2, seed=0)
|
17 |
-
expected = bytearray([0xc5, 0xd7])
|
18 |
-
self.assertEqual(actual, expected)
|
19 |
-
|
20 |
-
if __name__ == '__main__':
|
21 |
-
unittest.main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|