Llama 3.1 8B Financial Sentiment — QLoRA
A finance-domain fine-tuned Llama 3.1 8B Instruct model for 3-class financial sentiment classification: negative, neutral, and positive.
The model was fine-tuned with QLoRA, using a 4-bit NF4 frozen base model and BF16 LoRA adapters.
Highlights
| Metric | Base Model | Fine-Tuned |
|---|---|---|
| FPB Accuracy | 89.08% | 97.48% |
| FPB Macro-F1 | 87.65% | 97.25% |
| FiQA-SA Accuracy | 81.20% | 94.02% |
| FiQA-SA Macro-F1 | 67.05% | 83.35% |
- Base:
meta-llama/Meta-Llama-3.1-8B-Instruct - Fine-tuning: QLoRA
- Quantization: 4-bit NF4 during adapter training
- Adapter: LoRA, BF16
- Task: Financial sentiment classification
- Training data:
FinGPT/fingpt-sentiment-train(~76k examples) - License: Apache 2.0
Evaluation compares the fine-tuned model against a zero-shot Meta-Llama-3.1-8B-Instruct baseline using the same prompt template.
Model Details
| Parameter | Value |
|---|---|
| Base model | meta-llama/Meta-Llama-3.1-8B-Instruct |
| Method | QLoRA (4-bit NF4 + BF16 LoRA) |
| LoRA rank | 16 |
| LoRA alpha | 32 |
| LoRA dropout | 0.05 |
| Target modules | q, k, v, o, gate, up, down projections |
| Optimizer | AdamW 8-bit |
| Learning rate | 2e-4 |
| Scheduler | Cosine |
| Epochs | 3 |
| Early stopping | Patience = 3 |
| Loss | Completion-only cross-entropy |
Quick Start
Transformers
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_id = "jhon53/Llama3_1_8B_Finance_QLoRA-merged-16bit"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "user",
"content": "The company's quarterly earnings exceeded analyst expectations. "
"The stock price increased following the announcement."
}
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=50,
do_sample=False,
)
response = tokenizer.decode(
outputs[0][inputs["input_ids"].shape[-1]:],
skip_special_tokens=True,
)
print(response)
Pipeline
from transformers import pipeline
pipe = pipeline(
"text-generation",
model="jhon53/Llama3_1_8B_Finance_QLoRA-merged-16bit",
)
messages = [
{
"role": "user",
"content": "The company reported record revenue and strong quarterly growth."
}
]
output = pipe(messages)
print(output)
Intended Use
This model is intended for:
- Financial sentiment analysis
- Research and experimentation with finance-focused LLMs
- Classification of financial news, statements, and market-related text
- Building finance-oriented NLP and GenAI applications
For production financial decision-making, outputs should be independently validated and should not be treated as financial advice.
Limitations
- Model performance depends on the domain and wording of the input.
- Financial language can be ambiguous and context-dependent.
- Benchmark performance does not guarantee production performance.
- The model may produce incorrect or overconfident classifications.
- Human review and application-specific evaluation are recommended for high-impact use cases.
Evaluation
Financial PhraseBank (FPB)
| Model | Accuracy | Macro-F1 |
|---|---|---|
| Base | 0.8908 | 0.8765 |
| Fine-tuned | 0.9748 | 0.9725 |
FiQA-SA (Out-of-Domain)
| Model | Accuracy | Macro-F1 |
|---|---|---|
| Base | 0.8120 | 0.6705 |
| Fine-tuned | 0.9402 | 0.8335 |
Related Models
- QLoRA adapters:
jhon53/Llama3_1_8B_Finance_QLoRA - GGUF version:
jhon53/Llama3_1_8B_Finance_QLoRA-GGUF
Citation
If you use this model in your research or project, please reference the Hugging Face repository:
jhon53/Llama3_1_8B_Finance_QLoRA-merged-16bit
Author
Dharmik Bhingradiya
AI/ML Engineer focused on LLM fine-tuning, RAG, model evaluation, MLOps, and production AI systems.
Hugging Face: https://huggingface.co/jhon53