A powerful and user-friendly command-line tool for analyzing the sentiment of text using state-of-the-art transformer models.
- 🧠 Powerful NLP: Leverages Hugging Face transformer models for accurate sentiment analysis
- 🚀 High Performance: Automatic GPU acceleration when available
- 📊 Data Visualization: Generate charts and statistics from your analyses
- 🌈 Rich Output: Color-coded results with visual confidence indicators
- 📝 Comprehensive Logging: Track all analyses in a structured CSV format
- 📦 Batch Processing: Analyze multiple texts from files for efficiency
- 🛠️ Flexible Usage: Interactive mode or command-line options
- Python 3.7+
- pip (Python package manager)
-
Clone this repository:
git clone https://github.com/yourusername/sentiment-analysis-tool.git cd sentiment-analysis-tool -
Install the required dependencies:
pip install -r requirements.txt
Or install them directly:
pip install transformers torch tqdm colorama matplotlib
Simply run the script without arguments for interactive mode:
python sentiment_analyzer.pyEnter text at the prompt to analyze sentiment. Special commands:
stats: Display statistics about your sessionviz: Generate and display a visualization of sentiment distributionquit: Exit the program
python sentiment_analyzer.py --file input.txt --output results.csv --model cardiffnlp/twitter-roberta-base-sentimentAvailable options:
--model: Specify the Hugging Face model to use (default: "cardiffnlp/twitter-roberta-base-sentiment")--file: Process multiple texts from a file (one per line)--output: Save results to a specified CSV file--no-log: Disable automatic logging of results--cpu: Force CPU usage even if GPU is available
python sentiment_analyzer.py
> I absolutely love this new feature, it works perfectly!python sentiment_analyzer.py --file customer_reviews.txt --output sentiment_results.csvpython sentiment_analyzer.py --model distilbert-base-uncased-finetuned-sst-2-englishYou can import and use the SentimentAnalyzer class in your own Python code:
from sentiment_analyzer import SentimentAnalyzer
analyzer = SentimentAnalyzer()
result = analyzer.analyze("I'm really enjoying this new software!")
print(f"Sentiment: {result['sentiment']}, Score: {result['score']}")texts = ["Great product!", "Not satisfied with the quality", "It's okay, but not amazing"]
results = analyzer.analyze_batch(texts)By default, all analyses are logged to sentiment_log.csv with timestamps, which allows for:
- Tracking sentiment trends over time
- Building datasets for further analysis
- Generating comprehensive reports
The tool can generate pie charts showing the distribution of sentiments in your analyzed texts:
- transformers: State-of-the-art NLP models
- torch: Deep learning framework
- tqdm: Progress bars for batch processing
- colorama: Terminal text coloring
- matplotlib: Data visualization
Contributions are welcome!
- Hugging Face for their excellent transformers library
- Cardiff NLP for the pre-trained sentiment analysis model
Distributed under the GNU Affero General Public License v3.0 License. See LICENSE for more information.

