Text Classification
Transformers
Joblib
Safetensors
bert
sentiment-analysis
finance
macroeconomics
climate
esg
policy
ensemble
dictionary
finbert
Eval Results (legacy)
text-embeddings-inference
Instructions to use peyterho/macro-sentiment-finbert with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use peyterho/macro-sentiment-finbert with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="peyterho/macro-sentiment-finbert")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("peyterho/macro-sentiment-finbert") model = AutoModelForSequenceClassification.from_pretrained("peyterho/macro-sentiment-finbert", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update transformers_ensemble with custom model_name support for FinBERTHead
Browse files
macro_sentiment/transformers_ensemble.py
CHANGED
|
@@ -67,9 +67,10 @@ class SentimentHead:
|
|
| 67 |
|
| 68 |
|
| 69 |
class FinBERTHead(SentimentHead):
|
| 70 |
-
|
|
|
|
| 71 |
super().__init__(
|
| 72 |
-
model_name=
|
| 73 |
label_map={0: "positive", 1: "negative", 2: "neutral"},
|
| 74 |
score_map={"positive": 1.0, "negative": -1.0, "neutral": 0.0},
|
| 75 |
device=device,
|
|
@@ -168,11 +169,11 @@ class TopicRouter:
|
|
| 168 |
|
| 169 |
|
| 170 |
class TransformerEnsemble:
|
| 171 |
-
def __init__(self, device="cpu", use_router=True):
|
| 172 |
self.device = device
|
| 173 |
self.use_router = use_router
|
| 174 |
self.heads = {
|
| 175 |
-
"finbert": FinBERTHead(device),
|
| 176 |
"policy": FinancialRoBERTaHead(device),
|
| 177 |
"climate": ClimateBERTHead(device),
|
| 178 |
}
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
class FinBERTHead(SentimentHead):
|
| 70 |
+
"""FinBERT for financial news sentiment. Accepts custom model_name for fine-tuned variants."""
|
| 71 |
+
def __init__(self, model_name="ProsusAI/finbert", device="cpu"):
|
| 72 |
super().__init__(
|
| 73 |
+
model_name=model_name,
|
| 74 |
label_map={0: "positive", 1: "negative", 2: "neutral"},
|
| 75 |
score_map={"positive": 1.0, "negative": -1.0, "neutral": 0.0},
|
| 76 |
device=device,
|
|
|
|
| 169 |
|
| 170 |
|
| 171 |
class TransformerEnsemble:
|
| 172 |
+
def __init__(self, device="cpu", use_router=True, finbert_model="ProsusAI/finbert"):
|
| 173 |
self.device = device
|
| 174 |
self.use_router = use_router
|
| 175 |
self.heads = {
|
| 176 |
+
"finbert": FinBERTHead(model_name=finbert_model, device=device),
|
| 177 |
"policy": FinancialRoBERTaHead(device),
|
| 178 |
"climate": ClimateBERTHead(device),
|
| 179 |
}
|