A deep learning-powered web application that performs sentiment analysis on financial news headlines to classify them as positive or negative. Built with TensorFlow and Streamlit, this project leverages transfer learning with the Universal Sentence Encoder for accurate sentiment classification.
News2Sentiment analyzes financial news headlines in real-time to determine their sentiment, providing valuable insights for investment decisions, market analysis, and risk assessment. The system uses a sophisticated deep learning model trained on a comprehensive dataset of Indian financial news from 2017-2021.
- Real-time Sentiment Analysis: Instant classification of financial news headlines
- High Accuracy: ~80% accuracy using transfer learning and bidirectional LSTM
- User-friendly Interface: Clean Streamlit web application
- Confidence Scoring: Provides confidence levels for each prediction
- Transfer Learning: Uses Universal Sentence Encoder for robust text understanding
- Deployment Ready: Complete configuration for cloud deployment
The model is trained on the India Financial News Headlines Sentiments Dataset:
- Date Range: January 1, 2017 to April 15, 2021
- Sources: Economic Times, Money Control, Livemint, Business Today, Financial Express, NY Times, WSJ, Washington Post
- Keywords: Economy, markets, inflation, Indian economy, Indian businesses
- Sentiment Analysis: Performed using Flair NLP model
- Data Cleanup: Removed repetitive headlines and headlines < 30 characters
Input Layer (Text)
โ
Universal Sentence Encoder (Transfer Learning)
โ
Expand Dimensions
โ
Bidirectional LSTM (72 units, return_sequences=True)
โ
Dropout (0.5)
โ
Bidirectional LSTM (72 units, return_sequences=True)
โ
Dropout (0.5)
โ
Bidirectional LSTM (72 units)
โ
Dropout (0.5)
โ
Dense Output Layer (1 unit, sigmoid activation)
- Backend: Python 3.9.15
- Deep Learning: TensorFlow 2.8.0
- Web Framework: Streamlit 1.15.1
- Transfer Learning: Universal Sentence Encoder
- Data Processing: Pandas, NumPy
- Model Architecture: Bidirectional LSTM with Dropout
- Python 3.9.15
- pip package manager
git clone <repository-url>
cd News2Sentimentpip install -r requirements.txtThe application requires a pre-trained model file (best_model.h5). You can either:
- Train the model using the Jupyter notebook (
News2Sentiment.ipynb) - Download the pre-trained model from the releases section
- Start the Streamlit app:
streamlit run main.py-
Open your browser and navigate to the provided URL (usually
http://localhost:8501) -
Enter a financial news headline in the text input field
-
Click "Check" to get the sentiment analysis results
Input: "Student loan forgiveness has scammers 'on the move,' warns FTC"
Output: "It's a Negative News. Confidence Level is 96.459% Beware!! It's a Fake News."
- Open the Jupyter notebook:
jupyter notebook News2Sentiment.ipynb- Follow the notebook cells to:
- Download and preprocess the dataset
- Train the deep learning model
- Evaluate model performance
- Save the trained model
- Training Accuracy: 80.41%
- Validation Accuracy: 79.52%
- Loss Function: Binary Crossentropy
- Optimizer: Adam
- Training Epochs: 10
The model uses:
- Confusion Matrix for performance analysis
- Confidence Scoring for prediction reliability
- Binary Classification (Positive/Negative)
streamlit run main.pyThe project includes configuration files for cloud deployment:
- Setup script (
setup.sh) configures Streamlit for deployment - Runtime specification (
runtime.txt) specifies Python version - Requirements (
requirements.txt) lists all dependencies
- Create a new Heroku app
- Push the code to Heroku
- The setup script will automatically configure the environment
PORT: Server port (automatically set by deployment platform)- Streamlit credentials can be configured in
~/.streamlit/credentials.toml
News2Sentiment/
โโโ main.py # Streamlit web application
โโโ News2Sentiment.ipynb # Jupyter notebook for model development
โโโ requirements.txt # Python dependencies
โโโ runtime.txt # Python version specification
โโโ setup.sh # Deployment configuration script
โโโ best_model.h5 # Pre-trained model (not included in repo)
โโโ README.md # This file
The setup.sh script creates the following configuration:
# ~/.streamlit/config.toml
[server]
headless = true
enableCORS = false
port = $PORT- Input Shape: String input
- Output: Binary classification (0/1)
- Activation: Sigmoid
- Custom Objects: KerasLayer for TensorFlow Hub integration
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Dataset Source: India Financial News Headlines Sentiments on Kaggle
- GDELT Headline Scrape: Prof. Ken Blake's script for news headline scraping
- Helper Functions: TensorFlow Deep Learning helper functions by mrdbourke
- Universal Sentence Encoder: Google's pre-trained text embedding model
If you encounter any issues or have questions:
- Check the Issues page
- Create a new issue with detailed description
- Include error messages and system information
- Add neutral sentiment category
- Implement ensemble methods
- Add market-specific features
- Include temporal analysis
- Mobile-responsive design
- API endpoints for integration
- Real-time market data integration
- Multi-language support
Note: This project is for educational and research purposes. Always verify financial decisions with professional advisors and multiple sources.