Skip to main content

himotoki-split

Lightweight split-only Japanese tokenizer distilled from Himotoki.

Himotoki is a full morphological analyzer (dictionary + conjugations + meanings, ~1.8 GB DB).
himotoki-split is a separate product: a tiny boundary model that approximates Himotoki’s word splits for users who only need segmentation.

Himotoki himotoki-split
Output words + readings + POS + meanings surface splits only
Footprint ~1.8 GB SQLite ~KB–MB model
Accuracy gold / dictionary approximates teacher
Fallback optional Himotoki on low confidence

Install

pip install -e .
pip install -e ".[train]"      # linear student training
pip install -e ".[teacher]"    # Himotoki dump / fallback (needs DB)
pip install -e ".[neural]"     # BiLSTM train + ONNX export
pip install -e ".[onnx]"       # ONNX runtime only

Usage

from himotoki_split import split

result = split("学校で勉強しています")
print(result.segments)
print(result.confidence, result.source)
himotoki-split "猫が食べる"
himotoki-split --json "猫が食べる"

split() prefers packaged default.onnx when onnxruntime is installed, otherwise default.npz.
Default hybrid fallback threshold is min_confidence=0.96 (Phase B calibration).

Demo UI (FastAPI)

Interactive playground + active query (surfaces low-confidence pool sentences for Accept / Correct feedback):

pip install -e ".[demo]"
python -m demo.app
# → http://127.0.0.1:8765
# → http://127.0.0.1:8765/walkthrough   beginner canvas (repo / eval / training)

Markdown twin: docs/WALKTHROUGH.md.

Feedback is appended to demo/data/feedback.jsonl (gitignored). The active-query pool defaults to data/labels/holdout_clean.jsonl when present, or demo/data/pool.jsonl.

Tatoeba / JMdict path

Cleaner example sentences from Tatoeba, with optional JMdict-linked indices as labels — see docs/TATOEBA.md:

python scripts/tatoeba_indices_to_labels.py --download -o data/labels/tatoeba_indices.jsonl
python scripts/build_tatoeba_corpus.py --download --target 200000 -o data/corpus/tatoeba_sentences.txt

Shipped models: default = CRF mixed + Phase G wiki specialist + router (wiki clean ≈47%, Tatoeba ≈72%, avg ≈0.596). See docs/PHASE_G.md.

Active-query retrain (batch)

Agent/oracle loop over uncertain train examples (holdout stays frozen):

export HIMOTOKI_DB_PATH=~/.himotoki/himotoki.db
python scripts/active_query_train.py --sample-n 8000 --query-k 500 --upsample 5 --epochs 6 --train
python scripts/eval_model.py -m himotoki_split/models/default.onnx \
  -i data/labels/holdout.jsonl --clean data/labels/holdout_clean.jsonl

Scale silver labels (Wikipedia → Himotoki → train)

Large dumps stay local (gitignored). Wikipedia text is CC BY-SA.

Phase A — 100k sentences + linear student

# 1) Build cleaned sentence list (streams dump until --target)
python scripts/build_corpus.py --download --target 100000 -o data/corpus/sentences.txt
# or: python scripts/build_corpus.py --dump /path/to/jawiki-latest-pages-articles.xml.bz2 --target 100000

# 2) Shard for parallel labeling
python scripts/shard_corpus.py -i data/corpus/sentences.txt -o data/corpus/shards --num-shards 8

# 3) Dump Himotoki silver labels (requires Himotoki + DB; hours on one CPU)
for i in $(seq 0 7); do
  python scripts/dump_labels.py \
    -i data/corpus/sentences.txt \
    -o data/labels/shards/part-$(printf '%03d' $i).jsonl \
    --shard-id $i --num-shards 8 --resume &
done
wait

# 4) Merge + freeze 5k holdout
python scripts/merge_labels.py -i data/labels/shards/*.jsonl \
  --train-out data/labels/train.jsonl --holdout-out data/labels/holdout.jsonl

# 5) Train linear model + eval
python scripts/train.py -i data/labels/train.jsonl -o himotoki_split/models/default.npz
python scripts/eval_model.py -m himotoki_split/models/default.npz -i data/labels/holdout.jsonl

Rough cost: wiki extract is large (multi-GB download if using full articles dump); labeling ~20–100 ms/sentence ⇒ 100k ≈ a few hours single-threaded (faster with shards).

Phase B — full-data neural ONNX student

Trained BiLSTM on the full ~95k silver train set (6 epochs, CPU) and shipped default.onnx.

# Train ONNX student on full train.jsonl
python scripts/train_neural.py -i data/labels/train.jsonl \
  -o himotoki_split/models/default.onnx --epochs 6 --batch-size 64 --device cpu

# Clean eval slice + dual metrics
python scripts/make_clean_eval.py
python scripts/eval_phase_b.py

# Calibrate hybrid fallback (needs Himotoki DB)
python scripts/calibrate_fallback.py -m himotoki_split/models/default.onnx

Holdout results (frozen 5k wiki silver):

Backend Boundary F1 Exact-seg
Linear default.npz (30k subset) 0.917 10.6%
ONNX default.onnx (full 95k) 0.970 41.9%

Clean slice (800 sentences): ONNX F1 0.972, exact-seg 45.3%.

Hybrid fallback at min_confidence=0.96: exact-seg 48.2% with ~14% Himotoki calls.

Phase C — soft-launch (v0.2.0)

Packaging polish for a public soft-launch:

# Retrain zero-deps linear student on full train (optional; already shipped)
python scripts/train.py -i data/labels/train.jsonl -o himotoki_split/models/default.npz

# Latency microbench (clean-100 sample)
python scripts/bench_latency.py

# Build + smoke
pip install build twine
python -m build && twine check dist/*

Latency (100 clean sentences, CPU): ONNX ≈ 0.34 ms/sent (~3k sent/s); linear ≈ 2.4 ms/sent; split() API ≈ 0.61 ms/sent.

Linear full-95k retrain landed at similar holdout F1 to the Phase A 30k model (~0.917) — capacity-limited; prefer ONNX for quality.

See CHANGELOG.md and PUBLISH.md for release steps (TestPyPI/PyPI).

Optional later growth (append-only train, freeze holdout):

python scripts/build_corpus.py --download --target 500000 -o data/corpus/sentences.txt
# ... dump shards ...
python scripts/merge_labels.py -i data/labels/shards/*.jsonl \
  --freeze-holdout data/labels/holdout.jsonl \
  --train-out data/labels/train.jsonl --holdout-out data/labels/holdout.jsonl
python scripts/train_neural.py -i data/labels/train.jsonl -o himotoki_split/models/default.onnx

Small-scale distill (existing)

python scripts/dump_labels.py -i data/sample_sentences.txt -o data/labels.jsonl
python scripts/train.py -i data/labels.jsonl -o himotoki_split/models/default.npz

Large artifacts (data/corpus/, data/labels/train.jsonl, wiki dumps) are gitignored.
data/labels/holdout_clean.jsonl is kept in-repo for reproducible clean eval.

Design

  • Teacher: Himotoki analyze top path → {text, segments} JSONL
  • Student (default runtime): char BiLSTM → ONNX (default.onnx) when onnxruntime is available
  • Student (zero-deps fallback): logistic + Viterbi (default.npz, numpy)
  • Fallback: low-confidence → Himotoki if installed (min_confidence=0.96)

Relationship to Himotoki

Separate repository on purpose. Himotoki remains the accurate analyzer and training teacher.

License

MIT — see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

himotoki_split-0.2.9.tar.gz (10.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

himotoki_split-0.2.9-py3-none-any.whl (10.8 MB view details)

Uploaded Python 3

File details

Details for the file himotoki_split-0.2.9.tar.gz.

File metadata

  • Download URL: himotoki_split-0.2.9.tar.gz
  • Upload date:
  • Size: 10.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for himotoki_split-0.2.9.tar.gz
Algorithm Hash digest
SHA256 580e66950c42d64c319f19cb9e001994cfa81c45afb0c0c1905d4c29cca043c0
MD5 a89c5b1da62c1707aa438f8bfb74266e
BLAKE2b-256 a92546e06f01b90aaba7a7effafe686184a759b71c5e9632922b92dc78dea6cf

See more details on using hashes here.

File details

Details for the file himotoki_split-0.2.9-py3-none-any.whl.

File metadata

  • Download URL: himotoki_split-0.2.9-py3-none-any.whl
  • Upload date:
  • Size: 10.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for himotoki_split-0.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 38417c67ca5528a47bc6a822ecd8798d88c42c605a5103b844d4b36715541d5d
MD5 bcd557c93a498313b451e45acd12d2c6
BLAKE2b-256 dce7cbe6529566b61394296461d51d3f7b1bb4757095d0343aef0f77dd2fd00d

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.12

2 files

0.2.11

2 files

This release

0.2.9 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page