Views
No views yet
FinBERT-LoRA-SentFin adapter adds a specialized sentiment-aware layer to the base FinBERT model. By using LoRA, the model retains the deep financial domain knowledge of the original ProsusAI/finbert while adapting its attention mechanisms to the specific nuances of the SentFin 1.0 corpus.ProsusAI/finbertProsusAI/finbert1from transformers import AutoModelForSequenceClassification, AutoTokenizer
2from peft import PeftModel
3import torch
4
5# 1. Define IDs
6base_model_id = "ProsusAI/finbert"
7adapter_model_id = "tahp0604/finbert-sentfin-lora" # or local path
8
9# 2. Load Tokenizer
10tokenizer = AutoTokenizer.from_pretrained(base_model_id)
11
12# 3. Load Base Model
13base_model = AutoModelForSequenceClassification.from_pretrained(base_model_id)
14
15# 4. Load and Attach PEFT Adapter
16model = PeftModel.from_pretrained(base_model, adapter_model_id)
17
18# Example Inference
19text = "Reliance fell 2.1% today amid refinery outage concerns."
20inputs = tokenizer(text, return_tensors="pt")
21
22model.eval()
23with torch.no_grad():
24 logits = model(**inputs).logits
25 predicted_class_id = logits.argmax().item()
26
27# Map to label
28labels = {0: "positive", 1: "negative", 2: "neutral"}
29print(f"Sentiment: {labels[predicted_class_id]}")query, value (Attention layers)SEQ_CLS)classifier, score