CoolFace
Modelpublic

jhon53/Llama3_1_8B_Finance_QLoRA-merged-16bit

sourceHugging Faceapache-2.0updated 4d agoView on Hugging Face
2likes227downloads
Model Card

Llama 3.1 8B Financial Sentiment — QLoRA

<p align="center"> <img src="thumbnail.png" alt="Llama 3.1 8B Financial Sentiment QLoRA" width="100%"> </p>

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

MetricBase ModelFine-Tuned
FPB Accuracy89.08%97.48%
FPB Macro-F187.65%97.25%
FiQA-SA Accuracy81.20%94.02%
FiQA-SA Macro-F167.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

ParameterValue
Base modelmeta-llama/Meta-Llama-3.1-8B-Instruct
MethodQLoRA (4-bit NF4 + BF16 LoRA)
LoRA rank16
LoRA alpha32
LoRA dropout0.05
Target modulesq, k, v, o, gate, up, down projections
OptimizerAdamW 8-bit
Learning rate2e-4
SchedulerCosine
Epochs3
Early stoppingPatience = 3
LossCompletion-only cross-entropy

Quick Start

Transformers

python
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

python
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)

ModelAccuracyMacro-F1
Base0.89080.8765
Fine-tuned0.97480.9725

FiQA-SA (Out-of-Domain)

ModelAccuracyMacro-F1
Base0.81200.6705
Fine-tuned0.94020.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:

text
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