Tonic commited on
Commit
3c104db
·
1 Parent(s): 361c2c7

Delete selectbylines.py

Browse files
Files changed (1) hide show
  1. selectbylines.py +0 -32
selectbylines.py DELETED
@@ -1,32 +0,0 @@
1
- import os
2
- import random
3
-
4
- # Directory containing the shard JSONL files
5
- shard_directory = "/path/to/shard/directory"
6
-
7
- # Get a list of all JSONL files in the directory
8
- shard_files = [f for f in os.listdir(shard_directory) if f.endswith('.jsonl')]
9
-
10
- # Function to read a random number of lines (between min_lines and max_lines) from a file
11
- def read_random_lines(filename, min_lines, max_lines):
12
- selected_lines = []
13
- num_lines = random.randint(min_lines, max_lines)
14
-
15
- with open(filename, 'r') as file:
16
- lines = list(file)
17
- if len(lines) <= num_lines:
18
- return lines
19
- selected_lines = random.sample(lines, num_lines)
20
-
21
- return selected_lines
22
-
23
- # Function to combine shards
24
- def combine_shards(output_filename, num_combinations):
25
- with open(output_filename, 'w') as output_file:
26
- for _ in range(num_combinations):
27
- selected_shard_file = random.choice(shard_files)
28
- lines = read_random_lines(os.path.join(shard_directory, selected_shard_file), 5000, 10000)
29
- output_file.writelines(lines)
30
-
31
- # Example usage
32
- combine_shards("/path/to/output/combined_shards.jsonl", 10)