# tinker_cookbook.utils.format_colorized

### [**tinker_cookbook.utils.format_colorized**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/utils/format_colorized.py#L6) ( _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:**

- [**tokens**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/utils/format_colorized.py#L7) ( _list[int]_) – Token IDs to decode and display.
- [**weights**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/utils/format_colorized.py#L7) ( _list[float]_) – Per-token weight values (same length as _tokens_).
- [**tokenizer**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/utils/format_colorized.py#L7) ( _Tokenizer_) – Tokenizer used to decode token IDs to text.
- [**draw_newline_arrow**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/utils/format_colorized.py#L7) ( _bool_) – If `True`, render newlines as a visible arrow (`↵`) followed by an actual newline.

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

**Raises:**

- ValueError: If _tokens_ and _weights_ have different lengths.

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