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:
-
Get API Keys:
- Groq API
- Hugging Face API
- Scraper API
- Browser API from What Is My Browser
-
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.
-
Audio Files:
- Ensure audio files are converted to
.wav
format before processing.
- Ensure audio files are converted to
Features
-
Quick Sentiment Analysis
- Analyze the sentiment of text messages quickly using predefined models.
-
Feedback Sentiment from Websites
- Extract and analyze sentiments from customer feedback on e-commerce websites.
-
Overall Summary Sentiment Analysis
- Generate an overall sentiment summary for a product based on its reviews.
-
Analytical Visualization
- Visualize sentiment data using various chart types, including bar charts, box plots, histograms, pie charts, and violin plots.
-
Sentiment Analysis from Audio Files
- Analyze the sentiment of spoken words from audio files.
-
Product Comparison
- Compare sentiments between different products based on their reviews.
-
Sentiment Analysis from Image Files
- Extract and analyze sentiment from images containing text.
-
Multi-Language Sentiment Analysis
- Analyze sentiments in different languages using translation models.
-
Local Scraper Configuration
- Configure and use a local scraper for extracting reviews from websites.
-
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
Built Distribution
File details
Details for the file sentimatrix-0.1.4.tar.gz
.
File metadata
- Download URL: sentimatrix-0.1.4.tar.gz
- Upload date:
- Size: 28.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d15abb1224003f726220a8294068f51080883f1e6137aa5f1dbeaf6dbc8f0977 |
|
MD5 | bf0b6793ef7ebe541aad43c930c1edd3 |
|
BLAKE2b-256 | dc9d630faa1d96eba6bffc2eddc268dc6e9b1a1b26d296c052b4fd14bdb0d997 |
File details
Details for the file Sentimatrix-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: Sentimatrix-0.1.4-py3-none-any.whl
- Upload date:
- Size: 34.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a195a21d78cdb7614a4727e8a4e480c0aa58a1189b23a9c908a199e7765a8613 |
|
MD5 | 5d2fe8e42f26f42b0dd99ce7afe8bc59 |
|
BLAKE2b-256 | f28c2031f977a4bead0ca7412108dc6b2b64bfc0a79914f883334747f9031869 |