Views
No views yet
1from transformers import pipeline
2
3# Load the model
4classifier = pipeline(
5 "text-classification",
6 model="Hananguyen12/LAPEFT-Financial-Sentiment-Analysis"
7)
8
9# Analyze sentiment
10text = "The company reported strong quarterly earnings."
11result = classifier(text)
12print(result)
13# Output: [{'label': 'POSITIVE', 'score': 0.9234}]1from transformers import BertTokenizer, BertForSequenceClassification
2from peft import PeftModel
3
4# Load model components
5base_model = BertForSequenceClassification.from_pretrained(
6 "bert-base-uncased",
7 num_labels=3
8)
9model = PeftModel.from_pretrained(base_model, "Hananguyen12/LAPEFT-Financial-Sentiment-Analysis")
10tokenizer = BertTokenizer.from_pretrained("bert-base-uncased")
11
12# Inference
13text = "The quarterly results exceeded expectations."
14inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
15
16with torch.no_grad():
17 outputs = model(**inputs)
18 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
19 predicted_class = torch.argmax(predictions, dim=-1)
20
21labels = ["NEGATIVE", "NEUTRAL", "POSITIVE"]
22print(f"Predicted: {labels[predicted_class]}")1@misc{lapeft_financial_sentiment_2025,
2 title={LAPEFT: Financial Sentiment Analysis with LoRA},
3 author={Hananguyen12},
4 year={2025},
5 publisher={Hugging Face},
6 url={https://huggingface.co/Hananguyen12/LAPEFT-Financial-Sentiment-Analysis}
7}