Download Brain_O_Codebase/brain_v0_5/Datasets/Processing/chunking.py from BraegnAI/Brain-o: direct link, hf CLI and curl.
- Browser
- Download file 314 Bytes
-
https://huggingface.co/datasets/BraegnAI/Brain-o/resolve/main/Brain_O_Codebase/brain_v0_5/Datasets/Processing/chunking.py
- Command line
-
hf download hf://datasets/BraegnAI/Brain-o/Brain_O_Codebase/brain_v0_5/Datasets/Processing/chunking.py
-
curl -L -o chunking.py https://huggingface.co/datasets/BraegnAI/Brain-o/resolve/main/Brain_O_Codebase/brain_v0_5/Datasets/Processing/chunking.py
314 Bytes
| from __future__ import annotations | |
| def chunk_text(text: str, size: int = 800, overlap: int = 100) -> list[str]: | |
| if size <= 0: return [text] | |
| out, i = [], 0 | |
| while i < len(text): | |
| out.append(text[i:i+size]) | |
| if i + size >= len(text): break | |
| i += max(size - overlap, 1) | |
| return out | |