- Project Overview
- Setup Instructions
- 1. Data Loading and Cleaning
- 2. BiLSTM
- 3. Bert Models
- 4. RAG
- 5. Interactive Dashboard
- Contributors
The goal of this project is to perform sentiment analysis on real financial news from 2018 to 2023, scraped from Yahoo Finance. Several neural network models were implemented to classify each news in one of the three plausible labels: "Positive", "Negative" or "Neutral".
To ensure the correct execution of all project components and to avoid potential errors during setup and runtime, please follow the steps below carefully.
It is recommended to create and activate a virtual environment before installing the project dependencies. This helps maintain an isolated and consistent Python environment.
The project was developed using:
- Python 3.11.7
Before running any script or notebook, make sure to navigate to the root directory of the project.
All required libraries are listed in the requirements.txt file. Install them by running the following command from the project root directory:
pip install -r requirements.txtSee notebook: 1.Dataset_loading_cleaning.ipynb
- loading the data from https://github.com/felixdrinkall/financial-news-dataset
- ensuring the dataset is free of missing values and other inconsistencies
- Preparation and generation of the two CSV datasets used by the dashboard
See notebook: 2.BiLSTM.ipynb
-
Exploratory Data Analysis
-
BiLSTM with GloVe embeddings: bidirectional LSTM architecture for sentiment classification of financial news, using pre-trained GloVe embeddings to capture semantic relationships between words.
-
data preprocessing and balancing: cleaning the dataset, balancing sentiment classes, tokenizing text, and applying sequence padding.
-
hyperparameter tuning: performing grid search to identify the optimal model configuration.
-
model training and evaluation: training the BiLSTM model on the processed dataset and evaluating its performance on the test set.
-
saving model artifacts: storing checkpoints, grid search results, and evaluation outputs to allow reuse without retraining and to enable dashboard integration.
See notebook: 3.Bert_Models.ipynb
- transformers model which was pretrained by knowledge distillation using BERT as foundational model.
- pre-trained model to analyze sentiment of financial text, built by further training the BERT language model in the finance domain.
- transformers model pretrained on generic data, considered a foundational model for sequence classification, token classification or question answering tasks.
See script: RAG/RAG.py
-
loading and splitting the dataset into small text chunks.
-
creating embeddings and storing them in a FAISS index for efficient similarity-based retrieval of relevant context.
-
implementing a question-answering system that retrieves top-k relevant chunks, builds an augmented prompt, and asks a local LLM (via Ollama) to generate context-grounded answers.
The dashboard provides an interactive environment to explore and analyze the results generated by the project. It includes:
- Exploratory Data Analysis (EDA)
- Model performance metrics
- A BiLSTM model
- Three BERT-based models
- A Retrieval-Augmented Generation (RAG) component
- A dedicated page for company-level sentiment analysis and visualization
The dashboard relies on precomputed data, model outputs, and weights.
To use it correctly, all project files must be executed beforehand in order to generate the required resources.
Although the dashboard is contained within the dashboard/ folder, not all the files it depends on are located inside this directory.
Several required resources (e.g., model weights, results, FAISS index, dataset) are stored in the root directory of the project.
Make sure the entire project has been executed and all files are correctly placed before running the dashboard.
To launch the dashboard, run the following command from the project root directory:
python dashboard/app/app.pyBelow is the structure of the dashboard/ folder after running the full project:
dashboard/
│
├── app/
│ ├── pages/
│ │ ├── company_analysis.py
│ │ ├── eda.py
│ │ ├── homepage.py
│ │ ├── rag.py
│ │ ├── sentiment_model.py
│ │
│ ├── utils/
│ │ └── data_loader.py
│ │
│ └── app.py
│
├── data/
│ └── dashboard/
│ ├── balanced_dataset.csv
│ └── full_dataset.csv
│
└── .gitignore
app.py
Entry point of the dashboard application. It initializes and runs the interface.
Each file corresponds to a specific section of the dashboard:
-
homepage.py
Main landing page of the dashboard. -
eda.py
Contains the Exploratory Data Analysis visualizations. -
company_analysis.py
Provides sentiment-based analysis at the company level. -
sentiment_models.py
Displays model performance metrics and comparisons (BiLSTM and BERT models). -
rag.py
Implements the Retrieval-Augmented Generation (RAG) interface.
data_loader.pyHandles data loading and preprocessing for the dashboard.
-
balanced_dataset.csv
Balanced dataset used for visualization and analysis. -
full_dataset.csvComplete dataset used for exploratory analysis.
- Ensure that all project scripts have been executed before launching the dashboard.
- Verify that all required files are correctly positioned in their respective directories.
- Missing files may result in incomplete visualizations or runtime errors.
The RAG component is configured to use the following default model:
OLLAMA_MODEL = "llama3.1:8b"However, depending on the available hardware resources (especially GPU memory), this model may be too large to run. For this reason, a smaller alternative model has been included in the RAG script (RAG.py). Inside the file, you will find the following commented line:
# OLLAMA_MODEL = "qwen2:1.5b"If the default model cannot be executed due to hardware limitations, simply:
- comment out the
llama3.1:8bmodel - uncomment the
qwen2:1.5bmodel
The qwen2:1.5b model requires fewer computational resources and can be used on systems with limited GPU capacity.
- Lorenzo Galli
- Matteo Giuseppetti
- Gabriele Socrate
- Gabriele Trentin