Romeo777777 commited on
Commit
4ea2e77
·
verified ·
1 Parent(s): b19c715

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +155 -0
README.md ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: apache-2.0
4
+ tags:
5
+ - finance
6
+ - sentiment-analysis
7
+ - text-classification
8
+ - llama
9
+ - qlora
10
+ pipeline_tag: text-classification
11
+ library_name: transformers
12
+ ---
13
+
14
+ # Llama Sentiment Classifier (QLoRA Fine-Tuned)
15
+
16
+ This repository provides a **LLaMA-based financial sentiment classifier** fine-tuned using **QLoRA** for **3-class sentiment classification** on finance-domain text. The model is designed for downstream applications including **sentiment-driven alpha signal generation** and market-neutral trading strategies.
17
+
18
+ ---
19
+
20
+ ## Model Summary
21
+
22
+ - **Backbone**: Meta-LLaMA3-8B
23
+ - **Task**: Financial sentiment classification (3 classes)
24
+ - **Fine-tuning method**: **QLoRA** (4-bit quantization + LoRA adapters)
25
+ - **Training framework**: **SWIFT** (Scalable lightWeight Infrastructure for Fine-Tuning)
26
+ - **Architecture**: LlamaForSequenceClassification
27
+
28
+ ---
29
+
30
+ ## Labels
31
+
32
+ This model performs **single-label classification** into 3 discrete classes.
33
+
34
+ In the paper, the unified sentiment label space is:
35
+
36
+ - **-1** = Negative
37
+ - **0** = Neutral
38
+ - **1** = Positive
39
+
40
+ > Note: your Hugging Face config may show `LABEL_0`, `LABEL_1`, `LABEL_2`.
41
+
42
+ ---
43
+
44
+ ## Datasets
45
+
46
+ ### Part 1 — Fine-tuning datasets (4 sources)
47
+
48
+ Training uses 4 finance-domain sentiment datasets:
49
+
50
+ 1. **Financial PhraseBank v1.0**
51
+ - 4,840 manually annotated sentences
52
+ - 3-class sentiment (positive/neutral/negative)
53
+
54
+ 2. **NASDAQ News Sentiment**
55
+ - synthetic sentiment dataset generated using GPT-4o
56
+ - labeled into positive/neutral/negative
57
+
58
+ 3. **Twitter Financial News Sentiment**
59
+ - 11,932 finance-related tweets
60
+ - original label encoding: 0 bearish, 1 bullish, 2 neutral
61
+
62
+ 4. **FIQA2018 (FiQA)**
63
+ - financial opinion mining dataset
64
+ - sentiment score in [-1, 1] (continuous), then discretized
65
+
66
+ ---
67
+
68
+ ### Part 2 — Real-world news evaluation dataset
69
+
70
+ For downstream evaluation and trading strategy experiments, the paper uses a news + price dataset covering:
71
+
72
+ - **502 S&P 500 companies**
73
+ - **~77,000 news headlines**
74
+ - time range: **2024-01-01 to 2025-05-30**
75
+
76
+ ---
77
+
78
+ ## Preprocessing
79
+
80
+ ### Label normalization (unified mapping)
81
+
82
+ All datasets are standardized into the unified label space: {-1, 0, 1}.
83
+
84
+ Mapping rules:
85
+
86
+ - **Financial PhraseBank**:
87
+ `"negative" → -1`, `"neutral" → 0`, `"positive" → 1`
88
+
89
+ - **FIQA2018** (score in [-1, 1]):
90
+ `< -0.2 → -1`, `> 0.2 → 1`, otherwise `0`
91
+
92
+ - **Twitter Financial Sentiment**:
93
+ `0 → -1`, `2 → 0`, `1 → 1`
94
+
95
+ - **NASDAQ News** (0~5 score):
96
+ `<= 1 → -1`, `>= 4 → 1`, otherwise `0`
97
+
98
+ ### Tokenization
99
+
100
+ Uses the official **LLaMA 3 tokenizer**.
101
+
102
+ ---
103
+
104
+ ## Training Method
105
+
106
+ ### QLoRA fine-tuning
107
+
108
+ The model is fine-tuned with **QLoRA**, which keeps the backbone weights in 4-bit quantized form and trains LoRA adapters in higher precision.
109
+
110
+ The paper’s QLoRA setup includes NF4 quantization + double quantization for memory efficiency.
111
+
112
+ ### SWIFT training framework
113
+
114
+ Fine-tuning is orchestrated using **SWIFT**, a modular training framework that simplifies adapter integration and efficient training for quantized models.
115
+
116
+ ---
117
+
118
+ ## Hyperparameters (paper)
119
+
120
+ - LoRA rank **r = 16**
121
+ - LoRA alpha **= 32**
122
+ - LoRA dropout **= 0.1**
123
+ - learning rate **1e-4**, optimizer **AdamW**
124
+ - batch size **8**, epochs **1**
125
+ - gradient accumulation **4**
126
+ - gradient checkpointing enabled
127
+ - cosine learning rate schedule
128
+
129
+ ---
130
+
131
+ ## Evaluation Results (paper)
132
+
133
+ On a test set of **9,064** finance news samples, the fine-tuned model reports:
134
+
135
+ - **Accuracy**: **92.18%**
136
+ - **Micro-F1**: **0.9218**
137
+ - **Macro-F1**: **0.5787**
138
+
139
+ Class-wise performance highlights strong **Positive** and **Neutral** performance, but weaker **Negative** performance due to class imbalance.
140
+
141
+ ---
142
+
143
+ ## Usage
144
+
145
+ ```python
146
+ from transformers import pipeline
147
+
148
+ clf = pipeline(
149
+ "text-classification",
150
+ model="Romeo777777/Llama_Sentiment_Classifier",
151
+ tokenizer="Romeo777777/Llama_Sentiment_Classifier",
152
+ return_all_scores=True,
153
+ )
154
+
155
+ print(clf("Bitcoin is pumping hard today!"))