|
|
import json |
|
|
from pathlib import Path |
|
|
|
|
|
def chunk_text(text: str, chunk_size=500, overlap=50): |
|
|
"""Split text into overlapping word chunks.""" |
|
|
words = text.split() |
|
|
for i in range(0, len(words), chunk_size - overlap): |
|
|
yield " ".join(words[i:i+chunk_size]) |
|
|
|
|
|
def split_to_jsonl(input_file: str, output_file: str = "pretrain.jsonl", |
|
|
chunk_size=500, overlap=50): |
|
|
"""Split raw file into JSONL for pretraining (no cleaning).""" |
|
|
raw_text = Path(input_file).read_text(encoding="utf-8") |
|
|
|
|
|
with open(output_file, "w", encoding="utf-8") as f: |
|
|
for chunk in chunk_text(raw_text, chunk_size, overlap): |
|
|
record = {"text": chunk} |
|
|
f.write(json.dumps(record, ensure_ascii=False) + "\n") |
|
|
|
|
|
print(f"✅ Saved dataset → {output_file}") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|
|
input_file = "gist.md" |
|
|
split_to_jsonl(input_file, "pretrain.jsonl", chunk_size=500, overlap=50) |