🚀 FinancialBERTによる感情分析
FinancialBERTは、大量の金融テキストコーパスで事前学習されたBERTモデルです。このモデルの目的は、金融分野における自然言語処理(NLP)の研究と実践を強化することです。金融の実務者や研究者が、モデルを学習させるために必要な大量の計算資源を必要とせずに、このモデルを活用できるようにすることを目指しています。
このモデルは、_Financial PhraseBank_データセットを使用して感情分析タスクに対してファインチューニングされています。実験の結果、このモデルは一般的なBERTや他の金融分野固有のモデルを上回る性能を示しています。
FinancialBERT
の事前学習プロセスの詳細については、こちらを参照してください:https://www.researchgate.net/publication/358284785_FinancialBERT_-_A_Pretrained_Language_Model_for_Financial_Text_Mining
✨ 主な機能
- 金融分野のテキストに対する高精度な感情分析が可能です。
- 一般的なBERTや他の金融分野固有のモデルを上回る性能を発揮します。
📦 インストール
このモデルを使用するには、Transformersライブラリが必要です。以下のコマンドでインストールできます。
pip install transformers
📚 ドキュメント
学習データ
FinancialBERTモデルは、Financial PhraseBankというデータセットでファインチューニングされています。このデータセットは、感情(ネガティブ、中立、ポジティブ)によって分類された4840件の金融ニュースで構成されています。
ファインチューニングのハイパーパラメータ
- learning_rate = 2e-5
- batch_size = 32
- max_seq_length = 512
- num_train_epochs = 5
評価指標
評価に使用される指標は、Precision、Recall、F1-scoreです。以下は、テストセットに対する分類レポートです。
感情 |
適合率 |
再現率 |
F1値 |
サポート |
ネガティブ |
0.96 |
0.97 |
0.97 |
58 |
中立 |
0.98 |
0.99 |
0.98 |
279 |
ポジティブ |
0.98 |
0.97 |
0.97 |
148 |
マクロ平均 |
0.97 |
0.98 |
0.98 |
485 |
加重平均 |
0.98 |
0.98 |
0.98 |
485 |
💻 使用例
基本的な使用法
このモデルは、Transformersの感情分析パイプラインを使用して簡単に利用できます。
from transformers import BertTokenizer, BertForSequenceClassification
from transformers import pipeline
model = BertForSequenceClassification.from_pretrained("ahmedrachid/FinancialBERT-Sentiment-Analysis",num_labels=3)
tokenizer = BertTokenizer.from_pretrained("ahmedrachid/FinancialBERT-Sentiment-Analysis")
nlp = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
sentences = ["Operating profit rose to EUR 13.1 mn from EUR 8.7 mn in the corresponding period in 2007 representing 7.7 % of net sales.",
"Bids or offers include at least 1,000 shares and the value of the shares must correspond to at least EUR 4,000.",
"Raute reported a loss per share of EUR 0.86 for the first half of 2009 , against EPS of EUR 0.74 in the corresponding period of 2008.",
]
results = nlp(sentences)
print(results)
[{'label': 'positive', 'score': 0.9998133778572083},
{'label': 'neutral', 'score': 0.9997822642326355},
{'label': 'negative', 'score': 0.9877365231513977}]
作成者: Ahmed Rachid Hazourli