"""ja-gen stage 1.5: encode the token store ja-kana-v1-12k (configs/ja/data-ja-kana-store.toml). Kinds (one directory each, in the zh pinyin store layout; read by vimeml.training.joint_ja_kana): plain V4 LM lines (outputs/corpus-fast-v1 {split}.txt) chat V4.1 chat utterances web ja-gen-export-v1 paragraphs not selected for reading samples (the complement of kana_samples.py's doc_hash(label/select, web/#) < fractions.web), so no web paragraph is both plain text and a reading sample -- the three plain kinds are BOS + line + EOS cut into <=128-token windows, every target supervised (first = 1) span, sentence reading samples of the lm and chat parts of kana-samples-v1 (20M) web_span, web_sentence reading samples of the web parts (200M) -- [BOS, CTX] + context + [READ] + reading + [OUT] + output + [EOS], first = the first output index; the context is cut on the left to fit 129 ids Train lines of plain and chat equal to a validation line of either are dropped. Validation reading samples are thinned by doc_hash(label/validation, source/key) < validation_fractions. Lines with U+2581 or a lossy encoding are dropped and counted. Files per kind and split: {split}.tokens.bin (= cut: continue store = prefix + sample_kind encoded = encode(sp, context, reading, output) if encoded is None: stats[f'{store}_skip_encode'] += 1 continue ids, first, removed = encoded part.add(store, ids, first) r = ids.index(5) stats[f'{store}_examples_{source}'] += 1 stats[f'{store}_tokens'] += len(ids) stats[f'{store}_output_tokens'] += len(ids) - first - 1 stats[f'{store}_reading_tokens'] += first - r - 2 stats[f'{store}_context_tokens'] += r - 2 stats[f'{store}_reading_chars'] += len(reading) stats[f'{store}_output_chars'] += len(output) stats[f'{store}_context_trimmed'] += removed > 0 part.save(Path(config['parts_dir']) / job['name']) return job['name'], job.get('source', kind), {k: len(part.lengths[k]) for k in KINDS}, dict(stats) def preview(output_dir, sp, count=20): lines = [] for kind in KINDS: d = Path(output_dir) / kind ids = np.fromfile(d / 'validation.tokens.bin', dtype='