[GH-ISSUE #6161] [Feature]: Improve token estimation and token count display for CJK text #3433

Closed
opened 2026-10-21 06:03:03 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @minikkeuen on GitHub (Sep 13, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6161

Originally assigned to: @SpicyMarinara on GitHub.

What problem does this solve?

Marinara uses lightweight character-based token estimation in several places.

The existing heuristic works reasonably well as a rough estimate for English text, but can significantly underestimate Korean, Japanese, and Chinese text because CJK text has different tokenization characteristics.

Token count displays are also inconsistent across prompt and context inputs. Some fields show character counts, some show estimated token counts, and some relevant prompt fields show no count at all.

This makes it harder to estimate prompt and context size consistently, especially when working with CJK-heavy text.

Proposed solution

Improve the existing lightweight token estimator while keeping it simple and model-agnostic:

  • Use approximate CJK-aware weighting for Hangul, Han characters, and Hiragana/Katakana.
  • Preserve the existing lightweight estimation behavior for other text.

Also use the shared token estimator more consistently across relevant prompt and context input fields:

  • Replace existing character-only counts with estimated token counts where appropriate.
  • Add estimated token counts to relevant prompt/context fields that currently have no size indicator.
  • Reuse the shared estimator rather than implementing separate counting logic in individual UI components.

The estimates are intentionally approximate and are not intended to reproduce any specific model's tokenizer.

Alternatives considered

  • Using an actual tokenizer, which would be more accurate but add complexity and remain tokenizer/model-specific.
  • Provider/model-specific estimation, which could improve accuracy but would significantly increase implementation complexity.
  • Keeping character counts for prompt fields, which is simpler but is less useful for understanding LLM context usage and particularly misleading for CJK text.

Additional context

The implementation is split into two commits: one for the lightweight CJK-aware estimator and one for the prompt/context token count UI changes.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @minikkeuen on GitHub (Sep 13, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6161 Originally assigned to: @SpicyMarinara on GitHub. ## What problem does this solve? Marinara uses lightweight character-based token estimation in several places. The existing heuristic works reasonably well as a rough estimate for English text, but can significantly underestimate Korean, Japanese, and Chinese text because CJK text has different tokenization characteristics. Token count displays are also inconsistent across prompt and context inputs. Some fields show character counts, some show estimated token counts, and some relevant prompt fields show no count at all. This makes it harder to estimate prompt and context size consistently, especially when working with CJK-heavy text. ## Proposed solution Improve the existing lightweight token estimator while keeping it simple and model-agnostic: - Use approximate CJK-aware weighting for Hangul, Han characters, and Hiragana/Katakana. - Preserve the existing lightweight estimation behavior for other text. Also use the shared token estimator more consistently across relevant prompt and context input fields: - Replace existing character-only counts with estimated token counts where appropriate. - Add estimated token counts to relevant prompt/context fields that currently have no size indicator. - Reuse the shared estimator rather than implementing separate counting logic in individual UI components. The estimates are intentionally approximate and are not intended to reproduce any specific model's tokenizer. ## Alternatives considered - Using an actual tokenizer, which would be more accurate but add complexity and remain tokenizer/model-specific. - Provider/model-specific estimation, which could improve accuracy but would significantly increase implementation complexity. - Keeping character counts for prompt fields, which is simpler but is less useful for understanding LLM context usage and particularly misleading for CJK text. ## Additional context The implementation is split into two commits: one for the lightweight CJK-aware estimator and one for the prompt/context token count UI changes. ## Template check - [ ] I DID NOT read this template and provide the requested details.
Author
Owner

@SpicyMarinara commented on GitHub (Sep 13, 2026):

Maintainer follow-up: Codex is applying and validating the review fixes in the existing PR #6164 on behalf of @SpicyMarinara, preserving the contributor’s implementation and commits. This continues the existing PR; no duplicate implementation branch or PR is being opened.

<!-- gh-comment-id:5654311691 --> @SpicyMarinara commented on GitHub (Sep 13, 2026): Maintainer follow-up: Codex is applying and validating the review fixes in the existing PR #6164 on behalf of @SpicyMarinara, preserving the contributor’s implementation and commits. This continues the existing PR; no duplicate implementation branch or PR is being opened.
Author
Owner

@SpicyMarinara commented on GitHub (Sep 13, 2026):

Addressed by PR #6164, merged into staging at 67e5a486. The contributor’s CJK estimator and counter changes are preserved with the review fixes. All required checks, 266 Node regressions, the full browser matrix, and CodeRabbit completed successfully.

<!-- gh-comment-id:5654730794 --> @SpicyMarinara commented on GitHub (Sep 13, 2026): Addressed by PR #6164, merged into staging at 67e5a486. The contributor’s CJK estimator and counter changes are preserved with the review fixes. All required checks, 266 Node regressions, the full browser matrix, and CodeRabbit completed successfully.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#3433
No description provided.