Skip to main content

Advanced sentiment analysis platform for text, web content, audio data and Image data

Project description

Here’s a detailed documentation for your Sentimatrix project, including the functionalities and sample code for accessing them.


Sentimatrix Documentation

Overview

Sentimatrix is a sentiment analysis and web scraping toolkit designed to analyze and visualize sentiments from various sources, including text, audio, and images. It offers integration with local and remote sentiment analysis models and web scrapers.

Please Note: This is a beta version of the project, and it is in the initial stages of development. Updates will be patched frequently. Ensure you review the latest documentation and updates regularly.

Requirements

Before using this product, make sure to:

  1. Get API Keys:

  2. API Notes:

    • OpenAI API: Not advised for use as it has not been tested yet.
    • Local LLM: Performance depends on your system configuration. Some APIs may have limited free usage and could incur costs in the future.
  3. Audio Files:

    • Ensure audio files are converted to .wav format before processing.

Features

  1. Quick Sentiment Analysis

    • Analyze the sentiment of text messages quickly using predefined models.
  2. Feedback Sentiment from Websites

    • Extract and analyze sentiments from customer feedback on e-commerce websites.
  3. Overall Summary Sentiment Analysis

    • Generate an overall sentiment summary for a product based on its reviews.
  4. Analytical Visualization

    • Visualize sentiment data using various chart types, including bar charts, box plots, histograms, pie charts, and violin plots.
  5. Sentiment Analysis from Audio Files

    • Analyze the sentiment of spoken words from audio files.
  6. Product Comparison

    • Compare sentiments between different products based on their reviews.
  7. Sentiment Analysis from Image Files

    • Extract and analyze sentiment from images containing text.
  8. Multi-Language Sentiment Analysis

    • Analyze sentiments in different languages using translation models.
  9. Local Scraper Configuration

    • Configure and use a local scraper for extracting reviews from websites.
  10. Save Reviews to CSV

    • Save extracted reviews from websites to a CSV file for further analysis.

Installation

You can install Sentimatrix using pip:

pip install sentimatrix

Usage

Importing the Library

from Sentimatrix.sentiment_generation import SentConfig

Creating an Instance

sent = SentConfig(
    Use_Local_Sentiment_LLM=True,
    Use_Local_Scraper=True,
    device_map="auto"
)

Functionalities

1. Quick Sentiment Analysis

Description: Analyze the sentiment of short text messages quickly using local sentiment models.

Usage:

from Sentimatrix.sentiment_generation import SentConfig

Sent = SentConfig(
    Use_Local_Sentiment_LLM=True,
)

sentiments = ["I am very happy", "I am very sad", "I am alright"]
sentiment_result = Sent.get_Quick_sentiment(text_message=sentiments, device_map="auto")

print(sentiment_result)

2. Web Scraper

Description: Scrape reviews from e-commerce websites and analyze their sentiments.

Usage:

Initialization and Scraping:

from Sentimatrix.utils.web_scraper import ReviewScraper

scraper = ReviewScraper(Use_Local_Scraper=True)
url = "https://www.amazon.com/Razer-Huntsman-Esports-Gaming-Keyboard/dp/B0CG7FQML2"
reviews_local = scraper.fetch_reviews(url)

list_of_sentences = [' '.join(sublist) for sublist in reviews_local]
for sentence in list_of_sentences:
    print(sentence)

Adding and Checking Review Patterns:

scraper.add_review_pattern('div', {'class': 'new-review-class'})
current_patterns = scraper.get_review_patterns()
print("Current review patterns:", current_patterns)

3. Sentiment Analysis from Websites

Description: Analyze sentiments from reviews on a given website. Supports both local and API-based scraping.

Usage:

Without Scraper API:

from Sentimatrix.sentiment_generation import SentConfig

Sent = SentConfig(
    Use_Local_Sentiment_LLM=True,
    device_map="auto"
)
target = 'https://www.amazon.in/ASUS-Battery-i7-13650HX-Windows-G614JU-N3200WS/dp/B0C4TVHMR9?th=1'
result = Sent.get_sentiment_from_website_each_feedback_sentiment(
    target_website=target,
    Use_Local_Scraper=True,
    get_Groq_Review=False
)

print(result)

With Scraper API:

from Sentimatrix.sentiment_generation import SentConfig

Sent = SentConfig(
    Use_Local_Sentiment_LLM=True,
    device_map="auto",
    Use_Scraper_API=True,
    Scraper_api_key=""
)
target = 'https://www.amazon.in/ASUS-Battery-i7-13650HX-Windows-G614JU-N3200WS/dp/B0C4TVHMR9?th=1'
result = Sent.get_sentiment_from_website_each_feedback_sentiment(
    target_website=target,
    get_Groq_Review=False
)

print(result)

4. Multi-Site Scraper

Description: Scrape and analyze sentiments from multiple sites simultaneously.

Usage:

from Sentimatrix.sentiment_generation import SentConfig

Sent = SentConfig(
    Use_Local_Sentiment_LLM=True,
    device_map="auto"
)
targets = [
    'https://www.amazon.in/ASUS-Battery-i7-13650HX-Windows-G614JU-N3200WS/dp/B0C4TVHMR9?th=1',
    'https://www.amazon.com/Legendary-Whitetails-Journeyman-Jacket-Tarmac/dp/B013KW38RQ/ref=cm_cr_arp_d_product_top?ie=UTF8'
]
result = Sent.get_sentiment_from_website_each_feedback_sentiment(
    target_website=targets,
    Use_Local_Scraper=True,
    get_Groq_Review=False
)

print(result)

5. Sentiment Analysis from Audio Files

Description: Analyze sentiment from audio files.

Usage:

from Sentimatrix.sentiment_generation import SentConfig

Sent = SentConfig(
    Use_Local_Scraper=True,
    Use_Local_Sentiment_LLM=True
)
audio_path = r'D:\Sentimatrix\tests\voice_datasets-wav\review_1.wav'
result = Sent.get_Sentiment_Audio_file(audio_path)

print(result)

6. Comparing Products Based on Reviews

Description: Compare sentiments of reviews for two different products.

Usage:

from Sentimatrix.sentiment_generation import SentConfig

Sent = SentConfig(
    Use_Local_Scraper=True,
    Use_Groq_API=True,
    Use_Local_Sentiment_LLM=True,
    Groq_API=''
)
targetsite1 = 'https://www.amazon.in/ASUS-Battery-i7-13650HX-Windows-G614JU-N3200WS/dp/B0C4TVHMR9?th=1'
targetsite2 = 'https://www.amazon.in/dp/B0CV9S7ZV6/ref=sspa_dk_detail_0?pd_rd_i=B0CV9S7ZV6'
result = Sent.compare_product_on_reviews(
    target_website1=targetsite1,
    target_website2=targetsite2
)

print(result)

7. Sentiment Analysis from Images

Description: Analyze sentiment from images containing text.

Usage:

from Sentimatrix.sentiment_generation import SentConfig

Sent = SentConfig(
    Use_Local_Scraper=True,
    Use_Local_Sentiment_LLM=True
)
image_path = ''
result = Sent.get_Sentiment_Image_file(Image_File_path=image_path, Image_to_Text_Model='microsoft/Florence-2-large')

print(result)

8. Multi-Language Sentiment Analysis

Description: Perform sentiment analysis on text in multiple languages.

Usage:

from Sentimatrix.sentiment_generation import SentConfig

SENT = SentConfig(
    Use_Local_Sentiment_LLM=True
)
message = 'நான் இந்த தயாரிப்பை வெறுக்கிறேன்'
result = SENT.Multi_language_Sentiment(message)

print(result)

9. Configuration and Review Management

Description: Manage local scraper configurations and save reviews to CSV.

Usage:

Configuring Local Scraper:

from Sentimatrix.sentiment_generation import SentConfig

Sent = SentConfig()
result = Sent.Config_Local_Scraper(action='get')
print(result)

Saving Reviews to CSV:

from Sentimatrix.sentiment_generation import SentConfig

Sent = SentConfig(
    Use_Local_Scraper=True,
    Use_Local_Sentiment_LLM=True
)
target = 'https://www.amazon.in/ASUS-Battery-i7-13650HX-Windows-G614JU-N3200WS/dp/B0C4TVHMR9?th=1'
Sent.Save_reviews_to_CSV(
    target_site=target,
    output_dir=r'',
    file_name='review.csv'
)

Additional Notes

  • Function get_sentiment_from_website_overall_summary: This function is still under development. It will be updated in future releases.
  • Function compare_product_on_reviews: Features for this function will be updated soon, including additional mathematical comparisons.

Parameters

  • Use_Local_Sentiment_LLM (bool): Whether to use a local sentiment analysis model.
  • Use_Scraper_API (bool): Whether to use an external scraper API.
  • Scraper_api_key (str): API key for accessing the external scraper.
  • Use_Local_Scraper (bool): Whether to use a local web scraper.
  • Use_Groq_API (bool): Whether to use the Groq API for sentiment analysis.
  • Groq_API (str): API key for accessing the Groq API.
  • Use_Local_General_LLM (bool): Whether to use a general local LLM for analysis.
  • device_map (str): Device configuration for model inference (e.g., "auto").

Conclusion

This documentation provides an overview of Sentimatrix functionalities and usage. For more detailed configurations and advanced features, refer to the specific function implementations or the project's source code.


Feel free to modify any details or add additional sections based on specific project needs.

Testing

To ensure the correctness of your implementation, you can run the unit tests included in the tests/test_sent_config.py file. Use the following command to run the tests:

pytest

License

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

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

sentimatrix-0.1.1.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

Sentimatrix-0.1.1-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file sentimatrix-0.1.1.tar.gz.

File metadata

  • Download URL: sentimatrix-0.1.1.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for sentimatrix-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2e189edd70c4d78c43041faeafa4ccf0752f840de14f8d32f3b16dc618facd6f
MD5 bf30f5f04794c3adeb1aa8d6e78f9499
BLAKE2b-256 15c5d3f0015eb43eb458c8c7b6fb8a0b8efe164f84be7ca6432ef213a70b3a06

See more details on using hashes here.

File details

Details for the file Sentimatrix-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: Sentimatrix-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for Sentimatrix-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fae24ee5e685630cfeaa05c381176cde178acb5f566c9dd004c760d80db6accd
MD5 eccd0c1552100e02e17e88c93f8cdad3
BLAKE2b-256 f46446ec79b9a01558f2f0903fcbbd21bb06e446764e9e2dc50cf0dbbae3fb7a

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