Experimental NLP attribution strength visualization
Project description
trulens_viz
Visualize NLP results for human consumption
The nlp_viz.HTMLTable
class takes phrases for which per-word attribution strenths are available. A phrase is provided to the class as a list of (word, attribution_score) tuples. Instances create a table with pairs of lines, one pair for each phrase. The first line shows the phrase's sequence of words, styled with one of two methods for communicating the word's attribution score: color, or size. The second line shows the attributions below each word.
Installation
After cloning, and creation of a virtual environment:
pip install .
Usage
The above table display was created via this code:
word_attrs = [('foo', -10345), ('<s>', -3), ('bar', 6)]
tbl = HTMLTable(word_attrs, word_styling=WordStyles.FONT_COLOR)
# Add a second phrase, using fontsize as attribution score indicator:
tbl.add_rows([('My', -12345.),
('Bonny', -100),
('lies', 0),
('over', 100),
('the', 500),
('ocean', 10000.)],
word_styling=WordStyles.FONT_SIZE)
# The third phrase, uses font color instead of size:
tbl.add_rows([('My', -12345.),
('Bonny', -100),
('lies', 0),
('over', 100),
('the', 500),
('ocean', 10000.)],
word_styling=WordStyles.FONT_COLOR)
print(str(tbl.doc))
The printed string was transferred to a file, and opened in a browser. Alternatively, one can use the Python webbrowser package to open the file from code.
The code collects all scores, and sorts them into quantile bins (default is five bins). A word's bin membership determines the word's color or fontsize for display. Currently all attributions from all phrases in a table are used for quantiling. One could experiment with using only the strenghts within one phrase for that phrase's display.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for trulens_viz-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11a98903481cc580ffef29624ffdf794c672851c5e8a75ccf8bde483ae54d227 |
|
MD5 | ea37492dd67fbefb9f8b2b9ec5f75d8a |
|
BLAKE2b-256 | ddb2710d2560a4db681186efecac444fd3f83d64bee93991d766a8409a57ba4d |