32 KiB
Note
本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。
English · 原始项目 · 上游 README
原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。
FinGPT: Open-Source Financial Large Language Models
由于金融科技机构的内部法规和政策,我们不应指望华尔街会开源 LLM 或开放 API。
项目贡献者
FinGPT 是由 AI4Finance Foundation 开发并维护的开源金融大语言模型项目。
主要贡献者包括:
- Hongyang (Bruce) Yang – 金融大语言模型及相关应用的研究与开发
- [其他贡献者…]
最新动态:
- [模型发布] 2023 年 11 月:我们发布 FinGPT-Forecaster! 🔥Demo, Medium Blog 与 Model 已上线 Huggingface🤗!
- [论文录用] 2023 年 10 月:"FinGPT: Instruction Tuning Benchmark for Open-Source Large Language Models in Financial Datasets" 已被 Instruction Workshop @ NeurIPS 2023 录用🎉
- [论文录用] 2023 年 10 月:"FinGPT: Democratizing Internet-scale Data for Financial Large Language Models" 已被 Instruction Workshop @ NeurIPS 2023 录用🎉
- [模型发布] 2023 年 10 月:我们发布在 FinGPT-Benchmark 上评估基础 LLM 时产出的 金融多任务 LLM 🔥
- [论文录用] 2023 年 9 月:"Enhancing Financial Sentiment Analysis via Retrieval Augmented Large Language Models" 已被 ACM International Conference on AI in Finance (ICAIF-23) 录用🎉
- [模型发布] 2023 年 8 月:我们发布 金融情感分析模型 🔥
- [论文录用] 2023 年 7 月:"Instruct-FinGPT: Financial Sentiment Analysis by Instruction Tuning of General-Purpose Large Language Models" 已被 FinLLM 2023@IJCAI 2023 录用🎉
- [论文录用] 2023 年 7 月:"FinGPT: Open-Source Financial Large Language Models" 已被 FinLLM 2023@IJCAI 2023 录用🎉
- [Medium 博客] 2023 年 6 月:FinGPT: Powering the Future of Finance with 20 Cutting-Edge Applications
快速入门
🚀 几分钟即可上手 FinGPT!
有关在本地或 Replit 上运行 FinGPT 的详细设置说明,包括硬件要求和故障排除,请参阅我们的完整 SETUP 指南。
安装
# Clone the repository
git clone https://github.com/AI4Finance-Foundation/FinGPT.git
cd FinGPT
# Install dependencies
pip install -r requirements.txt
pip install -e .
试用 Demo
访问我们的 HuggingFace Space 无需安装即可试用 FinGPT-Forecaster!
基本用法
# Using cloud API (no GPU required)
import os
os.environ['FINGPT_LLM_PROVIDER'] = 'openai'
# Using local models (requires GPU)
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
# See SETUP.md for detailed examples
为什么选择 FinGPT?
1). 金融领域高度动态。BloombergGPT 使用金融数据与通用数据的混合集训练 LLM,耗时约 53 天,成本约 $3M)。像 BloombergGPT 这样的 LLM 若每月或每周重新训练成本高昂,因此轻量级适配(lightweight adaptation)更具优势。FinGPT 可快速微调以纳入新数据(成本显著降低,每次微调低于 $300)。
2). 让互联网规模的金融数据民主化至关重要,例如通过自动化数据整理流水线实现模型的及时更新(每月或每周更新)。BloombergGPT 拥有特权数据访问与 API,而 FinGPT 提供了更易获取的替代方案。它优先采用轻量级适配,并充分利用当前最佳的开源 LLM。
3). 关键技术是 "RLHF(Reinforcement learning from human feedback,基于人类反馈的强化学习)",而 BloombergGPT 中缺失这一能力。RLHF 使 LLM 能够学习个人偏好(风险厌恶程度、投资习惯、个性化智能投顾等),这正是 ChatGPT 与 GPT4 的“秘诀”所在。
AI 智能投顾里程碑:FinGPT-Forecaster
在我们最新的 HuggingFace Space 试用最新发布的 FinGPT-Forecaster 演示
FinGPT-Forecaster 数据集:https://huggingface.co/datasets/FinGPT/fingpt-forecaster-dow30-202305-202405
输入以下内容:
- 股票代码(例如 AAPL、MSFT、NVDA)
- 你希望预测起始的日期(yyyy-mm-dd)
- 检索市场新闻的过往周数
- 是否将最新基本财务数据作为附加信息
点击 Submit!你将获得对公司全面细致的分析,以及对下周股价走势的预测!
如需更详细、更可定制的实现,请参阅 FinGPT-Forecaster
FinGPT 演示:
金融情感分析领域当前最先进方案
-
-
新特性:可在单张 RTX 3090 上训练与推理的最佳 FinGPT 情感分析模型,效果甚至优于 GPT-4 与 ChatGPT 微调。
-
FinGPT v3 系列是在 News and Tweets 情感分析数据集上使用 LoRA 方法微调的 LLM,以较低成本在大多数金融情感分析数据集上取得了最佳成绩。
-
-
FinGPT v3.3 以 llama2-13b 为基础模型;FinGPT v3.2 以 llama2-7b 为基础模型;FinGPT v3.1 以 chatglm2-6B 为基础模型。
-
基准测试结果:
-
Weighted F1 FPB FiQA-SA TFNS NWGI 设备 时间 成本 FinGPT v3.3 0.882 0.874 0.903 0.643 1 × RTX 3090 17.25 hours $17.25 FinGPT v3.2 0.850 0.860 0.894 0.636 1 × A100 5.5 hours $ 22.55 FinGPT v3.1 0.855 0.850 0.875 0.642 1 × A100 5.5 hours $ 22.55 FinGPT (8bit) 0.855 0.847 0.879 0.632 1 × RTX 3090 6.47 hours $ 6.47 FinGPT (QLoRA) 0.777 0.752 0.828 0.583 1 × RTX 3090 4.15 hours $ 4.15 OpenAI Fine-tune 0.878 0.887 0.883 - - - - GPT-4 0.833 0.630 0.808 - - - - FinBERT 0.880 0.596 0.733 0.538 4 × NVIDIA K80 GPU - - Llama2-7B 0.390 0.800 0.296 0.503 2048 × A100 21 days $ 4.23 million BloombergGPT 0.511 0.751 - - 512 × A100 53 days $ 2.67 million 每 GPU 小时成本。 对于 A100 GPU,我们以配备 8 块 A100 GPU 的 AWS p4d.24xlarge 实例作为基准来估算成本。请注意,BloombergGPT 也使用了 p4d.24xlarge。截至 2023 年 7 月 11 日,该实例的每小时费率为 $32.773。因此,估算的每 GPU 小时成本为 $32.77 除以 8,约为 $4.10。以此作为参考单价(1 GPU 小时)。BloombergGPT 估算成本 = 512 x 53 x 24 = 651,264 GPU 小时 x $4.10 = $2,670,182.40。对于 RTX 3090,我们假设其每小时成本约为 $1.0,这实际上远高于 vast.ai 等平台上的可用 GPU 价格。
-
运行 benchmarks 可复现上述结果,详细教程即将推出。
-
仅需一块 RTX 3090,即可通过 LoRA 方法微调你自己的 FinGPT v3 模型:8bit 见 notebook,int4(QLoRA)见 notebook
-
-
- 通过 LoRA 使用市场标注数据微调 ChatGLM2 / Llama2,面向中国市场的 FinGPT
指令微调数据集与模型
我们使用的数据集以及多任务金融 LLM 模型可在 https://huggingface.co/FinGPT 获取
| 数据集 | 训练行数 | 测试行数 | 描述 |
|---|---|---|---|
| fingpt-sentiment-train | 76.8K | N/A | 情感分析训练指令 |
| fingpt-finred | 27.6k | 5.11k | 金融关系抽取指令 |
| fingpt-headline | 82.2k | 20.5k | 金融标题分析指令 |
| fingpt-ner | 511 | 98 | 金融命名实体识别(NER)指令 |
| fingpt-fiqa_qa | 17.1k | N/A | 金融问答指令 |
| fingpt-fineval | 1.06k | 265 | 中文多项选择题指令 |
多任务金融 LLM 模型:
demo_tasks = [
'Financial Sentiment Analysis',
'Financial Relation Extraction',
'Financial Headline Classification',
'Financial Named Entity Recognition',]
demo_inputs = [
"Glaxo's ViiV Healthcare Signs China Manufacturing Deal With Desano",
"Apple Inc. Chief Executive Steve Jobs sought to soothe investor concerns about his health on Monday, saying his weight loss was caused by a hormone imbalance that is relatively simple to treat.",
'gold trades in red in early trade; eyes near-term range at rs 28,300-28,600',
'This LOAN AND SECURITY AGREEMENT dated January 27 , 1999 , between SILICON VALLEY BANK (" Bank "), a California - chartered bank with its principal place of business at 3003 Tasman Drive , Santa Clara , California 95054 with a loan production office located at 40 William St ., Ste .',]
demo_instructions = [
'What is the sentiment of this news? Please choose an answer from {negative/neutral/positive}.',
'Given phrases that describe the relationship between two words/phrases as options, extract the word/phrase pair and the corresponding lexical relationship between them from the input text. The output format should be "relation1: word1, word2; relation2: word3, word4". Options: product/material produced, manufacturer, distributed by, industry, position held, original broadcaster, owned by, founded by, distribution format, headquarters location, stock exchange, currency, parent organization, chief executive officer, director/manager, owner of, operator, member of, employer, chairperson, platform, subsidiary, legal form, publisher, developer, brand, business division, location of formation, creator.',
'Does the news headline talk about price going up? Please choose an answer from {Yes/No}.',
'Please extract entities and their types from the input sentence, entity types should be chosen from {person/organization/location}.',]
| 模型 | 描述 | 功能 |
|---|---|---|
| fingpt-mt_llama2-7b_lora | 使用 LoRA 微调后的 Llama2-7b 模型 | 多任务 |
| fingpt-mt_falcon-7b_lora | 使用 LoRA 微调后的 falcon-7b 模型 | 多任务 |
| fingpt-mt_bloom-7b1_lora | 使用 LoRA 微调后的 bloom-7b1 模型 | 多任务 |
| fingpt-mt_mpt-7b_lora | 使用 LoRA 微调后的 mpt-7b 模型 | 多任务 |
| fingpt-mt_chatglm2-6b_lora | 使用 LoRA 微调后的 chatglm-6b 模型 | 多任务 |
| fingpt-mt_qwen-7b_lora | 使用 LoRA 微调后的 qwen-7b 模型 | 多任务 |
| fingpt-sentiment_llama2-13b_lora | 使用 LoRA 微调后的 llama2-13b 模型 | 单任务 |
| fingpt-forecaster_dow30_llama2-7b_lora | 使用 LoRA 微调后的 llama2-7b 模型 | 单任务 |
教程
[Training] FinGPT 初学者指南:使用 LoRA 和 ChatGLM2–6B,一本 Notebook,$10 GPU
了解 FinGPT:教育类博客系列
FinGPT 生态系统
FinGPT 采用面向 FinLLM 的全栈框架,共五个层级:
- 数据源层(Data source layer):该层确保全面的市场覆盖,通过实时信息采集应对金融数据的时间敏感性。
- 数据工程层(Data engineering layer):面向实时 NLP 数据处理,该层应对金融数据中固有的高时间敏感性与低信噪比挑战。
- LLM 层(LLMs layer):聚焦 LoRA 等一系列微调方法,该层缓解金融数据的高度动态性,确保模型的相关性与准确性。
- 任务层(Task layer):该层负责执行基础任务。这些任务作为 FinLLM 领域内性能评估与横向对比的基准。
- 应用层(Application layer):展示实际应用与演示,该层凸显 FinGPT 在金融领域的潜在能力。
- FinGPT 框架:开源金融大语言模型
- FinGPT-RAG: 我们提出一种专为金融情感分析设计的检索增强大语言模型(RAG)框架,通过外部知识检索优化信息深度与上下文,从而确保细粒度的预测。
- FinGPT-FinNLP: FinNLP 为所有对金融领域 LLM 与 NLP 感兴趣的人提供实验场。我们在此提供金融领域 LLM 训练与微调的完整流水线。完整架构如下图所示。详细代码与介绍可参见此处.,也可参阅 wiki
- FinGPT-Benchmark: 我们引入一种面向金融领域开源大语言模型(LLM)的新型指令微调(Instruction Tuning)范式,在提升其对多样化金融数据集适应能力的同时,也便于从任务特定、多任务和零样本指令微调任务出发进行低成本、系统化的基准测试。
用于 FinGPT 推理的云 LLM 提供商
对于 Finogrid 平台(finogrid/),FinGPT 支持多个云 LLM 提供商作为本地模型运行的替代方案。请在环境中设置 FINGPT_LLM_PROVIDER:
| 提供商 | 模型 | 上下文长度 | 用例 |
|---|---|---|---|
| OpenAI | GPT-3.5-turbo | 16K | 情感分析与智能体的默认备选方案 |
| MiniMax | MiniMax-M3 | 512K | 最新旗舰模型,支持 128K 最大输出与图像输入 |
| FinGPT(本地) | Llama-2-13B LoRA | 4K | 完整本地推理(需要 GPU) |
FinGPT 的 LLM 层所使用的开源基座模型
- 欢迎贡献更多面向各语言特定金融市场的开源基座模型。
| 基座模型 | 预训练 Token 数 | 上下文长度 | 模型优势 | 模型规模 | 实验结果 | 应用 |
|---|---|---|---|---|---|---|
| Llama-2 | 2 Trillion | 4096 | Llama-2 在英文市场数据上表现优异 | llama-2-7b 与 Llama-2-13b | llama-2 持续展现出更优的微调效果 | 金融情感分析、机器人投顾 |
| Falcon | 1,500B | 2048 | 在保持高质量结果的同时更具资源效率 | falcon-7b | 适用于英文市场数据 | 金融情感分析 |
| MPT | 1T | 2048 | MPT 模型可高效稳定收敛地训练 | mpt-7b | 适用于英文市场数据 | 金融情感分析 |
| Bloom | 366B | 2048 | 全球最大的开源多语言语言模型 | bloom-7b1 | 适用于英文市场数据 | 金融情感分析 |
| ChatGLM2 | 1.4T | 32K | 中文表达能力突出 | chatglm2-6b | 在中国市场数据上表现强劲 | 金融情感分析、财务报告摘要 |
| Qwen | 2.2T | 8k | 响应快速、准确率高 | qwen-7b | 适用于中国市场数据 | 金融情感分析 |
| InternLM | 1.8T | 8k | 可灵活独立构建工作流 | internlm-7b | 适用于中国市场数据 | 金融情感分析 |
- 以上开源基座模型在金融情感分析任务中的基准测试结果(使用相同 SFT(LoRA)指令模板):
加权 F1/Acc Llama2 Falcon MPT Bloom ChatGLM2 Qwen InternLM FPB 0.863/0.863 0.846/0.849 0.872/0.872 0.810/0.810 0.850/0.849 0.854/0.854 0.709/0.714 FiQA-SA 0.871/0.855 0.840/0.811 0.863/0.844 0.771/0.753 0.864/0.862 0.867/0.851 0.679/0.687 TFNS 0.896/0.895 0.893/0.893 0.907/0.907 0.840/0.840 0.859/0.858 0.883/0.882 0.729/0.731 NWGI 0.649/0.651 0.636/0.638 0.640/0.641 0.573/0.574 0.619/0.629 0.638/0.643 0.498/0.503
衷心感谢所有贡献者:
新闻
- 哥伦比亚大学视角:ChatGPT
- [MIT Technology Review] ChatGPT 即将颠覆经济。我们需要决定那将是什么样子
- [BloombergGPT] BloombergGPT:面向金融的大语言模型
- [Finextra] ChatGPT 与 Bing AI 将担任金融科技会议圆桌嘉宾
AI4Finance 中的 ChatGPT
- [YouTube 视频] 我用 ChatGPT 打造了一个交易机器人, 结合 ChatGPT 与 FinRL。
- 嘿,ChatGPT!给我讲讲 FinRL 代码!
入门资料
- Sparks of artificial general intelligence: Early experiments with GPT-4
- [GPT-4] GPT-4 Technical Report
- [InstructGPT] Training language models to follow instructions with human feedback NeurIPS 2022。
The Journey of Open AI GPT models. GPT 模型解读。Open AI 的 GPT-1、GPT-2、GPT-3。
- [GPT-3] Language models are few-shot learners NeurIPS 2020。
- [GPT-2] Language Models are Unsupervised Multitask Learners
- [GPT-1] Improving Language Understanding by Generative Pre-Training
- [Transformer] Attention is All you Need NeurIPS 2017。
(金融)大数据
-
[BloombergGPT] BloombergGPT: A Large Language Model for Finance
-
WHAT’S IN MY AI? 对用于训练 GPT-1、GPT-2、GPT-3、GPT-NeoX-20B、Megatron-11B、MT-NLG 和 Gopher 的数据集进行全面分析
-
FinRL-Meta Repo 以及论文 FinRL-Meta: Market Environments and Benchmarks for Data-Driven Financial Reinforcement Learning. Advances in Neural Information Processing Systems,2022。
-
[AI4Finance] FinNLP 让互联网规模的金融数据普惠化。
有趣演示
- GPT-3 Creative Fiction OpenAI 的 GPT-3 模型进行创意写作,展示诗歌、对话、双关语、文学戏仿和讲故事。另附有效 GPT-3 提示词编程(prompt programming)建议及常见错误规避方法。
面向 FinTech 的 ChatGPT
ChatGPT 交易机器人
- [YouTube 视频] ChatGPT Trading strategy 20097% returns
- [YouTube 视频] ChatGPT Coding - Make A Profitable Trading Strategy In Five Minutes!
- [YouTube 视频] Easy Automated Live Trading using ChatGPT (+9660.3% hands free)
- [YouTube 视频] ChatGPT Trading Strategy 893% Returns
- [YouTube 视频] ChatGPT 10 Million Trading Strategy
- [YouTube 视频] ChatGPT: Your Crypto Assistant
- [YouTube 视频] Generate Insane Trading Returns with ChatGPT and TradingView
引用 FinGPT
@article{yang2023fingpt_open,
title = {FinGPT: Open-Source Financial Large Language Models},
author = {Yang, Hongyang and Liu, Xiao-Yang and Wang, Christina Dan},
journal = {arXiv preprint arXiv:2306.06031},
year = {2023},
url = {https://arxiv.org/abs/2306.06031},
note = {First official FinGPT paper; FinLLM Workshop at IJCAI 2023}
}
@article{zhang2023instructfingpt,
title={Instruct-FinGPT: Financial Sentiment Analysis by Instruction Tuning of General-Purpose Large Language Models},
author={Boyu Zhang and Hongyang Yang and Xiao-Yang Liu},
journal={FinLLM Symposium at IJCAI 2023},
year={2023}
}
@article{zhang2023fingptrag,
title={Enhancing Financial Sentiment Analysis via Retrieval Augmented Large Language Models},
author={Zhang, Boyu and Yang, Hongyang and Zhou, tianyu and Babar, Ali and Liu, Xiao-Yang},
journal = {ACM International Conference on AI in Finance (ICAIF)},
year={2023}
}
@article{liang2024fingpt,
title={FinGPT: enhancing sentiment-based stock movement prediction with dissemination-aware and context-enriched LLMs},
author={Liang, Yixuan and Liu, Yuncong and Wang, Neng and Yang, Hongyang and Zhang, Boyu and Wang, Christina Dan},
journal={AAAI 2025 Workshop GoodData},
year={2025}
}
@article{wang2023fingptbenchmark,
title={FinGPT: Instruction Tuning Benchmark for Open-Source Large Language Models in Financial Datasets},
author={Wang, Neng and Yang, Hongyang and Wang, Christina Dan},
journal={NeurIPS Workshop on Instruction Tuning and Instruction Following},
year={2023}
}
@article{2023finnlp,
title={Data-centric FinGPT: Democratizing Internet-scale Data for Financial Large Language Models},
author={Liu, Xiao-Yang and Wang, Guoxuan and Yang, Hongyang and Zha, Daochen},
journal={NeurIPS Workshop on Instruction Tuning and Instruction Following},
year={2023}
}
LICENSE
MIT License
免责声明:我们在 MIT 教育许可证(MIT education license)下出于学术目的分享代码。本文内容不构成财务建议,也不是使用真实资金进行交易的推荐。请运用常识,并在交易或投资前务必先咨询专业人士。





