A sentence-level visualization tool for attention in large language models
Project description
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.
Features
- Inter-sentence attention calculation
- Interactive visualization of attention patterns
- Support for various LLMs through Hugging Face's
transformerslibrary
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
TextGenerator: Interfaces with the LLM to generate text and extract attention information.Attention: Manages the underlying LLM and provides methods for obtaining attention data from the model.ISA(Inter-Sentence Attention): Processes raw attention data to compute attention between sentences.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:
TextGeneratoruses the LLM to generate text based on input prompts.Attentionhandles the interaction with the LLM, extracting detailed attention information.ISAtakes the raw attention data and computes meaningful inter-sentence attention scores.ISAVisualizationtakes these scores and creates interactive visualizations.
License
SAVIS is released under the MIT License. See the LICENSE file for more details.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file savis-0.4.3.tar.gz.
File metadata
- Download URL: savis-0.4.3.tar.gz
- Upload date:
- Size: 4.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a0f8ef6fd59db83d781f11524e0726f4ead38ba901c49b699a1ce19efd27bb6
|
|
| MD5 |
b5b694fbc9a5691c17d210cfceea790c
|
|
| BLAKE2b-256 |
7938df1fce6641e4e7826cb3ed09d555d2bef7cf5f24e01065eb3d7e862b697d
|
File details
Details for the file savis-0.4.3-py3-none-any.whl.
File metadata
- Download URL: savis-0.4.3-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f19e432aa2b9972d93a50d1fae9bc14c6f3e55aad813142705eb0aae4c55cd02
|
|
| MD5 |
f9435b04e5cd37fb18c088c4171ac29d
|
|
| BLAKE2b-256 |
cb2ec9b1af7e7dfdfa5a393f81440b02f86efa05918556df405e8192e397208b
|