Update README.md
Browse files
README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
| 5 |
|
| 6 |
This project explores the task of financial question answering, specifically focusing on generating answers based on provided context snippets, often simulating Retrieval-Augmented Generation (RAG) scenarios. Accurate information extraction is crucial in finance, but LLMs can sometimes struggle with domain-specific factuality.
|
| 7 |
|
| 8 |
-
To address this, we fine-tuned the `facebook/bart-large-cnn` model using Low-Rank Adaptation (LoRA) on a
|
| 9 |
|
| 10 |
Post-training benchmarks using an LLM-as-Judge approach (Gemini) and attempted evaluations with RAG-specific frameworks (like Ragas) indicated **mixed results**. While fine-tuning potentially **improved the model's faithfulness** (generating answers more consistent with the provided context), it **did not show clear improvements in answer relevancy or overall quality scores** compared to the baseline model, and may have slightly decreased performance in these areas for some examples. Automated RAG benchmarks further highlighted challenges with context retrieval precision in the experimental setup.
|
| 11 |
|
|
@@ -151,73 +151,6 @@ with torch.no_grad():
|
|
| 151 |
print(f"\nQuestion: {question}")
|
| 152 |
print(f"Generated Answer: {prediction}")
|
| 153 |
```
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
## 4. Evaluation
|
| 157 |
-
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.
|
| 158 |
-
|
| 159 |
-
We evaluated the model on three benchmark tasks:
|
| 160 |
-
1. **Financial QA Test Set** (custom dataset)
|
| 161 |
-
2. **GPT-2 Medium** (baseline)
|
| 162 |
-
3. **FLAN-T5 Small** (comparison model)
|
| 163 |
-
4. **BART-Large Base** (untuned version)
|
| 164 |
-
|
| 165 |
-
### Results Table
|
| 166 |
-
| Task | Model | BLEU | ROUGE-L | Precision@1 |
|
| 167 |
-
|-----------------------------|-------------------|-------|----------|--------------|
|
| 168 |
-
| Financial QA Test Set | BART-Large (LoRA) | 0.854 | 0.899 | 1.000 |
|
| 169 |
-
| Financial QA Test Set | BART-Large (Base) | 0.000 | 0.118 | 0.000 |
|
| 170 |
-
| Financial QA Test Set | GPT-2 Medium | 0.049 | 0.201 | 0.778 |
|
| 171 |
-
| Financial QA Test Set | FLAN-T5 Small | 0.117 | 0.305 | 0.889 |
|
| 172 |
-
|
| 173 |
-
**Summary:** The LoRA-tuned BART-Large model consistently outperformed all comparison models across all metrics.
|
| 174 |
-
|
| 175 |
-
## 5. Usage and Intended Uses
|
| 176 |
-
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.
|
| 177 |
-
```python
|
| 178 |
-
|
| 179 |
-
import torch
|
| 180 |
-
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
| 181 |
-
from peft import PeftModel, PeftConfig
|
| 182 |
-
|
| 183 |
-
# Specify the path to your saved model repository on Hugging Face or local directory
|
| 184 |
-
peft_model_path = "deoleojr/bart-finance-lora"
|
| 185 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 186 |
-
|
| 187 |
-
# Load the configuration from the PEFT model path
|
| 188 |
-
config = PeftConfig.from_pretrained(peft_model_path)
|
| 189 |
-
|
| 190 |
-
# Load the base model
|
| 191 |
-
base_model = AutoModelForSeq2SeqLM.from_pretrained(config.base_model_name_or_path).to(device)
|
| 192 |
-
|
| 193 |
-
# Load the PEFT model (LoRA layers) on top of the base model
|
| 194 |
-
model = PeftModel.from_pretrained(base_model, peft_model_path).to(device)
|
| 195 |
-
model.eval() # Set model to evaluation mode
|
| 196 |
-
|
| 197 |
-
# Load the tokenizer
|
| 198 |
-
tokenizer = AutoTokenizer.from_pretrained(peft_model_path)
|
| 199 |
-
|
| 200 |
-
# Example usage
|
| 201 |
-
question = "What was the main reason for Tesla's stock rally?"
|
| 202 |
-
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."
|
| 203 |
-
prompt = f"Instruction: {question}\n\n[Context Information]\n{context}"
|
| 204 |
-
|
| 205 |
-
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512).to(device)
|
| 206 |
-
|
| 207 |
-
with torch.no_grad():
|
| 208 |
-
outputs = model.generate(
|
| 209 |
-
**inputs,
|
| 210 |
-
max_new_tokens=100,
|
| 211 |
-
temperature=0.7,
|
| 212 |
-
top_k=50,
|
| 213 |
-
top_p=0.95,
|
| 214 |
-
do_sample=True # Set to False for deterministic output if preferred
|
| 215 |
-
)
|
| 216 |
-
|
| 217 |
-
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
|
| 218 |
-
print(f"Question: {question}")
|
| 219 |
-
print(f"Generated Answer: {prediction}")
|
| 220 |
-
```
|
| 221 |
**Intended Use:** Primarily for offline analysis or integration into systems where context is supplied alongside the question. Suitable for assisting financial analysts or researchers needing fact extraction from specific texts. Not intended for real-time trading decisions or fully automated financial advice due to limitations.
|
| 222 |
|
| 223 |
|
|
|
|
| 5 |
|
| 6 |
This project explores the task of financial question answering, specifically focusing on generating answers based on provided context snippets, often simulating Retrieval-Augmented Generation (RAG) scenarios. Accurate information extraction is crucial in finance, but LLMs can sometimes struggle with domain-specific factuality.
|
| 7 |
|
| 8 |
+
To address this, we fine-tuned the `facebook/bart-large-cnn` model using Low-Rank Adaptation (LoRA) on a financial QA dataset derived from financial_phrasebank. The goal was to improve the model's ability to generate concise, contextually grounded answers.
|
| 9 |
|
| 10 |
Post-training benchmarks using an LLM-as-Judge approach (Gemini) and attempted evaluations with RAG-specific frameworks (like Ragas) indicated **mixed results**. While fine-tuning potentially **improved the model's faithfulness** (generating answers more consistent with the provided context), it **did not show clear improvements in answer relevancy or overall quality scores** compared to the baseline model, and may have slightly decreased performance in these areas for some examples. Automated RAG benchmarks further highlighted challenges with context retrieval precision in the experimental setup.
|
| 11 |
|
|
|
|
| 151 |
print(f"\nQuestion: {question}")
|
| 152 |
print(f"Generated Answer: {prediction}")
|
| 153 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
**Intended Use:** Primarily for offline analysis or integration into systems where context is supplied alongside the question. Suitable for assisting financial analysts or researchers needing fact extraction from specific texts. Not intended for real-time trading decisions or fully automated financial advice due to limitations.
|
| 155 |
|
| 156 |
|