|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| import numpy as np
|
| from tokenizers import Tokenizer
|
|
|
| TXT_FILE = "dataset.txt"
|
| BIN_FILE = "train.bin"
|
| TOKENIZER_PATH = "tokenizer.json"
|
|
|
| print("Загрузка токенизатора...")
|
| tokenizer = Tokenizer.from_file(TOKENIZER_PATH)
|
| eos_id = tokenizer.token_to_id("<|endoftext|>")
|
|
|
| print(f"Конвертируем {TXT_FILE} в {BIN_FILE}...")
|
|
|
| with open(BIN_FILE, 'wb') as f_out:
|
| batch_ids = []
|
|
|
| with open(TXT_FILE, 'r', encoding='utf-8') as f_in:
|
| for line in f_in:
|
| line = line.strip()
|
| if not line: continue
|
|
|
| ids = tokenizer.encode(line).ids + [eos_id]
|
| batch_ids.extend(ids)
|
|
|
| if len(batch_ids) >= 5_000_000:
|
| arr = np.array(batch_ids, dtype=np.uint16)
|
| f_out.write(arr.tobytes())
|
| batch_ids = []
|
|
|
| if batch_ids:
|
| arr = np.array(batch_ids, dtype=np.uint16)
|
| f_out.write(arr.tobytes())
|
|
|
| print("Готово!")
|
|
|