visualize

dialz.visualize.highlight_token(score, vmin=-1.0, vmax=1.0)[source]

Generate ANSI escape codes for 24‑bit background highlighting (red→white→turquoise) with black text. Uses the same color interpolation logic as html_value_to_color.

Parameters:
  • score (float) – Activation score.

  • vmin (float) – Minimum score (mapped to red).

  • vmax (float) – Maximum score (mapped to turquoise).

Return type:

str

Returns:

ANSI escape sequence string.

dialz.visualize.html_value_to_color(val, vmin, vmax)[source]

Map a scalar score to a CSS RGB color string on a red→white→turquoise gradient.

Parameters:
  • val (float) – Activation score.

  • vmin (float) – Minimum score (mapped to red).

  • vmax (float) – Maximum score (mapped to turquoise).

Return type:

str

Returns:

CSS rgb(r,g,b) string.

dialz.visualize.visualize_activation(input_text, model, control_vector, layer_index=None, mode='ansi', show_score=False)[source]

Highlight token activations by projecting hidden states onto a steering vector.

Supports negative indices (e.g., -1 for final layer) and averaging over multiple layers. Outputs ANSI-colored text for terminal or HTML snippet for Jupyter notebooks.

Parameters:
  • input_text (str) – Original input string.

  • model (SteeringModel) – SteeringModel instance wrapping an LLM.

  • control_vector (SteeringVector) – SteeringVector defining the intervention direction.

  • layer_index (Union[int, List[int]]) – Single index or list of indices; negative values count from end.

  • mode (str) – “ansi” for console output, “html” for notebook display.

  • show_score (bool) – If True, append numeric score to each token.

Return type:

Union[str, HTML]

Returns:

ANSI string or IPython.display.HTML.

Raises:
  • ValueError – If no controlled layers set on the model.

  • RuntimeError – If hidden states are not captured.