Skip to main content

ToneTint is a Python package that provides an intuitive way to perform sentiment analysis on text data and visualize the results. It splits the input text into manageable chunks, analyzes each chunk using a pre-trained sentiment analysis model, and highlights the text with background colors corresponding to the sentiment. Additionally, it displays tooltips with detailed sentiment scores when hovering over each text chunk.

Project description

ToneTint

PyPI version License: MIT

ToneTint is a Python package that provides an intuitive way to perform sentiment analysis on text data and visualize the results. It splits the input text into manageable chunks, analyzes each chunk using a pre-trained sentiment analysis model, and highlights the text with background colors corresponding to the sentiment. Additionally, it displays tooltips with detailed sentiment scores when hovering over each text chunk. Perfect for Jupyter Notebooks.

images

Table of Contents

Features

  • Sentiment Analysis: Uses pre-trained models to analyze the sentiment of text chunks.
  • Color-Coded Visualization: Highlights text with colors representing positive, negative, or neutral sentiments.
  • Opacity Adjustment: Adjusts the opacity of the highlight based on the confidence score of the sentiment prediction.
  • Interactive Tooltips: Displays sentiment labels and scores when hovering over text chunks.
  • Customizable Colors: Allows customization of highlight colors for different sentiments.
  • Flexible Text Chunking: Splits text into sentences and further into chunks of specified sizes for detailed analysis.

Installation

You can install ToneTint via pip:

pip install tonetint

Alternatively, you can clone the repository and install it manually:

git clone https://github.com/janduplessis883/tonetint_package.git
cd tonetint_package
python setup.py install

Usage

Basic Example

from tonetint.sentiment_visualizer import ToneTint

# Initialize the visualizer
visualizer = ToneTint()

# Your input text
text = "I love sunny days. However, I hate the rain. The weather today is okay."

# Display the sentiment visualization
visualizer.display(text)

This code will display your text with:

  • Positive sentiments highlighted in green.
  • Negative sentiments highlighted in red.
  • Neutral sentiments highlighted in yellow.

Hovering over each text chunk will show a tooltip with the sentiment label and confidence score.

Customization

Customizing Highlight Colors

You can specify custom colors for positive, negative, and neutral sentiments by passing a dictionary to the ToneTint constructor:

custom_colors = {
        "POS": "#aec867",  # Green
        "NEG": "#e8a56c",  # Red
        "NEU": "#f0e8d2",  # Yellow
}

visualizer = ToneTint(colors=custom_colors)

Adjusting Chunk Size

You can adjust the chunk size (number of words per chunk) for more granular or broader analysis:

visualizer = ToneTint(chunk_size=10)

Using a Different Model

You can specify a different pre-trained model for sentiment analysis:

visualizer = ToneTint(model_name='nlptown/bert-base-multilingual-uncased-sentiment')

Dependencies

  • Python 3.6 or higher
  • Transformers: For using pre-trained sentiment analysis models.
  • NLTK: For text tokenization.
  • IPython: For displaying HTML in Jupyter notebooks.
  • Torch: Required by some Transformer models.
  • SentencePiece: For certain tokenizer models.

You can install the dependencies via pip:

pip install transformers nltk ipython torch sentencepiece

Contributing

Contributions are welcome! If you have ideas for improvements or new features, feel free to open an issue or submit a pull request.

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/YourFeature).
  3. Commit your changes (git commit -am 'Add some feature').
  4. Push to the branch (git push origin feature/YourFeature).
  5. Open a pull request.

Please ensure your code adheres to the existing style conventions and that all tests pass.

License

This project is licensed under the MIT License - see the LICENSE file for details.


Disclaimer: This package uses pre-trained models from Hugging Face's Transformers library. The performance and accuracy of sentiment analysis depend on the chosen model. Always verify the outputs, especially when used for critical applications.

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

tonetint-0.0.7.tar.gz (976.1 kB view details)

Uploaded Source

Built Distribution

tonetint-0.0.7-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file tonetint-0.0.7.tar.gz.

File metadata

  • Download URL: tonetint-0.0.7.tar.gz
  • Upload date:
  • Size: 976.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.6

File hashes

Hashes for tonetint-0.0.7.tar.gz
Algorithm Hash digest
SHA256 538f224b66a86f15ec8d7804c769feeae139a093fa191e48750cc17091c1bc28
MD5 677114bfb4eb1d8f8a2d233a60d755c5
BLAKE2b-256 f0baf765d450d5d91ab18427950f0cd6f81f7eb8894552b21ccd8194089eab9b

See more details on using hashes here.

File details

Details for the file tonetint-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: tonetint-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.6

File hashes

Hashes for tonetint-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 bd472c251c28de05edf679ff3d7c78db7e1a0daea48d8e784e3505a83106f489
MD5 1cca82a9e005f6d7f37447c465f78e38
BLAKE2b-256 ccff034b89519f083167a56ff404ead2ebc328905643879399964dc84d0d9d33

See more details on using hashes here.

Supported by

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