dianna.visualization.text
Module Contents
Functions
|
Highlights a given text based on values in a given explanation object. |
|
Assign a color to a text based on its importance. |
- dianna.visualization.text.highlight_text(explanation, input_tokens=None, show_plot=True, output_filename=None, colormap='RdBu', alpha=1.0, heatmap_range=(-1, 1))[source]
Highlights a given text based on values in a given explanation object.
- Parameters:
explanation – list of tuples of (word, index of word in original data, importance)
input_tokens – list of all tokens (including those without importance)
show_plot – Shows plot if true (for testing or writing plots to disk instead)
output_filename – Name of the file to save the plot to (optional).
colormap – color map for the heatmap plot (see mpl.Axes.imshow documentation for options).
alpha – alpha value for the heatmap plot.
heatmap_range – a tuple (vmin, vmax) to set the range of the heatmap.
- Returns:
None
- dianna.visualization.text._get_text_color(importance, vmin, vmax, colormap, alpha)[source]
Assign a color to a text based on its importance.
- Parameters:
importance (float) – The importance of the text (between vmin and vmax)
vmin (float) – The minimum value of the importance range
vmax (float) – The maximum value of the importance range
colormap (str) – color map for the heatmap plot (see mpl.Axes.imshow documentation for options).
alpha (float) – alpha value for the color.
- Returns:
(r, g, b, alpha) values of the color.
- Return type: