Downloads · 30 days
10
2% of all-time downloads
sgzsh269/fingpt-sentiment_llama2-13b_merged
fingpt-sentiment_llama2-13b_merged is a text generation model from sgzsh269. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as mit.
This model is a merge of the following models: - Base Model: NousResearch/Llama-2-13b-hf - LoRA Model: FinGPT/fingpt-sentimentllama2-13blora
Downloads · 30 days
10
2% of all-time downloads
All-time downloads
631
Public
Parameters
13B
26 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors26 GB · 100%
From the Hugging Face model README
This model is a merge of the following models:
Primary Usecase: Financial Sentiment Analysis
The base model was dequantized before merging to retain the performance of base model + LoRA adapter. Check the below resources for more details:
import torch
import os
from transformers import AutoModelForCausalLM, AutoTokenizer, LlamaForCausalLM
from peft import PeftModel
base_model_name = "NousResearch/Llama-2-13b-hf"
peft_model_name = "FinGPT/fingpt-sentiment_llama2-13b_lora"
output_path = "merged_model"
model = AutoModelForCausalLM.from_pretrained(
base_model_name,
device_map="auto",
load_in_8bit=True
)
# Dequantize base model weights to match precision of LoRA weights
model.dequantize()
model = PeftModel.from_pretrained(model, peft_model_name)
merged_model = model.merge_and_unload()
merged_model.save_pretrained(output_path)
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
tokenizer.save_pretrained(output_path)
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
device = "cuda" if torch.cuda.is_available() else "cpu"
model_path = "sgzsh269/fingpt-sentiment_llama2-13b_merged"
model = AutoModelForCausalLM.from_pretrained(
model_path,
device_map=device,
torch_dtype=torch.float16
)
tokenizer = AutoTokenizer.from_pretrained(model_path)
tokenizer.pad_token = tokenizer.eos_token
model.eval()
prompts = [
'''Instruction: What is the sentiment of this news? Please choose an answer from {negative/neutral/positive}
Input: FINANCING OF ASPOCOMP 'S GROWTH Aspocomp is aggressively pursuing its growth strategy by increasingly focusing on technologically more demanding HDI printed circuit boards PCBs .
Answer: ''',
'''Instruction: What is the sentiment of this news? Please choose an answer from {negative/neutral/positive}
Input: According to Gran , the company has no plans to move all production to Russia , although that is where the company is growing .
Answer: ''',
'''Instruction: What is the sentiment of this news? Please choose an answer from {negative/neutral/positive}
Input: A tinyurl link takes users to a scamming site promising that users can earn thousands of dollars by becoming a Google ( NASDAQ : GOOG ) Cash advertiser .
Answer: ''',
]
model_inputs = tokenizer(prompts, return_tensors='pt', padding=True).to(device)
with torch.no_grad():
generated_ids = model.generate(**model_inputs, max_length=512)
output_ids = generated_ids[:, model_inputs.input_ids.shape[1]:].tolist()
output_texts = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
print(output_texts) # Expected: ['positive', 'neutral', 'negative']