deoleojr commited on
Commit
b869b24
·
verified ·
1 Parent(s): aeebfd1

Upload BART LoRA finance model

Browse files
README.md CHANGED
@@ -1,123 +1,202 @@
1
  ---
2
- license: apache-2.0
 
3
  ---
4
- # Financial Question Answering with BART + LoRA Fine-Tuning
5
 
6
- ## 1. Introduction
7
- This project focuses on financial question answering using recent news articles from trusted sources. Large language models (LLMs) often hallucinate or fail to produce factually grounded answers when it comes to domain-specific tasks like equity research. This is especially problematic in financial contexts where accuracy is critical. To address this, we fine-tuned the `facebook/bart-large-cnn` model using Low-Rank Adaptation (LoRA) on a custom financial QA dataset. After training, the model achieved a BLEU score of 0.218 and a ROUGE-L score of 0.431, significantly outperforming the base model and other comparison models.
8
 
9
- ## 2. Training Data
10
- The dataset comprises eight financial news articles sourced from platforms such as Moneycontrol, Bloomberg, CNBC, and Yahoo Finance. Texts were loaded using LangChain's `UnstructuredURLLoader` and chunked using `RecursiveCharacterTextSplitter`. We then manually constructed QA pairs based on these article chunks. The dataset was split into training and validation sets using an 80/20 ratio with a fixed random seed (`random_state=42`). The data was stored in `financial_train.csv` and `financial_test.csv`.
11
 
12
- ## 3. Training Method
13
- The chosen training method was LoRA (Low-Rank Adaptation), applied to the facebook/bart-large-cnn base model. LoRA was selected based on empirical results from prior experiments (mentioned in Step 1 rationale) where it consistently outperformed few-shot prompting and prompt tuning on metrics like BLEU, ROUGE-L, and Precision@1 for this financial QA task. It demonstrated better fluency, factual correctness, generalization to unseen questions (based on validation performance), and retention of pre-trained knowledge. LoRA's parameter efficiency was also a key advantage, allowing effective fine-tuning of a large model on limited data and computational resources.
14
 
15
- We chose LoRA fine-tuning after comparing its performance to prompt tuning. LoRA allows efficient adaptation of large models using low-rank updates, keeping most parameters frozen. We fine-tuned `facebook/bart-large-cnn` using the following configuration:
16
 
17
- - `r=8`, `lora_alpha=16`, `lora_dropout=0.1`
18
- - `task_type=SEQ_2_SEQ_LM`, `target_modules=["q_proj", "v_proj"]`
19
- - Learning rate: 2e-4
20
- - Epochs: 3
21
- - Batch size: 2 per device
22
 
23
- The model was trained using `Seq2SeqTrainer` with `load_best_model_at_end=True` and `evaluation_strategy="epoch"`.
24
 
25
- ## 4. Evaluation
26
- Evaluation focused on a custom financial question-answering task using the test/validation splits derived from the curated training data. The primary metrics used were BLEU (to assess n-gram overlap and fluency), ROUGE-L (to measure semantic similarity based on the longest common subsequence), and Precision@1 (to check if at least one relevant word from the reference answer was present in the prediction). These metrics were chosen to provide a quantitative measure of the model's ability to generate relevant, accurate, and well-formed answers based on the provided context. The base model (facebook/bart-large-cnn) was evaluated pre-training, and the LoRA-tuned model was evaluated post-training.
27
 
28
- We evaluated the model on three benchmark tasks:
29
- 1. **Financial QA Test Set** (custom dataset)
30
- 2. **GPT-2 Medium** (baseline)
31
- 3. **FLAN-T5 Small** (comparison model)
32
- 4. **BART-Large Base** (untuned version)
33
 
34
- ### Results Table
35
- | Task | Model | BLEU | ROUGE-L | Precision@1 |
36
- |-----------------------------|-------------------|-------|----------|--------------|
37
- | Financial QA Test Set | BART-Large (LoRA) | 0.218 | 0.431 | 1.000 |
38
- | Financial QA Test Set | BART-Large (Base) | 0.000 | 0.056 | 0.667 |
39
- | Financial QA Test Set | GPT-2 Medium | 0.049 | 0.201 | 0.778 |
40
- | Financial QA Test Set | FLAN-T5 Small | 0.117 | 0.305 | 0.889 |
41
 
42
- **Summary:** The LoRA-tuned BART-Large model consistently outperformed all comparison models across all metrics.
 
 
 
 
 
 
43
 
44
- ## 5. Usage and Intended Uses
45
- The model is intended for use in applications requiring question answering based on provided financial text, such as assisting equity research analysts, summarizing key points from news articles, or powering financial chatbots. It takes a question and a context passage as input and generates a concise answer based only on the information within that context.
46
- ```python
47
 
 
48
 
49
- import torch
50
- from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
51
- from peft import PeftModel, PeftConfig
52
 
53
- # Specify the path to your saved model repository on Hugging Face directory
54
- peft_model_path = ""deoleojr/bart-finance-lora""
55
- device = "cuda" if torch.cuda.is_available() else "cpu"
56
 
57
- # Load the configuration from the PEFT model path
58
- config = PeftConfig.from_pretrained(peft_model_path)
59
 
60
- # Load the base model
61
- base_model = AutoModelForSeq2SeqLM.from_pretrained(config.base_model_name_or_path).to(device)
62
 
63
- # Load the PEFT model (LoRA layers) on top of the base model
64
- model = PeftModel.from_pretrained(base_model, peft_model_path).to(device)
65
- model.eval() # Set model to evaluation mode
66
 
67
- # Load the tokenizer
68
- tokenizer = AutoTokenizer.from_pretrained(peft_model_path)
69
 
70
- # Example usage
71
- question = "What was the main reason for Tesla's stock rally?"
72
- context = "Tesla (TSLA.O) rallied 10% after Morgan Stanley upgraded the electric car maker to 'overweight' from 'equal-weight', saying its Dojo supercomputer could boost the company's market value by nearly $600 billion."
73
- prompt = f"Instruction: {question}\n\n[Context Information]\n{context}"
74
 
75
- inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512).to(device)
76
 
77
- with torch.no_grad():
78
- outputs = model.generate(
79
- **inputs,
80
- max_new_tokens=100,
81
- temperature=0.7,
82
- top_k=50,
83
- top_p=0.95,
84
- do_sample=True # Set to False for deterministic output if preferred
85
- )
86
 
87
- prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
88
- print(f"Question: {question}")
89
- print(f"Generated Answer: {prediction}")
90
- ```
91
- **Intended Use:** Financial analysts, researchers, or fintech developers needing factual QA over financial news articles. Not intended for real-time trading or automated financial advice.
92
 
93
- ## 6. Prompt Format
94
- The model expects prompts formatted with an "Instruction:" prefix for the question, followed by two newlines, the label "[Context Information]", a newline, and then the context text itself.
95
 
96
- ```
97
- Instruction: {question}
98
 
99
- [Context Information]
100
- {news_article_chunk}
101
 
 
102
 
103
- Instruction: What is the impact of AI on Tesla’s stock movement?
104
 
105
- [Context Information]
106
- Tesla (TSLA.O) rallied 10% after Morgan Stanley upgraded the electric car maker to "overweight" from "equal-weight". Morgan Stanley said Tesla's Dojo supercomputer could boost the company's market value by nearly $600 billion.
107
 
108
- ```
109
 
110
- ## 7. Expected Output Format
111
- The model outputs a single block of text representing the answer generated based on the provided question and context.
112
- ```
113
- A concise, fact-based answer derived from the provided context.
114
- Example:
115
- "Tesla's stock rose 10% after Morgan Stanley cited the potential of its Dojo supercomputer."
116
- ```
117
 
118
- ## 8. Limitations
119
- This model is trained on a limited set of eight news articles, which may restrict generalization to unseen financial domains. It is also susceptible to hallucination if the input lacks sufficient context. Furthermore, open-ended evaluation metrics like BLEU and ROUGE don't fully capture factual accuracy, so human evaluation or external fact-checking (e.g., via GPT-4) is still recommended for high-stakes applications.
120
 
121
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
 
 
123
 
 
 
1
  ---
2
+ base_model: facebook/bart-large-cnn
3
+ library_name: peft
4
  ---
 
5
 
6
+ # Model Card for Model ID
 
7
 
8
+ <!-- Provide a quick summary of what the model is/does. -->
 
9
 
 
 
10
 
 
11
 
12
+ ## Model Details
 
 
 
 
13
 
14
+ ### Model Description
15
 
16
+ <!-- Provide a longer summary of what this model is. -->
 
17
 
 
 
 
 
 
18
 
 
 
 
 
 
 
 
19
 
20
+ - **Developed by:** [More Information Needed]
21
+ - **Funded by [optional]:** [More Information Needed]
22
+ - **Shared by [optional]:** [More Information Needed]
23
+ - **Model type:** [More Information Needed]
24
+ - **Language(s) (NLP):** [More Information Needed]
25
+ - **License:** [More Information Needed]
26
+ - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
+ ### Model Sources [optional]
 
 
29
 
30
+ <!-- Provide the basic links for the model. -->
31
 
32
+ - **Repository:** [More Information Needed]
33
+ - **Paper [optional]:** [More Information Needed]
34
+ - **Demo [optional]:** [More Information Needed]
35
 
36
+ ## Uses
 
 
37
 
38
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
 
39
 
40
+ ### Direct Use
 
41
 
42
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
 
 
43
 
44
+ [More Information Needed]
 
45
 
46
+ ### Downstream Use [optional]
 
 
 
47
 
48
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
 
50
+ [More Information Needed]
 
 
 
 
 
 
 
 
51
 
52
+ ### Out-of-Scope Use
 
 
 
 
53
 
54
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
 
55
 
56
+ [More Information Needed]
 
57
 
58
+ ## Bias, Risks, and Limitations
 
59
 
60
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
 
62
+ [More Information Needed]
63
 
64
+ ### Recommendations
 
65
 
66
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
 
68
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
 
 
 
 
 
 
69
 
70
+ ## How to Get Started with the Model
 
71
 
72
+ Use the code below to get started with the model.
73
+
74
+ [More Information Needed]
75
+
76
+ ## Training Details
77
+
78
+ ### Training Data
79
+
80
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
+
82
+ [More Information Needed]
83
+
84
+ ### Training Procedure
85
+
86
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
+
88
+ #### Preprocessing [optional]
89
+
90
+ [More Information Needed]
91
+
92
+
93
+ #### Training Hyperparameters
94
+
95
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
+
97
+ #### Speeds, Sizes, Times [optional]
98
+
99
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
+
101
+ [More Information Needed]
102
+
103
+ ## Evaluation
104
+
105
+ <!-- This section describes the evaluation protocols and provides the results. -->
106
+
107
+ ### Testing Data, Factors & Metrics
108
+
109
+ #### Testing Data
110
+
111
+ <!-- This should link to a Dataset Card if possible. -->
112
+
113
+ [More Information Needed]
114
+
115
+ #### Factors
116
+
117
+ <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
+
119
+ [More Information Needed]
120
+
121
+ #### Metrics
122
+
123
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
+
125
+ [More Information Needed]
126
+
127
+ ### Results
128
+
129
+ [More Information Needed]
130
+
131
+ #### Summary
132
+
133
+
134
+
135
+ ## Model Examination [optional]
136
+
137
+ <!-- Relevant interpretability work for the model goes here -->
138
+
139
+ [More Information Needed]
140
+
141
+ ## Environmental Impact
142
+
143
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
+
145
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
+
147
+ - **Hardware Type:** [More Information Needed]
148
+ - **Hours used:** [More Information Needed]
149
+ - **Cloud Provider:** [More Information Needed]
150
+ - **Compute Region:** [More Information Needed]
151
+ - **Carbon Emitted:** [More Information Needed]
152
+
153
+ ## Technical Specifications [optional]
154
+
155
+ ### Model Architecture and Objective
156
+
157
+ [More Information Needed]
158
+
159
+ ### Compute Infrastructure
160
+
161
+ [More Information Needed]
162
+
163
+ #### Hardware
164
+
165
+ [More Information Needed]
166
+
167
+ #### Software
168
+
169
+ [More Information Needed]
170
+
171
+ ## Citation [optional]
172
+
173
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
+
175
+ **BibTeX:**
176
+
177
+ [More Information Needed]
178
+
179
+ **APA:**
180
+
181
+ [More Information Needed]
182
+
183
+ ## Glossary [optional]
184
+
185
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
+
187
+ [More Information Needed]
188
+
189
+ ## More Information [optional]
190
+
191
+ [More Information Needed]
192
+
193
+ ## Model Card Authors [optional]
194
+
195
+ [More Information Needed]
196
+
197
+ ## Model Card Contact
198
 
199
+ [More Information Needed]
200
+ ### Framework versions
201
 
202
+ - PEFT 0.14.0
adapter_config.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alpha_pattern": {},
3
+ "auto_mapping": null,
4
+ "base_model_name_or_path": "facebook/bart-large-cnn",
5
+ "bias": "none",
6
+ "eva_config": null,
7
+ "exclude_modules": null,
8
+ "fan_in_fan_out": false,
9
+ "inference_mode": true,
10
+ "init_lora_weights": true,
11
+ "layer_replication": null,
12
+ "layers_pattern": null,
13
+ "layers_to_transform": null,
14
+ "loftq_config": {},
15
+ "lora_alpha": 16,
16
+ "lora_bias": false,
17
+ "lora_dropout": 0.1,
18
+ "megatron_config": null,
19
+ "megatron_core": "megatron.core",
20
+ "modules_to_save": null,
21
+ "peft_type": "LORA",
22
+ "r": 8,
23
+ "rank_pattern": {},
24
+ "revision": null,
25
+ "target_modules": [
26
+ "q_proj",
27
+ "v_proj"
28
+ ],
29
+ "task_type": "SEQ_2_SEQ_LM",
30
+ "use_dora": false,
31
+ "use_rslora": false
32
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:955937c095f977679f96b8effaf925e0595af29bbea963d4a13ccfcc405dae2c
3
+ size 4738744
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
special_tokens_map.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "cls_token": "<s>",
4
+ "eos_token": "</s>",
5
+ "mask_token": {
6
+ "content": "<mask>",
7
+ "lstrip": true,
8
+ "normalized": true,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "pad_token": "</s>",
13
+ "sep_token": "</s>",
14
+ "unk_token": "<unk>"
15
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "0": {
5
+ "content": "<s>",
6
+ "lstrip": false,
7
+ "normalized": true,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "1": {
13
+ "content": "<pad>",
14
+ "lstrip": false,
15
+ "normalized": true,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "2": {
21
+ "content": "</s>",
22
+ "lstrip": false,
23
+ "normalized": true,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "3": {
29
+ "content": "<unk>",
30
+ "lstrip": false,
31
+ "normalized": true,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ },
36
+ "50264": {
37
+ "content": "<mask>",
38
+ "lstrip": true,
39
+ "normalized": true,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": true
43
+ }
44
+ },
45
+ "bos_token": "<s>",
46
+ "clean_up_tokenization_spaces": false,
47
+ "cls_token": "<s>",
48
+ "eos_token": "</s>",
49
+ "errors": "replace",
50
+ "extra_special_tokens": {},
51
+ "mask_token": "<mask>",
52
+ "model_max_length": 1000000000000000019884624838656,
53
+ "pad_token": "</s>",
54
+ "sep_token": "</s>",
55
+ "tokenizer_class": "BartTokenizer",
56
+ "trim_offsets": true,
57
+ "unk_token": "<unk>"
58
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:effe253ae3437ff7bacb3654d592ac9f0855b840855638fa3748183202727d95
3
+ size 5432
vocab.json ADDED
The diff for this file is too large to render. See raw diff