FinTwitBERT: Specialized BERT Model for Financial Twitter Analysis. Trained on vast financial tweets, it's ideal for sentiment analysis, trend prediction, and financial NLP tasks.
import shap
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
from datasets import load_dataset
# Load pre-trained model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("StephanAkkerman/FinTwitBERT-sentiment")
model = AutoModelForSequenceClassification.from_pretrained(
"StephanAkkerman/FinTwitBERT-sentiment"
)
classifier = pipeline(
"text-classification",
model=model,
tokenizer=tokenizer,
device=0,
top_k=None,
)
dataset = load_dataset(
"financial_phrasebank",
cache_dir="datasets/",
split="train",
name="sentences_50agree",
)
# Rename sentence to text
dataset = dataset.rename_column("sentence", "text")
short_data = [v[:500] for v in dataset["text"][:20]]
# define the explainer
explainer = shap.Explainer(classifier)
# explain the predictions of the pipeline on the first two samples
shap_values = explainer(short_data[:2])
# Try visualizing the SHAP values without indexing
shap.plots.text(shap_values)
SHAP -> only works using notebook...
LIME