Skip to main content

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.

NLP attribution strength demo

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trulens_viz-0.0.2.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trulens_viz-0.0.2-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file trulens_viz-0.0.2.tar.gz.

File metadata

  • Download URL: trulens_viz-0.0.2.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for trulens_viz-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f1e4dee0809a594f2ffd19c7beec850a2a35b68035b8551fb689e1398d47f927
MD5 7ef9090b80b384202c8abd382c5d7a6e
BLAKE2b-256 2fc469846817d55585bc20ff88c10a72ad3fcf9c7ef5e85ef4f9cfde864b6752

See more details on using hashes here.

File details

Details for the file trulens_viz-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: trulens_viz-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for trulens_viz-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cd8f83e46606343b8055f2bdacb9fb30fc8d9158a1f0b0da43265bbbcc370f93
MD5 fab32f0c21fd6deb24c57a64f34771e0
BLAKE2b-256 5744613bdd57c421065473ad61460c643e9c021d5148277a50c97e61d315bb4d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page