A machine learning project that performs sentiment analysis on YouTube video comments. Users can input the URL of a YouTube video, and the model analyzes the comments to determine the percentage of positive and negative sentiments.
- Overview
- Features
- Project Workflow
- Tools & Libraries
- Implementation
- Results
- Future Improvements
- Getting Started
This project uses Natural Language Processing (NLP) to analyze user comments fetched from YouTube. The goal is to classify the comments into positive or negative sentiment and provide a percentage summary of the sentiment distribution.
- Fetches comments from YouTube using YouTube Data API v3.
- Analyzes sentiments using a pre-trained transformer-based model (
Hugging Facepipeline). - Returns the percentage of positive and negative comments.
- Provides a foundational ML project for sentiment analysis.
- Input a YouTube video URL.
- Extract comments using YouTube Data API v3.
- Preprocess comments (removal of special characters, lowering text, etc.).
- Perform sentiment analysis using a pre-trained NLP model.
- Display the percentage of positive and negative sentiments.
- Programming Language: Python
- ML Model: Hugging Face Transformers
- Libraries:
transformersfor sentiment analysis.google-api-python-clientto interact with YouTube Data API.numpyandpandasfor data manipulation.matplotlibfor visualization (optional).
- Environment: Jupyter Notebook/Google Colab.
- Utilize the YouTube Data API v3 to fetch the top 50 comments for a given video.
- Requires an API key for authentication.
- Clean comments by removing special characters and converting to lowercase.
- Use a pre-trained transformer model from Hugging Face, such as
distilbert-base-uncased. - Classify comments into positive and negative sentiments.
- Calculate the percentage of positive and negative comments.
- Visualize the results using a pie chart or bar graph.
Here’s an example output for a test video:
| Metric | Value |
|---|---|
| Positive | 72% |
| Negative | 28% |
A pie chart displaying the sentiment distribution:
- Positive: Green
- Negative: Red
- Increase Comment Limit: Fetch more comments for better accuracy.
- Custom Training: Train the sentiment model on domain-specific data for improved performance.
- Frontend Integration: Build a user-friendly web app using Flask, FastAPI, or React.
- Enhanced Metrics: Add neutral sentiment analysis for a three-way classification.
- Batch Processing: Allow analysis of multiple videos simultaneously.
git clone https://github.com/Devanshi-Sonara/Youtube-Comment-Analysis.git
cd YouTube-Sentiment-Analysispip install transformers google-api-python-client numpy pandasReplace YOUR_API_KEY in the code with your API key.
Run the Jupyter Notebook or Python script:
python sentiment_analysis.py- Python
- Hugging Face Transformers
- YouTube Data API v3
Contributions are welcome! Please open an issue or submit a pull request.