cyrilzhang/financial_phrasebank_split
Viewer • Updated • 4.85k • 106 • 1
How to use nickwong64/bert-base-uncased-finance-sentiment with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="nickwong64/bert-base-uncased-finance-sentiment") # Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("nickwong64/bert-base-uncased-finance-sentiment")
model = AutoModelForSequenceClassification.from_pretrained("nickwong64/bert-base-uncased-finance-sentiment", device_map="auto")Bert is a Transformer Bidirectional Encoder based Architecture trained on MLM(Mask Language Modeling) objective. bert-base-uncased finetuned on the cyrilzhang/financial_phrasebank_split dataset using HuggingFace Trainer with below training parameters.
learning rate 2e-5,
batch size 8,
num_train_epochs=6,
| Epoch | Training Loss | Validation Loss | Accuracy | F1 |
|---|---|---|---|---|
| 6 | 0.034100 | 0.954745 | 0.853608 | 0.854358 |
from transformers import pipeline
nlp = pipeline(task='text-classification',
model='nickwong64/bert-base-uncased-finance-sentiment')
p1 = "HK stocks open lower after Fed rate comments"
p2 = "US stocks end lower on earnings worries"
p3 = "Muted Fed, AI hopes send Wall Street higher"
print(nlp(p1))
print(nlp(p2))
print(nlp(p3))
"""
output:
[{'label': 'negative', 'score': 0.9991507530212402}]
[{'label': 'negative', 'score': 0.9997240900993347}]
[{'label': 'neutral', 'score': 0.9834381937980652}]
"""
cyrilzhang/financial_phrasebank_split
{0: 'negative', 1: 'neutral', 2: 'positive'}
{'test_loss': 0.9547446370124817,
'test_accuracy': 0.8536082474226804,
'test_f1': 0.8543579048224414,
'test_runtime': 4.9865,
'test_samples_per_second': 97.263,
'test_steps_per_second': 12.233}