tokenizer: без внешних зависимостей
Browse files1234345674 unmodified lines12131415161718192021222324252627282930313233343536373839404142434445465 unmodified lines52535426555628575859604 unmodified lines656667394068697044717273747576507778798081825683848586"""Обучение токенизатора PPAI с нуля: BPE 24576 на русском + английском + Python.
Почему с нуля: у PP-L свой словарь, а не расширенный от Aurora2 — так чище(нет мусорных токенов от чужой модели) и мы сами выбираем баланс ru/en/code.Словарь обучается с нуля под конкретный набор языков — так чище,нет мусорных токенов от других моделей, и баланс ru/en/code выбираем сами.
Запускается как CPU-ядро Kaggle: GPU-квоту не тратит."""4 unmodified linesimport sys
SPECIALS = ["<|pad|>", "<|bos|>", "<|eos|>"]# --- минимальный реестр источников (без внешних зависимостей) ---SOURCES = { "ru_wiki": dict(hf="wikimedia/wikipedia", config="20231101.ru", split="train", cols=["text"]), "ru_web": dict(hf="HuggingFaceFW/fineweb-2", config="rus_Cyrl", split="train", cols=["text"]), "ru_c4": dict(hf="allenai/c4", config="ru", split="train", cols=["text"]), "en_web": dict(hf="HuggingFaceFW/fineweb-edu", config="sample-10BT", split="train", cols=["text"]), "code_python": dict(hf="codeparrot/codeparrot-clean", split="train", cols=["content"]),}
def load_stream(name: str, token: str | None = None): from datasets import load_dataset
spec = SOURCES[name] kw = dict(split=spec.get("split", "train"), streaming=True) if token: kw["token"] = token if spec.get("config"): kw["name"] = spec["config"] return load_dataset(spec["hf"], **kw)
def format_doc(name: str, ex: dict, spec: dict) -> str | None: for col in spec.get("cols", []): v = ex.get(col) if isinstance(v, str) and v.strip(): return v return None
OUT_DIR = os.environ.get("PPAI_TOK_OUT", "/kaggle/working/ppai_tok")REPO = os.environ.get("PPAI_TOK_REPO", "AdminHugging/PP-Hydrogen")
5 unmodified lines
def find_pkg() -> str: for root, _dirs, files in os.walk("/kaggle/input"): if "kernel_common.py" in files: if "train_tokenizer.py" in files: return root raise SystemExit("нет пакета aurora_train в /kaggle/input") raise SystemExit("нет каталога ppai в /kaggle/input")
def find_token() -> str:4 unmodified lines
def collect_texts(pkg: str, token: str | None): sys.path.insert(0, pkg) from aurora_train import data as dm
per_source = {k: int(TOTAL_CHARS * v) for k, v in SAMPLE.items()} for name, budget in per_source.items(): spec = dm.SOURCES.get(name) spec = SOURCES.get(name) if spec is None: print(f"[tok] нет источника {name}, пропуск") continue got = 0 try: stream = dm.load_stream(name, token) stream = load_stream(name, token) except Exception as exc: # noqa: BLE001 print(f"[tok] {name}: недоступен — {str(exc).splitlines()[0][:100]}") continue print(f"[tok] {name}: цель {budget/1e6:.1f}M символов", flush=True) for ex in stream: text = dm.format_doc(name, ex, spec) text = format_doc(name, ex, spec) if not text or len(text) < 200: continue yield textppai/train_tokenizer.py+36-9