-
Notifications
You must be signed in to change notification settings - Fork 3
/
prepare_redpajama_chunks.py
43 lines (34 loc) · 1.29 KB
/
prepare_redpajama_chunks.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
import os
import fire
import json
import tqdm
from datasets import load_dataset
os.environ["RED_PAJAMA_DATA_DIR"] = "/lustre/home/bowen.tan/dataset_cache/redpajama"
REDPAJAME_SUBSETS = ['arxiv', 'book', 'c4', 'stackexchange', 'wikipedia']
OUTPUT_DIR = '/lustre/scratch/shared-folders/llm_project/bowen.tan/chunked_datasets'
CHUNK_WORD_SIZE = 10 ** 9
def main():
for subset_name in REDPAJAME_SUBSETS:
subset_dir = f'{OUTPUT_DIR}/redpajama.{subset_name}'
if os.path.exists(subset_dir):
print(f'{subset_dir} exists. skiped.')
continue
else:
os.makedirs(subset_dir)
dataset = load_dataset(
'togethercomputer/RedPajama-Data-1T',
name=subset_name,
split='train',
streaming=True)
file_idx = 0
output_file = open(f'{subset_dir}/{file_idx}.jsonl', 'w')
n_chunk_words = 0
for example in tqdm.tqdm(dataset, desc=subset_dir):
output_file.write(json.dumps(example) + '\n')
n_chunk_words += len(example['text'].split())
if n_chunk_words >= CHUNK_WORD_SIZE:
file_idx += 1
output_file = open(f'{subset_dir}/{file_idx}.jsonl', 'w')
n_chunk_words = 0
if __name__ == '__main__':
fire.Fire(main)