Skip to content

Main content

Token Byte Character Ratio Tool

Compare portable UTF-8 bytes to code points; isolated surrogates use replacement encoding.

Loading tool…

Description

Return UTF-8 bytes per Unicode code point for one token.

Language-processing records depend on tokenization, indexing, null sentinels and text representation. A UTF-8 byte offset, UTF-16 index, dependency link or literal feature label can be handled precisely without inferring linguistic correctness or semantic equivalence.

Return UTF-8 bytes per Unicode code point for one token.

When to use this tool

Use Token Byte Character Ratio when checking a supplied linguistic annotation, span, alignment or text-offset convention.

How to use the tool and how it works

  1. Enter token. Use the units and conventions below.
  2. Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
  3. Read utf8Bytes, codePoints, ratio, defined. Inspect defined before interpreting the associated values.

Return UTF-8 bytes per Unicode code point for one token. Count encoded bytes and code-point iteration length; ratio divides them, or zero with defined false for empty text.1

UTF-8 bytes, UTF-16 code units and Unicode code points are distinct; grapheme boundaries need separate treatment.2

Input fieldMeaning and unitsAccepted input
tokenTokenRequired. Text; maximum UTF-16 length 8192.
Output fieldInterpretationReturned shape
utf8BytesUtf8 BytesRequired. Safe integer.
codePointsCode PointsRequired. Safe integer.
ratioEncoded UTF-8 byte count/code-point count, or zero when defined=false.Required. Finite number.
definedWhether the stated denominator or information basis permits interpretation of the associated value; inspect before using a placeholder.Required. Boolean.
json
{
  "input": {
    "token": "Aé🚀"
  },
  "output": {
    "utf8Bytes": 7,
    "codePoints": 3,
    "ratio": 2.3333333333333335,
    "defined": true
  }
}

Limitations and assumptions

  • This is a representation ratio, not tokenizer efficiency or grapheme width; encoding behavior for isolated surrogates follows the implementation.
  • Inputs must satisfy both the field types and the cross-field conditions above. Invalid input causes an error; a successful false flag or documented placeholder is a different result.

Alternative or Complementary methods

Use the appropriate tokenizer, Unicode and annotation-format conventions and validate the complete text or tree for full linguistic processing.

References

  1. Calculation and input contract: computational-linguistics/token-byte-character-ratio — tool.io

  2. Unicode 17.0: conformance and encoding forms — Unicode Consortium

Similar or alternative tools