Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Text-Mining- Financial News Sentiment Analysis

Table of Contents

Project Overview

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".

Setup Instructions

To ensure the correct execution of all project components and to avoid potential errors during setup and runtime, please follow the steps below carefully.

Environment Setup

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

Working Directory

Before running any script or notebook, make sure to navigate to the root directory of the project.

Dependency Installation

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.txt

1. Data Loading and Cleaning

See notebook: 1.Dataset_loading_cleaning.ipynb

2. BiLSTM

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.

3. Bert Models

See notebook: 3.Bert_Models.ipynb

DistilBert fine-tuning:

  • transformers model which was pretrained by knowledge distillation using BERT as foundational model.

FinBert feature extraction:

  • pre-trained model to analyze sentiment of financial text, built by further training the BERT language model in the finance domain.

Bert base fine-tuning:

  • transformers model pretrained on generic data, considered a foundational model for sequence classification, token classification or question answering tasks.

4. RAG

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.

5. Interactive Dashboard

Introduction

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.

Important Note

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.

Running the Dashboard

To launch the dashboard, run the following command from the project root directory:

python dashboard/app/app.py

Dashboard Structure (After Full Execution)

Below 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

File Description

Main Application

  • app.py
    Entry point of the dashboard application. It initializes and runs the interface.

Pages (app/pages/)

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.

Utilities (app/utils/)

  • data_loader.py Handles data loading and preprocessing for the dashboard.

Data (data/dashboard/)

Notes

  • 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.

Attention

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:8b model
  • uncomment the qwen2:1.5b model

The qwen2:1.5b model requires fewer computational resources and can be used on systems with limited GPU capacity.

Contributors

  • Lorenzo Galli
  • Matteo Giuseppetti
  • Gabriele Socrate
  • Gabriele Trentin

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages