zeroshot/twitter-financial-news-sentiment
Viewer • Updated • 11.9k • 4.67k • 168
How to use codealchemist01/financial-sentiment-improved with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="codealchemist01/financial-sentiment-improved") # Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("codealchemist01/financial-sentiment-improved")
model = AutoModelForSequenceClassification.from_pretrained("codealchemist01/financial-sentiment-improved")This model is a fine-tuned version of DistilBERT for financial sentiment analysis. It has been trained on financial news and social media data to classify text into three sentiment categories: Bearish (negative), Neutral, and Bullish (positive).
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
tokenizer = AutoTokenizer.from_pretrained("codealchemist01/financial-sentiment-improved")
model = AutoModelForSequenceClassification.from_pretrained("codealchemist01/financial-sentiment-improved")
def predict_sentiment(text):
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
with torch.no_grad():
outputs = model(**inputs)
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
labels = ["Bearish", "Neutral", "Bullish"]
predicted_class = torch.argmax(predictions, dim=-1).item()
confidence = predictions[0][predicted_class].item()
return {
"label": labels[predicted_class],
"confidence": confidence
}
# Example
result = predict_sentiment("The stock market is showing strong growth today")
print(result)
This model was trained using advanced techniques including:
This model is designed for financial sentiment analysis tasks, including: