ArunKr commited on
Commit
19833fb
·
verified ·
1 Parent(s): c6714d3

Create data_prep.py

Browse files
Files changed (1) hide show
  1. data_prep.py +25 -0
data_prep.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from pathlib import Path
3
+
4
+ def chunk_text(text: str, chunk_size=500, overlap=50):
5
+ """Split text into overlapping word chunks."""
6
+ words = text.split()
7
+ for i in range(0, len(words), chunk_size - overlap):
8
+ yield " ".join(words[i:i+chunk_size])
9
+
10
+ def split_to_jsonl(input_file: str, output_file: str = "pretrain.jsonl",
11
+ chunk_size=500, overlap=50):
12
+ """Split raw file into JSONL for pretraining (no cleaning)."""
13
+ raw_text = Path(input_file).read_text(encoding="utf-8")
14
+
15
+ with open(output_file, "w", encoding="utf-8") as f:
16
+ for chunk in chunk_text(raw_text, chunk_size, overlap):
17
+ record = {"text": chunk}
18
+ f.write(json.dumps(record, ensure_ascii=False) + "\n")
19
+
20
+ print(f"✅ Saved dataset → {output_file}")
21
+
22
+ if __name__ == "__main__":
23
+ # Example usage
24
+ input_file = "gist.md" # your markdown/text file
25
+ split_to_jsonl(input_file, "pretrain.jsonl", chunk_size=500, overlap=50)