format_colorized - Tinker Documentation

tinker_cookbook.utils.format_colorized

tinker_cookbook.utils.format_colorized ( tokens, weights, tokenizer, draw_newline_arrow)

Colour-code text according to per-token weights.

Tokens are coloured green (weight > 0), yellow (weight == 0), or red (weight < 0). The function minimises ANSI escape sequences by wrapping runs of like-coloured tokens, and decodes each run in a single call so that multi-byte characters (e.g. CJK) render correctly.

Parameters:

Returns: str – ANSI-coloured string suitable for terminal display.

Raises:

text = format_colorized(token_ids, loss_weights, tokenizer)
print(text)