v2 stacks training on
NOSIBLE Financial Sentiment
(100K examples) on top of
v1
which was trained on
Financial PhraseBank.
1from transformers import AutoTokenizer, AutoModelForCausalLM
2from peft import PeftModel
3import torch
4
5tokenizer = AutoTokenizer.from_pretrained("poseidon1113/gpt2-lora-financial-sentiment-v2")
6model = PeftModel.from_pretrained(
7 AutoModelForCausalLM.from_pretrained("gpt2", torch_dtype=torch.float16),
8 "poseidon1113/gpt2-lora-financial-sentiment-v2"
9).eval()
10
11def predict(sentence):
12 inputs = tokenizer(f"### Sentence:\n{sentence}\n\n### Sentiment:\n", return_tensors="pt")
13 with torch.no_grad():
14 out = model.generate(**inputs, max_new_tokens=10, do_sample=False,
15 pad_token_id=tokenizer.eos_token_id)
16 result = tokenizer.decode(out[0][inputs["input_ids"].shape[1]:],
17 skip_special_tokens=True).strip().lower()
18 return next((w for w in result.split() if w in ("positive", "negative", "neutral")), "neutral")
19
20predict("Operating profit rose to EUR 13.1 mn from EUR 21.1 mn.") # → positive
21predict("The company reported a loss for the third consecutive quarter.") # → negative
1@article{Malo2014GoodDO,
2 title={Good Debt or Bad Debt: Detecting Semantic Orientations in Economic Texts},
3 author={P. Malo and A. Sinha and P. Korhonen and J. Wallenius and P. Virtanen},
4 journal={Journal of the Association for Information Science and Technology},
5 year={2014}, volume={65}
6}