Metadata-Version: 2.4
Name: savis
Version: 0.4.2
Summary: A sentence-level visualization tool for attention in large language models
Project-URL: Homepage, https://github.com/Seongbuming/savis
Project-URL: Repository, https://github.com/Seongbuming/savis
Project-URL: Documentation, https://github.com/Seongbuming/savis#readme
Project-URL: Bug Tracker, https://github.com/Seongbuming/savis/issues
Author-email: Seongbum Seo <seo@seongbum.com>
License: Copyright (c) 2012-2024 Scott Chacon and others
        
        Permission is hereby granted, free of charge, to any person obtaining
        a copy of this software and associated documentation files (the
        "Software"), to deal in the Software without restriction, including
        without limitation the rights to use, copy, modify, merge, publish,
        distribute, sublicense, and/or sell copies of the Software, and to
        permit persons to whom the Software is furnished to do so, subject to
        the following conditions:
        
        The above copyright notice and this permission notice shall be
        included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
        EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
        MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
        NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
        LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
        OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
        WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
License-File: LICENSE
Keywords: attention,large language models,nlp,visualization
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: matplotlib
Requires-Dist: nltk
Requires-Dist: numpy
Requires-Dist: torch
Requires-Dist: transformers
Description-Content-Type: text/markdown

# 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.

<center>
<img src="https://raw.githubusercontent.com/Seongbuming/savis/master/images/savis.png" width="500" alt="SAVIS analyzing reviews">
</center>

## Features

- Inter-sentence attention calculation
- Interactive visualization of attention patterns
- Support for various LLMs through [Hugging Face](https://huggingface.co)'s `transformers` library

## Installation

```bash
pip install savis
```

## Quick Start

```python
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](https://github.com/Seongbuming/savis/blob/master/LICENSE) file for more details.
