🚀 金融情感分析的FinancialBERT
FinancialBERT 是一个在大量金融文本语料库上预训练的BERT模型。其目的是推动金融领域的自然语言处理研究与实践,让金融从业者和研究人员无需投入大量计算资源来训练模型,就能从该模型中受益。
该模型在 Financial PhraseBank 数据集上针对情感分析任务进行了微调。实验表明,该模型的性能优于通用的BERT模型以及其他金融领域特定的模型。
有关 FinancialBERT
预训练过程的更多详细信息,请访问:https://www.researchgate.net/publication/358284785_FinancialBERT_-_A_Pretrained_Language_Model_for_Financial_Text_Mining
✨ 主要特性
- 预训练优势:基于大量金融文本语料库预训练,能更好地理解金融领域的语义。
- 微调优化:在 Financial PhraseBank 数据集上针对情感分析任务进行微调,性能表现出色。
- 资源友好:让金融从业者和研究人员无需大量计算资源即可使用。
📦 安装指南
文档未提及具体安装步骤,若使用该模型,可参考 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}]
📚 详细文档
训练数据
FinancialBERT模型在 Financial PhraseBank 数据集上进行了微调,该数据集包含4840条按情感(负面、中性、正面)分类的财经新闻。
微调超参数
- 学习率(learning_rate) = 2e-5
- 批次大小(batch_size) = 32
- 最大序列长度(max_seq_length) = 512
- 训练轮数(num_train_epochs) = 5
评估指标
使用的评估指标为:精确率(Precision)、召回率(Recall)和F1分数(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 |
📄 许可证
文档未提及许可证信息。
由 Ahmed Rachid Hazourli 创建