Develop an NLP-powered sentiment analysis engine to predict stock movements using financial news data to help traders in their daily decisions.
-
Sentiment Analysis ✅
--> Analyze the sentiments and perspectives within the texts to discern the global sentiment of a document -
Topic Modeling ✅ --> Identify and categorize key themes in the texts to obtain a comprehensive understanding of the topics.
-
Aspect Based Sentiment ✅ --> Analyze specific aspects in the text to understand sentiment nuances or specific perspectives .
-
Historical Sentiment Records (Next steps) --> Explore temporal trends in sentiment analysis to understand the evolution of opinions over time
mermaid
graph TD
A[Raw Financial News] --> B(Sentiment Analysis)
B --> C(Topic Modeling)
C --> D(Aspect-Based Analysis)
D --> E(Temporal Trend Analysis)
E --> F[Stock Movement Prediction]
| Model | Architecture | Epochs | Classes | Accuracy |
|---|---|---|---|---|
| DistilRoberta | Transformer | 10 | 2 | 100% (overfit) |
| FinancialBERT | BERT-base | 10 | 2 | 99% (overfit) |
| FinancialLarge | RoBERTa-large | 5 | 3 | 92% |
Two-Class Sentiment Analysis:
- Data classified into Negative or Positive sentiments
- Fine-tuning with a 4-layer architecture
- Training conducted over 10 epochs

Three-Class Sentiment Analysis:
- Data categorized into Negative, Neutral, and Positive sentiments
- Fine-tuning with a 4-layer architecture
- Model trained for 5 epochs
The results weren't good with the fine tunned models, it decreased some performance, especially the 3 class predictions. Let's moove on with the topic detection.
I tested 3 LDA approachs. Linear discriminant analysis (LDA) is an approach used in supervised machine learning to solve multi-class classification problems. LDA separates multiple classes with multiple features through data dimensionality reduction.
| Model | Pros | Cons |
|---|---|---|
| LDA 1 | Robust, complete | Buggy code |
| LDA 2 (BART) | StackExchange fine-tuned | Very slow |
| LDA 3 (Gensim) | Clear, interactive visu | Alpha balancing tricky |
Gensim visualisations with alpha manipulation :
Hybrid Solution choosen:
- LDA for probabilistic topic assignment
- BERT for semantic embedding
- Weighted concatenation (α = 0.4)
Key Parameters:
- 10 main financial topics
- 3 subtopics per category
Targeted goal: Be able to obtain a balanced analysis for a relevant measure of a sentiment associated to a speciic company or theme in a sentence where the opinion are mixed.
Aspect-Based Sentiment Analysis: Unlike general sentiment analysis, ABSA focuses on extracting sentiments associated with specific aspectsmentioned in a text.
Example Output:
{
"text": "Bank A reported 15% revenue growth but increased debt",
"aspects": [
{"term": "revenue", "sentiment": "positive", "score": 0.82},
{"term": "debt", "sentiment": "negative", "score": -0.76}
]
}
After identifying aspects, the model determines the sentiment (positive, negative, neutral) for each aspect in each document.
- Version that identify the aspect by extracting nouns:
- Version after LDA topics injected
- Good detection results with a big increase with LDA topic injection
- Aspect-level sentiment extraction
- PhraseBank dataset limitation
- Dependency chain between modules
- Alpha parameter sensitivity in LDA-BERT hybrid
- More data integration
- Web scraper for historical sentiment
- Unified prediction engine
- Real-time API deployment
{
"sentence": "Orion Corp reported Q3 earnings fall due to R&D costs",
"label": "negative",
"topics": ["pharma", "earnings"],
"aspects": {
"earnings": -0.68,
"R&D": 0.12
}
}
- NLP Models: HuggingFace Transformers, Gensim, SpaCy
- Visualization: PyLDAvis, Matplotlib
- Infrastructure: Python 3.9, PyTorch 2.0
Aurélien Pouxviel, Data Scientist.
