Download data_prep.py from ArunKr/manim-docs-gitingest: direct link, hf CLI and curl.
- Browser
- Download file 976 Bytes
-
https://huggingface.co/datasets/ArunKr/manim-docs-gitingest/resolve/main/data_prep.py
- Command line
-
hf download hf://datasets/ArunKr/manim-docs-gitingest/data_prep.py
-
curl -L -o data_prep.py https://huggingface.co/datasets/ArunKr/manim-docs-gitingest/resolve/main/data_prep.py
976 Bytes
| 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__": | |
| # Example usage | |
| input_file = "gist.md" # your markdown/text file | |
| split_to_jsonl(input_file, "pretrain.jsonl", chunk_size=500, overlap=50) |