Downloads · 30 days
0
Karthikeyan-M3011/llama2-fin-summarizer
llama2-fin-summarizer is a text generation model from Karthikeyan-M3011. Use it when you need the model to write or continue text.
This is a fine-tuned version of the LLaMA2 7B model, quantized to 4-bit precision, specifically trained for financial text summarization. The model was fine-tuned on a custom dataset of 200+ large financial documents,…
Downloads · 30 days
0
Access
Public
Updated Aug 14, 2024
Repo size
67.6 MB
Likes
0
Public
Click a slice to open those files.
.safetensors67.1 MB · 97%
From the Hugging Face model README
This is a fine-tuned version of the LLaMA2 7B model, quantized to 4-bit precision, specifically trained for financial text summarization. The model was fine-tuned on a custom dataset of 200+ large financial documents, allowing it to generate concise and accurate summaries of financial reports, articles, and other related documents.
To use this model, you need to install the required Python libraries:
pip install accelerate peft bitsandbytes git+https://github.com/huggingface/transformers py7zr
from peft import AutoPeftModelForCausalLM
from transformers import AutoTokenizer
import torch
peft_model_dir = "Karthikeyan-M3011/llama2-fin-summarizer"
trained_model = AutoPeftModelForCausalLM.from_pretrained(
peft_model_dir,
low_cpu_mem_usage=True,
torch_dtype=torch.float16,
load_in_4bit=True,
)
tokenizer = AutoTokenizer.from_pretrained(peft_model_dir)
query = 'Your text to summarize'
dialogue = query[:10000] # max tokens allowed
prompt = f"""
Summarize the following conversation.
### Input:
{dialogue}
### Summary:
"""
input_ids = tokenizer(prompt, return_tensors='pt', truncation=True).input_ids.cuda()
outputs = trained_model.generate(input_ids=input_ids, max_new_tokens=200)
output = tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0][len(prompt):]
dash_line = '-' * 100
print(dash_line)
print(f'INPUT PROMPT:\n{prompt}')
print(dash_line)
print(f'TRAINED MODEL GENERATED TEXT:\n{output}')
The model was fine-tuned using the following training parameters:
from transformers import TrainingArguments
training_arguments = TrainingArguments(
per_device_train_batch_size=4,
gradient_accumulation_steps=4,
optim="paged_adamw_32bit",
logging_steps=1,
learning_rate=1e-4,
fp16=True,
max_grad_norm=0.3,
num_train_epochs=4,
evaluation_strategy="steps",
eval_steps=0.2,
warmup_ratio=0.05,
save_strategy="epoch",
group_by_length=True,
output_dir=OUTPUT_DIR,
report_to="tensorboard",
save_safetensors=True,
lr_scheduler_type="cosine",
seed=42,
)
model.config.use_cache = False
from trl import SFTTrainer
trainer = SFTTrainer(
model=model,
train_dataset=train_data,
eval_dataset=validation_data,
peft_config=lora_config,
dataset_text_field="text",
max_seq_length=1024,
tokenizer=tokenizer,
args=training_arguments,
)
trainer.train()
If you use this model in your research or applications, please cite it as follows:
@misc{llama2-fin-summarizer,
publisher = {Karthikeyan M},
title = {Fine-tuned LLaMA2 7B Model for Financial Summarization},
year = {2024},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/Karthikeyan-M3011/llama2-fin-summarizer}},
}