Practical Sentiment and Emotion Analysis with DistilBERT, RoBERTa, and Meta-Llama
Welcome to the Sentiment and Emotion Analysis Application repository! This guide provides a detailed overview of how to run a sentiment and emotion analysis tool using both Streamlit and Gradio interfaces. This project demonstrates how to integrate advanced AI models with user-friendly interfaces for practical natural language processing tasks.
- Script Folder: This repository contains the scripts required to run the sentiment and emotion analysis application with both Streamlit and Gradio.
Overview
This application utilizes the distilbert-base-multilingual-cased-sentiments-student model for sentiment analysis, the roberta-base-go_emotions model for emotion detection, and the meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo model for personalized advice generation. The sentiment analysis covers three categories: positive, negative, and neutral, while the emotion detection identifies the top six emotions with corresponding scores. The advice generation provides practical suggestions based on the sentiment and emotions detected, incorporating context from the original user prompt.
The application provides two interfaces:
- Streamlit Interface: For a web-based interactive experience with additional features.
- Gradio Interface: For a quick and easy web-based demo with suggestion capabilities.
For detailed information about the models used, refer to the used_model_details.ipynb notebook.
This guide covers:
- Prerequisites: Necessary tools and software.
- Installation Instructions: How to set up your environment.
- Running the Application: Detailed commands to launch either interface.
- Troubleshooting: Common issues and their solutions.
- Contribution Guidelines: How to contribute to the project.
- Additional Resources: Links for further reading.
Prerequisites
Before you begin, ensure you have the following tools installed on your system:
- Conda: Follow the instructions on the Miniconda installation page to install Conda.
- Bash: Bash is typically included with Unix-based systems (Linux, macOS). For Windows users, consider using Git Bash or the Windows Subsystem for Linux (WSL).
Installation Instructions
Follow these steps to set up your environment and install the necessary packages:
-
Clone the Repository
Clone this repository to your local machine:
git clone https://github.com/yourusername/sentiment-analysis-app.git cd sentiment-analysis-app
-
Run the Setup Script
The
setup_environment.shscript automates the environment setup process. It creates and activates a Conda environment, installs necessary packages, and provides options to run the application using Streamlit or Gradio.bash setup_environment.shThe script will prompt you with a menu to choose between the following options:
- Run with Streamlit interface
- Run with Gradio interface
- Update dependencies
- Exit
Choose the appropriate option to proceed.
Running the Application
You can run the application using the provided script:
Launch Streamlit Interface
To run the application with Streamlit, select the Streamlit interface option from the setup script menu, or use the following command:
python run_sentiment_analysis.py --interface streamlit
This will start a local Streamlit server and open your default web browser to view the application. The Streamlit interface includes:
- Theme Selection: Choose between Normal, Unnormal, or Fun themes.
- Sentiment and Emotion History: View past sentiment and emotion analyses.
- Interactive Tutorial: Get a guided tour of the application.
- Animated Transitions: Experience dynamic visual effects for sentiment scores.
- Twitter Sharing: Share your analysis results directly on Twitter.
- Visualization: Displays sentiment and emotion scores using colorful bar charts.
- Personalized Advice: Generates advice based on sentiment and emotion analysis using the
meta-llama/Meta-Llama-3.1-70B-Instruct-Turbomodel.
Launch Gradio Interface
To run the application with Gradio, select the Gradio interface option from the setup script menu, or use the following command:
python run_sentiment_analysis.py --interface gradio
This will start a local Gradio server and open your default web browser to view the application. The Gradio interface features:
- Twitter Sharing: Share your analysis results directly on Twitter.
- Visualization: Displays sentiment and emotion scores using bar charts.
- Suggestion Options: Offers pre-prepared text options that users can pick from to facilitate analysis.
Troubleshooting
- Streamlit Command Not Found: Ensure Streamlit is installed correctly. Verify by running
streamlit --version. - Gradio Command Not Found: Ensure Gradio is installed correctly. Verify by running
pip show gradio. - Environment Activation: Ensure the Conda environment is activated with
conda activate sentiment_analysis.
If you encounter issues, verify that you are in the correct directory and that all dependencies are installed.
Contributing
Contributions to enhance this application are welcome! If you have suggestions, improvements, or additional features, please feel free to open an issue or create a pull request. Let's collaborate to make this tool even more useful for sentiment and emotion analysis.
Additional Resources
Explore additional resources to deepen your understanding of sentiment and emotion analysis and the tools used:
- Hugging Face Transformers Documentation
- Streamlit Documentation
- Gradio Documentation
- DistilBERT Model Overview
- RoBERTa Model Overview
- Meta-Llama Model Overview
- Used Model Details
License
The content in this repository is licensed under the MIT License. You are free to use, modify, and distribute the code, provided you include the original copyright notice and license.
© 2024 Erfan Shafiee Moghaddam
Metadata
Release files for sentiment-emotion-detection 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sentiment_emotion_detection-0.1.0.tar.gz | 167.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sentiment_emotion_detection-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 183.1 kB
Release files / sentiment_emotion_detection-0.1.0.tar.gz
| Download URL | sentiment_emotion_detection-0.1.0.tar.gz |
|---|---|
| Size | 167.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b95e29aceaa7b5cb44626cd0eb79de0b2c0102c727485e213181f4a92f258679
|
|
BLAKE2b-256 checksum How to use checksums |
eae63d91e6f987af7768cb9a80a1851128e00974c3dae27e2e718d2e70c01c08
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.18
|
Release files / sentiment_emotion_detection-0.1.0-py3-none-any.whl
| Download URL | sentiment_emotion_detection-0.1.0-py3-none-any.whl |
|---|---|
| Size | 15.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c07ec0feb00fc4ee58d13f0a306bd5a881081ef0912f492e0e32f43bc6323b50
|
|
BLAKE2b-256 checksum How to use checksums |
4b3c00add60ea1c0ac3dc69e67379b775130a0724f9d0869c18a4658e4a33c64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.18
|