You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
frompeftimportPeftModel, PeftConfigfromtransformersimportLlamaForCausalLM, LlamaTokenizerFast# Load Modelsbase_model="daryl149/llama-2-13b-chat-hf"peft_model="oliverwang15/FinGPT_v11_Llama2_13B_Sentiment_Market_Feedback_LoRA_FT_8bit"tokenizer=LlamaTokenizerFast.from_pretrained(base_model, trust_remote_code=True)
tokenizer.pad_token=tokenizer.eos_tokenmodel=LlamaForCausalLM.from_pretrained(base_model, trust_remote_code=True, device_map="cuda:0", load_in_8bit=True,)
model=PeftModel.from_pretrained(model, peft_model)
model=model.eval()
# Make prompts# Please change the news to the news you wantnews='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'template="""News: '''{}'''Instruction: Please 'ONLY' output 'one' sentiment of all the above News from {{ Severely Positive / Moderately Positive / Mildly Positive / Neutral / Mildly Negative / Moderately Negative / Severely Negative }} without other words.Answer:"""prompt=template.format(mews)
# Generate resultstokens=tokenizer(prompt, return_tensors='pt', padding=True)
tokens=tokens.to(model.device)
withtorch.no_grad():
res=model.generate(**tokens, max_length=1024)
torch.cuda.empty_cache()
res_sentences= [tokenizer.decode(i, skip_special_tokens=True) foriinres]
out_text= [o.split("Answer:")[1] foroinres_sentences]
sentiment=out_text[0].strip()
print(sentiment)
# Severely Negative
Ⅰ. What is FinGPT-V1 series
FinGPT-V1 is a series of LoRA model for financial sentiment analysis whose labels are generated by the change of market (stock price).
You can also say these models are analyzing or predicting the market through related alternative data (news, social media, filings, etc,).
Ⅱ. Why label by the market
Labeling has always been a big issue in the ever-changing financial market, labeling by the market is more efficient and economic than human labor (not necessarily better).
Human's opinion on the market is sometimes biased. Since our final goal is to analyze or predict the market, why not let the model learn directly from the market.