shap.plots.text

shap.plots.text(shap_values, num_starting_labels=0, grouping_threshold=0.01, separator='', xmin=None, xmax=None, cmax=None, display=True)

Plots an explanation of a string of text using coloring and interactive labels.

The output is interactive HTML and you can click on any token to toggle the display of the SHAP value assigned to that token.

Parameters
shap_values[numpy.array]

List of arrays of SHAP values. Each array has the shap values for a string(# input_tokens x output_tokens).

num_starting_labelsint

Number of tokens (sorted in decending order by corresponding SHAP values) that are uncovered in the initial view. When set to 0 all tokens covered.

grouping_thresholdfloat

If the component substring effects are less than a grouping_threshold fraction of an unlowered interaction effect then we visualize the entire group as a single chunk. This is primarily used for explanations that were computed with fixed_context set to 1 or 0 when using the Partition explainer, since this causes interaction effects to be left on internal nodes rather than lowered.

separatorstring

The string seperator that joins tokens grouped by interation effects and unbroken string spans.

xminfloat

Minimum shap value bound.

xmaxfloat

Maximum shap value bound.

cmaxfloat

Maximum absolute shap value for sample. Used for scaling colors for input tokens.

display: bool

Whether to display or return html to further manipulate or embed. default: True