How vedavyas0105/financial-sentiment-distillation works
Project Type and Purpose
• Type: A research-style NLP/ML pipeline implementing knowledge distillation for financial sentiment analysis.
• Purpose: Pre-train a compact student model (DistilBERT) to mimic a larger teacher model (FinBERT) on a financial-news dataset, with data augmentation, training, evaluation, and visualization.
(Implicit) File Structure
Although the repository shows only README.md and a notebook, the README references the following top-level scripts:
– train.py (training & distillation)
– evaluate.py (metrics calculation)
– Sentiment_Analysis.ipynb (interactive exploration)
A “data/” folder is implied for raw and augmented datasets.
Core Components
a. Data Ingestion & Preprocessing
• Raw financial‐news dataset (CSV/JSON)
• Data augmentation module (synonym replacement)
• Result: augmented training set
b. Teacher Model
• FinBERT (Hugging Face Transformers)
• Outputs “soft targets” (probability distributions)
c. Student Model
• DistilBERT encoder + layer norm + pooling + FC + softmax
• Learns from both hard labels and soft targets
d. Knowledge Distillation Engine
• Loss function = λ·KL-Divergence(teacher, student) + (1–λ)·CrossEntropy(student, labels)
• Implemented in train.py using PyTorch (or TensorFlow)
e. Training Pipeline
• Optimizer: Adam @ 5e-5
• Batch size 32, epochs 20, early stopping, LR scheduler
• Checkpointing & logging (e.g., TensorBoard)
f. Evaluation Module
• Confusion matrix, precision/recall/F1 (sklearn or custom)
• Accuracy & loss metrics
g. Visualization Module
• Matplotlib/Seaborn plots for training/validation curves and heatmaps
h. Deployment / Usage
• Scripts: train.py → student model artifact (.pt/.bin)
• evaluate.py → metrics report
• Notebook for ad-hoc analysis
Relationships & Data Flow
• Data Ingestion → Data Augmentation → Tokenization → Batching
• Batches → Teacher Model & Student Model in parallel
• Teacher logits + Student logits + Labels → Distillation Loss → Backprop into Student
• At epoch end → checkpoint student model → log metrics
• After training → Evaluate student model on validation/test splits
• Evaluation outputs → Visualization module → static plots
Architectural Patterns & Principles
• Modular pipeline: clear separation of data, models, training, and evaluation
• Plug-and-play models (any Hugging Face model can be swapped)
• Functional decomposition: each script/notebook handles one concern
• Use of callbacks for early stopping/LR scheduling (separation of training logic and control flow)
• CI-style reproducibility: configuration through CLI arguments or config files (implied)