Note
本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。
English · 原始项目 · 上游 README
原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。
由于金融科技机构的内部法规和政策,我们不应指望华尔街会开源 LLM 或开放 API。
FinGPT 是由 AI4Finance Foundation 开发并维护的开源金融大语言模型项目。
主要贡献者包括:
🚀 几分钟即可上手 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 .
访问我们的 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
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 的“秘诀”所在。
在我们最新的 HuggingFace Space 试用最新发布的 FinGPT-Forecaster 演示
FinGPT-Forecaster 数据集:https://huggingface.co/datasets/FinGPT/fingpt-forecaster-dow30-202305-202405
输入以下内容:
点击 Submit!你将获得对公司全面细致的分析,以及对下周股价走势的预测!
如需更详细、更可定制的实现,请参阅 FinGPT-Forecaster
新特性:可在单张 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
我们使用的数据集以及多任务金融 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
对于 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) |
| 基座模型 | 预训练 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 | 适用于中国市场数据 | 金融情感分析 |
| 加权 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 |
The Journey of Open AI GPT models. GPT 模型解读。Open AI 的 GPT-1、GPT-2、GPT-3。
[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 让互联网规模的金融数据普惠化。
ChatGPT 交易机器人
@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}
}
MIT License
免责声明:我们在 MIT 教育许可证(MIT education license)下出于学术目的分享代码。本文内容不构成财务建议,也不是使用真实资金进行交易的推荐。请运用常识,并在交易或投资前务必先咨询专业人士。