finbert-minilm-sentiment classifies financial text into
negative / neutral / positive sentiment.
It is a compact MiniLM encoder (
microsoft/MiniLM-L12-H384-uncased, 33.4M parameters)
fine-tuned on the
Financial PhraseBank
benchmark. All metrics below are
real, measured numbers on a held-out test set that was
never seen during training — no illustrative or synthetic figures.
Evaluated on a stratified 15% test split (340 sentences) of Financial PhraseBank
Sentences_AllAgree — held out completely during training and validation.
Model selection used best validation accuracy; the reported figures are then computed
once on the untouched test set.
1import torch
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
4model_id = "9mark9/finbert-minilm-sentiment"
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForSequenceClassification.from_pretrained(model_id)
7model.eval()
8
9texts = [
10 "The company reported record quarterly profit, beating analyst expectations.",
11 "Net sales decreased by 12% and the firm warned of further losses ahead.",
12 "The board will meet next Tuesday to review the quarterly schedule.",
13]
14
15enc = tokenizer(texts, padding=True, truncation=True, max_length=96, return_tensors="pt")
16with torch.no_grad():
17 probs = model(**enc).logits.softmax(-1)
18
19for text, p in zip(texts, probs):
20 label = model.config.id2label[int(p.argmax())]
21 print(f"[{label:8s} {p.max():.2f}] {text}")
22# [positive 0.97] The company reported record quarterly profit, ...
23# [negative 0.98] Net sales decreased by 12% and the firm warned ...
24# [neutral 0.99] The board will meet next Tuesday to review ...
1@article{malo2014good,
2 title={Good debt or bad debt: Detecting semantic orientations in economic texts},
3 author={Malo, Pekka and Sinha, Ankur and Korhonen, Pekka and Wallenius, Jyrki and Takala, Pyry},
4 journal={Journal of the Association for Information Science and Technology},
5 volume={65}, number={4}, pages={782--796}, year={2014}
6}