Neetree commited on
Commit
d3b867c
·
verified ·
1 Parent(s): d4077e9

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +170 -0
README.md ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pretty_name: "LittleTzu FineWeb-Edu Tokenized (Custom 65k Balanced)"
3
+ language:
4
+ - en
5
+ - zh
6
+ - ja
7
+ - ko
8
+ - it
9
+ - es
10
+ - de
11
+ license: other
12
+ task_categories:
13
+ - text-generation
14
+ tags:
15
+ - pretraining
16
+ - tokenized
17
+ - fineweb-edu
18
+ - numpy
19
+ - custom-tokenizer
20
+ - bpe
21
+ size_categories:
22
+ - 10B<n<100B
23
+ ---
24
+
25
+ # LittleTzu FineWeb-Edu Tokenized (Custom 65k Balanced)
26
+
27
+ Tokenized shards of **FineWeb-Edu** (`HuggingFaceFW/fineweb-edu`, config: `sample-10BT`) for language model pretraining.
28
+
29
+ This dataset stores a derived, tokenized representation of the original FineWeb-Edu corpus. It has been tokenized using **LittleTzu's custom 65K balanced tokenizer**, optimized for multi-domain training (English, multilingual text, math, and code) while maintaining a compact vocabulary footprint that fits within a `uint16` data type.
30
+
31
+ ## Dataset Structure
32
+
33
+ The dataset consists of flat 1D NumPy binary shards (`.npy` files) serialized in `uint16` format:
34
+ - `edufineweb_val_000000.npy` (Validation set: first shard, containing exactly 100M tokens)
35
+ - `edufineweb_train_000001.npy`
36
+ - `edufineweb_train_000002.npy`
37
+ - ...
38
+ - `edufineweb_train_000099.npy`
39
+
40
+ Each shard contains exactly **100,000,000** (100M) tokens. Shards are created by tokenizing raw documents from the source, prefixing/delimiting each document with the `<|eos|>` token, and packing them into contiguous 100M token arrays.
41
+
42
+ ## Custom Tokenizer: `tokenizer_65k_balanced`
43
+
44
+ To overcome the vocabulary size overhead of tokenizers like OpenAI's `cl100k_base` (100k vocab) or Llama 3 (128k vocab) when training smaller models (~124M to 500M parameters), we trained a custom **Byte-Level BPE tokenizer** with a vocabulary size of **65,536**.
45
+
46
+ ### Tokenizer Configuration
47
+ - **Model Type**: Byte-Level BPE (Byte Pair Encoding)
48
+ - **Vocabulary Size**: 65,536 (fits natively in `uint16` arrays, saving 50% memory/storage overhead during loading compared to standard `uint32` or `int32`/`int64` loaders!)
49
+ - **Pre-tokenization**:
50
+ - `ByteLevel(add_prefix_space=False)`
51
+ - `Digits(individual_digits=True)` — Splits digits individually (e.g. `123` becomes `1`, `2`, `3`) to prevent the vocabulary from being bloated with random numbers and to ensure stable mathematical tokenization.
52
+ - **Special & Control Tokens**:
53
+ - Standard: `<|pad|>`, `<|bos|>`, `<|eos|>`, `<|unk|>`, `<|sep|>`
54
+ - Chat Format: `<|im_start|>`, `<|im_end|>`
55
+ - Reserved: 50 reserved placeholders (`<|reserved_0|>` to `<|reserved_49|>`) for future-proofing and custom special tokens.
56
+
57
+ ### Training Mixture (Balanced Corpus)
58
+ To ensure the tokenizer remains highly efficient across various domains despite its compact vocabulary, it was trained on a balanced 5,000,000 document subset spanning the following domains:
59
+ 1. **English (General & Educational)**: `HuggingFaceFW/fineweb-edu` (25%)
60
+ 2. **Multilingual Chinese**: `epfml/FineWeb2-HQ` (`cmn_Hani` config) (20%)
61
+ 3. **Multilingual Italian**: `HuggingFaceFW/fineweb-2` (`ita_Latn` config) (15%)
62
+ 4. **Math / Scientific**: `open-web-math/open-web-math` (15%)
63
+ 5. **Multilingual Japanese**: `epfml/FineWeb2-HQ` (`jpn_Jpan` config) (10%)
64
+ 6. **Code (Programming)**: `bigcode/the-stack-v2-train-smol` (10%)
65
+ 7. **Multilingual Korean**: `HuggingFaceFW/fineweb-2` (`kor_Hang` config) (5%)
66
+
67
+ ### Tokenization Compression Efficiency (Chars/Token)
68
+ The balanced training corpus ensures the custom tokenizer compresses multilingual text and code far more efficiently than general-purpose English tokenizers, even with 35% fewer vocabulary dimensions:
69
+
70
+ | Language / Domain | Custom 65k (chars/token) | OpenAI cl100k_base (chars/token) | Relative Efficiency |
71
+ |---|---|---|---|
72
+ | **English** | 5.13 | 5.13 | **Parity** (1.00x) |
73
+ | **Italian** | 5.19 | 3.59 | **+44.5%** (1.44x) |
74
+ | **Korean** | 1.71 | 1.09 | **+56.8%** (1.57x) |
75
+ | **Japanese** | 1.38 | 0.85 | **+62.3%** (1.62x) |
76
+ | **Chinese** | 1.20 | 0.94 | **+27.6%** (1.28x) |
77
+ | **Python Code** | 2.35 | 2.94 | -20.0% (0.80x) |
78
+
79
+ *By optimizing for multi-domain text, each sequence packed into the model context carries denser semantic information, speeding up pre-training convergence on multilingual benchmarks.*
80
+
81
+ ## Data Preparation & Preprocessing
82
+
83
+ This dataset was tokenized and sharded via a parallelized processing script (`fineweb.py`) which:
84
+ 1. Streams documents from the original `HuggingFaceFW/fineweb-edu` (`sample-10BT`) dataset.
85
+ 2. Tokenizes document text using the `tokenizer_65k_balanced.json` model.
86
+ 3. Prepends the `<|eos|>` token to every document.
87
+ 4. Packs token streams into contiguous `1D` NumPy array buffers of size `100,000,000`.
88
+ 5. Casts and saves each shard as `np.uint16` to a local directory or uploads to Hugging Face.
89
+
90
+ ## How to Load and Stream
91
+
92
+ You can download and stream these tokenized shards using the Hugging Face Hub snapshot API or load them directly into your dataset loaders.
93
+
94
+ ### 1. Download Shards
95
+ ```python
96
+ from huggingface_hub import snapshot_download
97
+
98
+ snapshot_download(
99
+ repo_id="Neetree/fineweb10B-tokenized", # Replace with your repo name
100
+ repo_type="dataset",
101
+ local_dir="data/edu_fineweb10B",
102
+ allow_patterns="*.npy",
103
+ )
104
+ ```
105
+
106
+ ### 2. PyTorch DataLoader Example
107
+ Here is how you can implement an efficient, lightweight streaming dataloader using `np.load`:
108
+
109
+ ```python
110
+ import os
111
+ import numpy as np
112
+ import torch
113
+
114
+ class ShardDataLoader:
115
+ def __init__(self, data_dir, batch_size, seq_len, split="train"):
116
+ self.B = batch_size
117
+ self.T = seq_len
118
+ self.shards = sorted([os.path.join(data_dir, f) for f in os.listdir(data_dir) if split in f])
119
+ assert len(self.shards) > 0, f"No shards found for split: {split}"
120
+
121
+ self.current_shard_idx = 0
122
+ self._load_shard()
123
+
124
+ def _load_shard(self):
125
+ shard_path = self.shards[self.current_shard_idx]
126
+ # Memory-map the file to prevent loading the entire 100M array into RAM at once
127
+ self.tokens = np.load(shard_path, mmap_mode="r")
128
+ self.current_pos = 0
129
+
130
+ def next_batch(self):
131
+ B, T = self.B, self.T
132
+ # We need B * T + 1 tokens to construct input (X) and target (Y)
133
+ needed = B * T + 1
134
+
135
+ if self.current_pos + needed > len(self.tokens):
136
+ # Advance to the next shard
137
+ self.current_shard_idx = (self.current_shard_idx + 1) % len(self.shards)
138
+ self._load_shard()
139
+
140
+ buf = self.tokens[self.current_pos : self.current_pos + needed]
141
+ self.current_pos += B * T
142
+
143
+ # Convert uint16 array to torch.long for embedding layer lookup
144
+ tensor = torch.from_numpy(buf.astype(np.int64))
145
+ x = tensor[:-1].view(B, T)
146
+ y = tensor[1:].view(B, T)
147
+
148
+ return x, y
149
+ ```
150
+
151
+ ## Intended Use
152
+
153
+ - Large-scale causal language model pretraining.
154
+ - Benchmarking dataloading pipelines.
155
+ - Lightweight and budget-friendly model training baseline (compatible with LittleTzu training configs).
156
+
157
+ ## Citation & Original Dataset
158
+
159
+ Original dataset is FineWeb-Edu by Hugging Face:
160
+ ```bibtex
161
+ @misc{HuggingFaceFW_fineweb-edu,
162
+ author = {Hugging Face FineWeb Team},
163
+ title = {FineWeb-Edu: Finest educational web data for LM pretraining},
164
+ year = {2024},
165
+ publisher = {Hugging Face},
166
+ journal = {Hugging Face Dataset},
167
+ howpublished = {\url{https://huggingface.co/datasets/HuggingFaceFW/fineweb-edu}}
168
+ }
169
+ ```
170
+ If you use this sharded/tokenized representation, please cite the original creators of the FineWeb-Edu dataset.