🚀 交易英雄金融情感分析
本模型是一个金融情感分析模型,基于预训练的金融领域模型进行微调,能有效处理金融领域的自然语言处理任务,为金融分析和研究提供有力支持。
🚀 快速开始
代码示例
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
tokenizer = AutoTokenizer.from_pretrained("fuchenru/Trading-Hero-LLM")
model = AutoModelForSequenceClassification.from_pretrained("fuchenru/Trading-Hero-LLM")
nlp = pipeline("text-classification", model=model, tokenizer=tokenizer)
def preprocess(text, tokenizer, max_length=128):
inputs = tokenizer(text, truncation=True, padding='max_length', max_length=max_length, return_tensors='pt')
return inputs
def predict_sentiment(input_text):
inputs = tokenizer(input_text, return_tensors="pt", truncation=True, padding=True)
with torch.no_grad():
outputs = model(**inputs)
predicted_label = torch.argmax(outputs.logits, dim=1).item()
label_map = {0: 'neutral', 1: 'positive', 2: 'negative'}
predicted_sentiment = label_map[predicted_label]
return predicted_sentiment
stock_news = [
"Market analysts predict a stable outlook for the coming weeks.",
"The market remained relatively flat today, with minimal movement in stock prices.",
"Investor sentiment improved following news of a potential trade deal.",
]
for i in stock_news:
predicted_sentiment = predict_sentiment(i)
print("Predicted Sentiment:", predicted_sentiment)
Predicted Sentiment: neutral
Predicted Sentiment: neutral
Predicted Sentiment: positive
✨ 主要特性
- 本模型是 FinBERT 的微调版本,FinBERT 是一个在金融文本上预训练的 BERT 模型。
- 微调过程使模型适应特定的金融自然语言处理任务,增强了其在特定领域情感分析应用中的性能。
📦 安装指南
文档未提及安装步骤,故跳过此章节。
💻 使用示例
基础用法
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
tokenizer = AutoTokenizer.from_pretrained("fuchenru/Trading-Hero-LLM")
model = AutoModelForSequenceClassification.from_pretrained("fuchenru/Trading-Hero-LLM")
nlp = pipeline("text-classification", model=model, tokenizer=tokenizer)
def preprocess(text, tokenizer, max_length=128):
inputs = tokenizer(text, truncation=True, padding='max_length', max_length=max_length, return_tensors='pt')
return inputs
def predict_sentiment(input_text):
inputs = tokenizer(input_text, return_tensors="pt", truncation=True, padding=True)
with torch.no_grad():
outputs = model(**inputs)
predicted_label = torch.argmax(outputs.logits, dim=1).item()
label_map = {0: 'neutral', 1: 'positive', 2: 'negative'}
predicted_sentiment = label_map[predicted_label]
return predicted_sentiment
stock_news = [
"Market analysts predict a stable outlook for the coming weeks.",
"The market remained relatively flat today, with minimal movement in stock prices.",
"Investor sentiment improved following news of a potential trade deal.",
]
for i in stock_news:
predicted_sentiment = predict_sentiment(i)
print("Predicted Sentiment:", predicted_sentiment)
高级用法
文档未提及高级用法相关内容,故跳过此部分。
📚 详细文档
主要用户
金融分析师、自然语言处理研究人员以及处理金融数据的开发人员。
训练数据
- 微调数据集:该模型在一个自定义的金融通信文本数据集上进行了微调。数据集分为训练集、验证集和测试集,具体如下:
- 训练集:10,918,272 个标记
- 验证集:1,213,184 个标记
- 测试集:1,347,968 个标记
- 预训练数据集:FinBERT 在一个总计 49 亿个标记的大型金融语料库上进行了预训练,包括:
- 公司报告(10 - K 和 10 - Q):25 亿个标记
- 财报电话会议记录:13 亿个标记
- 分析师报告:11 亿个标记
评估指标
- 测试准确率 = 0.908469
- 测试精确率 = 0.927788
- 测试召回率 = 0.908469
- 测试 F1 值 = 0.913267
- 标签含义:0 -> 中性;1 -> 积极;2 -> 消极
🔧 技术细节
文档未提供足够详细的技术实现细节(未超过 50 字),故跳过此章节。
📄 许可证
本项目采用 MIT 许可证。
引用
@misc{yang2020finbert,
title={FinBERT: A Pretrained Language Model for Financial Communications},
author={Yi Yang and Mark Christopher Siy UY and Allen Huang},
year={2020},
eprint={2006.08097},
archivePrefix={arXiv},
}