đ Finance-Llama-8B
This model is a fine - tuned version of unsloth/Meta - Llama-3.1-8B
on the Josephgflowers/Finance-Instruct-500k
dataset. It's designed for financial tasks, reasoning, and multi - turn conversations.
đ Quick Start
This model can be used with the transformers
library pipeline for text generation.
First, make sure you have the transformers
and torch
libraries installed:
pip install transformers torch
⨠Features
- Extensive Coverage: Trained on over 500,000 entries spanning financial QA, reasoning, sentiment analysis, topic classification, multilingual NER, and conversational AI.
- Multi - Turn Conversations: Capable of rich dialogues emphasizing contextual understanding and reasoning.
- Diverse Data Sources: Includes entries from Cinder, Sujet - Finance - Instruct - 177k, Phinance Dataset, BAAI/IndustryInstruction_Finance - Economics, Josephgflowers/Financial - NER - NLP, and many other high - quality datasets.
- Financial Specialization: Tailored for financial reasoning, question answering, entity recognition, sentiment analysis, and more.
đ Documentation
Finance-Instruct-500k Dataset
Overview
Finance - Instruct - 500k is a comprehensive and meticulously curated dataset designed to train advanced language models for financial tasks, reasoning, and multi - turn conversations. Combining data from numerous high - quality financial datasets, this corpus provides over 500,000 entries, offering unparalleled depth and versatility for finance - related instruction tuning and fine - tuning.
The dataset includes content tailored for financial reasoning, question answering, entity recognition, sentiment analysis, address parsing, and multilingual natural language processing (NLP). Its diverse and deduplicated entries make it suitable for a wide range of financial AI applications, including domain - specific assistants, conversational agents, and information extraction systems.
Key Features of the Dataset
- Extensive Coverage: Over 500,000 entries spanning financial QA, reasoning, sentiment analysis, topic classification, multilingual NER, and conversational AI.
- Multi - Turn Conversations: Rich dialogues emphasizing contextual understanding and reasoning.
- Diverse Data Sources: Includes entries from Cinder, Sujet - Finance - Instruct - 177k, Phinance Dataset, BAAI/IndustryInstruction_Finance - Economics, Josephgflowers/Financial - NER - NLP, and many other high - quality datasets.
đģ Usage Examples
Basic Usage
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
import torch
model_id = "tarun7r/Finance-Llama-8B"
print("Loading model with memory optimizations...")
try:
print("Trying FP16 loading...")
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.float16,
device_map="auto",
low_cpu_mem_usage=True,
trust_remote_code=True
)
print("â Model loaded with FP16")
except Exception as e:
print(f"FP16 loading failed: {e}")
try:
print("Trying CPU offloading...")
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.float16,
device_map="balanced",
low_cpu_mem_usage=True,
trust_remote_code=True
)
print("â Model loaded with CPU offloading")
except Exception as e:
print(f"CPU offloading failed: {e}")
print("Loading on CPU...")
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.float16,
device_map="cpu",
low_cpu_mem_usage=True,
trust_remote_code=True
)
print("â Model loaded on CPU")
tokenizer = AutoTokenizer.from_pretrained(model_id)
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token
generator = pipeline(
"text-generation",
model=model,
tokenizer=tokenizer
)
print("â Pipeline created successfully!")
finance_prompt_template = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
### Instruction:
{}
### Input:
{}
### Response:
"""
messages = [
{"role": "system", "content": "You are a highly knowledgeable finance chatbot. Your purpose is to provide accurate, insightful, and actionable financial advice to users, tailored to their specific needs and contexts."},
{"role": "user", "content": "What strategies can an individual investor use to diversify their portfolio effectively in a volatile market?"},
]
prompt = "\n".join([f"{msg['role'].capitalize()}: {msg['content']}" for msg in messages])
print("\n--- Generating Response ---")
try:
outputs = generator(
prompt,
do_sample=True,
temperature=0.7,
top_p=0.9,
pad_token_id=tokenizer.eos_token_id,
num_beams=1,
early_stopping=True,
use_cache=True
)
generated_text = outputs[0]['generated_text']
response_start = generated_text.rfind("### Response:")
if response_start != -1:
response = generated_text[response_start + len("### Response:"):].strip()
print("\n--- Response ---")
print(response)
else:
print(generated_text)
if torch.cuda.is_available():
torch.cuda.empty_cache()
except Exception as e:
print(f"Generation error: {e}")
Citation
@misc{tarun7r/Finance-Llama-8B,
author = {tarun7r},
title = {tarun7r/Finance-Llama-8B: A Llama 3.1 8B Model Fine-tuned on Josephgflowers/Finance-Instruct-500k},
year = {2025},
publisher = {Hugging Face},
journal = {Hugging Face Model Hub},
howpublished = {\url{https://huggingface.co/tarun7r/Finance-Llama-8B}}
}
đ License
This project is under the Apache - 2.0 license.
đĻ Information
Property |
Details |
Model Type |
Fine - tuned version of unsloth/Meta-Llama-3.1-8B |
Training Data |
Josephgflowers/Finance-Instruct-500k |
Pipeline Tag |
text - generation |
Library Name |
transformers |