Instructions to use ahmedrachid/FinancialBERT-Sentiment-Analysis with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ahmedrachid/FinancialBERT-Sentiment-Analysis with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="ahmedrachid/FinancialBERT-Sentiment-Analysis")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("ahmedrachid/FinancialBERT-Sentiment-Analysis") model = AutoModelForSequenceClassification.from_pretrained("ahmedrachid/FinancialBERT-Sentiment-Analysis") - Inference
- Notebooks
- Google Colab
- Kaggle
Does the program support num_labels = 2?
Thank you for the excellent work!! Is there a way to set num_labels = 2? I tried to modify the codes here
https://huggingface.co/ahmedrachid/FinancialBERT-Sentiment-Analysis
in order to accommodate 2 labels (positive, negative) rather than 3 (positive, neutral, negative) as follows:
"model = BertForSequenceClassification.from_pretrained("ahmedrachid/FinancialBERT-Sentiment-Analysis",num_labels=2)" but I got an error message.
Hello @ewmiao , sorry for the late response.. just noticed your comment. It's possible for sure ! You need to fine-tune the model for your needs if you have num_labels = 2, you can do transfer learning and freeze all layers before last Dense layer
Load the pre-trained FinancialBERT model
model = BertForSequenceClassification.from_pretrained("ahmedrachid/FinancialBERT-Sentiment-Analysis", num_labels=3)
Adjusting the model for binary classification (positive, negative)
model.classifier = torch.nn.Linear(model.classifier.in_features, 2)
Training setup
trainer = Trainer(
model=model,
args=training_args,
train_dataset=train_dataset,
eval_dataset=val_dataset,
)
Train the model
trainer.train()