Loading…
Loading…
This is a BERT-based model fine-tuned on a dataset of stock market news headlines to perform sentiment analysis. The labels are:
positiveneutralnegativeThe model is intended for financial news and headlines, especially useful for trading, sentiment scoring, or market analysis pipelines.
bert-base-uncasedpositive, neutral, negativefrom transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
tokenizer = AutoTokenizer.from_pretrained("hasnain43/bert-stock-sentiment-v1")
model = AutoModelForSequenceClassification.from_pretrained("hasnain43/bert-stock-sentiment-v1")
model.eval()
label_map = {0: "negative", 1: "neutral", 2: "positive"}
def predict_sentiment(text):
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
prediction = torch.argmax(logits, dim=1).item()
return label_map[prediction]
predict_sentiment("Tesla stock drops after disappointing delivery numbers.")