Skip to main content

SAVIS: Sentence-Level Attention Visualization for Large Language Models

SAVIS (Sentence-level Attention VISualization) is a Python library for visualizing inter-sentence attention in large language models (LLMs). This tool enhances the interpretability of LLMs by providing an intuitive visualization of how attention is distributed across sentences in generated text.

SAVIS analyzing reviews

Features

  • Inter-sentence attention calculation
  • Interactive visualization of attention patterns
  • Support for various LLMs through Hugging Face's transformers library

Installation

pip install savis

Quick Start

from savis import TextGenerator, ISA, ISAVisualization

# Initialize the text generator with your chosen model
generator = TextGenerator("Model name")

# Generate text and get attention data
input_text = "Your input prompt here"
generated_text, attentions, tokenizer, input_ids, outputs = generator.generate_text(input_text)

# Calculate inter-sentence attention
isa = ISA(outputs.sequences[0], attentions, tokenizer)

# Visualize the attention patterns
vis = ISAVisualization(isa.sentence_attention, isa.sentences)
vis.visualize_sentence_attention()

Key Components

  1. TextGenerator: Interfaces with the LLM to generate text and extract attention information.
  2. Attention: Manages the underlying LLM and provides methods for obtaining attention data from the model.
  3. ISA (Inter-Sentence Attention): Processes raw attention data to compute attention between sentences.
  4. ISAVisualization: Creates interactive visualizations of the computed inter-sentence attention.

These components work together to provide a comprehensive pipeline from text generation to attention visualization:

  • TextGenerator uses the LLM to generate text based on input prompts.
  • Attention handles the interaction with the LLM, extracting detailed attention information.
  • ISA takes the raw attention data and computes meaningful inter-sentence attention scores.
  • ISAVisualization takes these scores and creates interactive visualizations.

License

SAVIS is released under the MIT License. See the LICENSE file for more details.

Metadata

Release files for savis 0.4.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for savis 0.4.3
File Size Uploaded Provenance
savis-0.4.3.tar.gz 4.9 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for savis 0.4.3
File Interpreter ABI Platform
savis-0.4.3-py3-none-any.whl Python 3 none any Details

Total release size: 4.9 MB

Release files / savis-0.4.3.tar.gz

Download URL savis-0.4.3.tar.gz
Size 4.9 MB
Tags Source
SHA-256 checksum
How to use checksums
4a0f8ef6fd59db83d781f11524e0726f4ead38ba901c49b699a1ce19efd27bb6
BLAKE2b-256 checksum
How to use checksums
7938df1fce6641e4e7826cb3ed09d555d2bef7cf5f24e01065eb3d7e862b697d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.10.13

Release files / savis-0.4.3-py3-none-any.whl

Download URL savis-0.4.3-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f19e432aa2b9972d93a50d1fae9bc14c6f3e55aad813142705eb0aae4c55cd02
BLAKE2b-256 checksum
How to use checksums
cb2ec9b1af7e7dfdfa5a393f81440b02f86efa05918556df405e8192e397208b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.10.13

Security for savis 0.4.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page