Visualization

Token attribution visualization plugins.

nlp_shap.viz.display_attribution_html(output: ExplainRunOutput, snapshot: ConversationSnapshot, player_set: PlayerSet, *, title: str | None = None) Any[source]

Display colored token HTML when IPython is available.

nlp_shap.viz.render_attribution(output: ExplainRunOutput, snapshot: ConversationSnapshot, player_set: PlayerSet, *, renderer: str = 'token_text', title: str | None = None, registry: PluginRegistry | None = None) Figure[source]

Render output attributions with a registered renderer plugin.

nlp_shap.viz.render_attribution_html(output: ExplainRunOutput, snapshot: ConversationSnapshot, player_set: PlayerSet, *, title: str | None = None) str[source]

Return an HTML fragment for inline token coloring in Jupyter.

Public helpers for attribution visualization.

nlp_shap.viz.render.render_attribution(output: ExplainRunOutput, snapshot: ConversationSnapshot, player_set: PlayerSet, *, renderer: str = 'token_text', title: str | None = None, registry: PluginRegistry | None = None) Figure[source]

Render output attributions with a registered renderer plugin.

nlp_shap.viz.render.render_attribution_html(output: ExplainRunOutput, snapshot: ConversationSnapshot, player_set: PlayerSet, *, title: str | None = None) str[source]

Return an HTML fragment for inline token coloring in Jupyter.

nlp_shap.viz.render.display_attribution_html(output: ExplainRunOutput, snapshot: ConversationSnapshot, player_set: PlayerSet, *, title: str | None = None) Any[source]

Display colored token HTML when IPython is available.

SHAP-style inline colored token attribution renderer.

class nlp_shap.viz.token_text.TokenTextRenderer[source]

Bases: object

Render attributions as inline colored tokens.

property name: str

Return the registered renderer identifier.

render(labels: Sequence[str], values: Sequence[float], *, estimand: Estimand, title: str | None = None) Figure[source]

Build a matplotlib figure with SHAP-style colored token labels.

to_html(labels: Sequence[str], values: Sequence[float], *, estimand: Estimand, title: str | None = None) str[source]

Return an HTML fragment with colored token spans for Jupyter.

Horizontal bar chart renderer for token attributions.

class nlp_shap.viz.token_bar.TokenBarRenderer[source]

Bases: object

Render attributions as a SHAP-style horizontal bar chart.

property name: str

Return the registered renderer identifier.

render(labels: Sequence[str], values: Sequence[float], *, estimand: Estimand, title: str | None = None) Figure[source]

Build a horizontal bar chart sorted by absolute attribution.

Attribution renderer protocol.

class nlp_shap.protocols.renderer.AttributionRenderer(*args, **kwargs)[source]

Bases: Protocol

Render per-player attribution values for human review.

property name: str

Return the registered renderer identifier.

render(labels: Sequence[str], values: Sequence[float], *, estimand: Estimand, title: str | None = None) Any[source]

Return a visualization artifact for the given labels and values.