Commit
·
7491560
1
Parent(s):
cd0f8c6
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,108 @@
|
|
1 |
---
|
2 |
license: apache-2.0
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
+
language:
|
4 |
+
- zh
|
5 |
+
pipeline_tag: text-generation
|
6 |
---
|
7 |
+
---
|
8 |
+
<div style="text-align:center">
|
9 |
+
<!-- <img src="https://big-cheng.com/k2/k2.png" alt="k2-logo" width="200"/> -->
|
10 |
+
<h2>📈 CFGPT: Chinese Financial Assistant with Large Language Model (CFGPT1-sft-7b-LoRA)</h2>
|
11 |
+
</div>
|
12 |
+
|
13 |
+
## Introduction
|
14 |
+
|
15 |
+
We introduce **CFGPT**, an open-source language model trained by firstly further pretraining general LLMs on collected and cleaned Chinese finance text data (CFData-pt), including financial domain-specific data (announcement, finance articles, finance exams, finance news, finance research papers) and general data (Wikipedia), and secondly fine-tuning with knowledge-intensive instruction tuning data (CFData-sft).
|
16 |
+
As for preliminary evaluation, we use CFBenchmark-Basic.
|
17 |
+
CFGPT outperforms the baselines on objective and subjective tasks compared to several baseline models with similar parameters.
|
18 |
+
|
19 |
+
In this repository, we will share the supervised finetuning LoRA model.
|
20 |
+
|
21 |
+
- [Supervised Finetuned Model (Lora)](https://huggingface.co/TongjiFinLab/CFGPT1-sft-7B-LoRA): Adapter model weights trained by PEFT (LoRA).
|
22 |
+
|
23 |
+
## How to Use
|
24 |
+
|
25 |
+
**1. Prepare the code and the environment**
|
26 |
+
|
27 |
+
Clone [CFGPT]() repository, create a Python environment, and activate it via the following command
|
28 |
+
```bash
|
29 |
+
git clone https://github.com/TongjiFinLab/CFGPT.git
|
30 |
+
cd CFGPT
|
31 |
+
conda create -n env_name python=3.10
|
32 |
+
source activate env_name
|
33 |
+
pip install -r requirements.txt
|
34 |
+
```
|
35 |
+
|
36 |
+
**2. Use CFGPT1-sft-7B-LoRA**
|
37 |
+
|
38 |
+
```python
|
39 |
+
from transformers import AutoModel, AutoTokenizer
|
40 |
+
from peft import PeftModel
|
41 |
+
base_model = 'TongjiFinLab/CFGPT1-pt-7B'
|
42 |
+
lora_weights = 'TongjiFinLab/CFGPT1-sft-7B-LoRA'
|
43 |
+
device_map = 'cuda:0'
|
44 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model, trust_remote_code=True)
|
45 |
+
model = AutoModel.from_pretrained(
|
46 |
+
base_model,
|
47 |
+
trust_remote_code=True,
|
48 |
+
device_map=device_map,
|
49 |
+
torch_dtype=torch.bfloat16
|
50 |
+
)
|
51 |
+
model = PeftModel.from_pretrained(
|
52 |
+
model,
|
53 |
+
lora_weights,
|
54 |
+
device_map=device_map,
|
55 |
+
)
|
56 |
+
model = model.eval()
|
57 |
+
inputs = tokenizer("""你是一名金融从业者,请对这篇新闻进行情感分析。请从(中性、积极、消极)中选取答案。新闻内容:挖贝快讯:特步国际发布2023年第二季度中国内地业务营运状况,披露截至2023年6月30日止3个月零售销售实现高双位数同比增长(包括线上线下渠道),零售折扣水平约七五折。同时,2022年7月MSCI首次予以特步ESG评级,一年后评级表现即迎来提升。明晟MSCI上调特步ESG评级,由“BB”升至“BBB”。\n回答:""", return_tensors='pt').to('cuda:4')
|
58 |
+
pred = model.generate(**inputs, max_new_tokens=64, do_sample=False, repetition_penalty=1.0)
|
59 |
+
print(tokenizer.decode(pred.cpu()[0], skip_special_tokens=True).split('回答:')[1])
|
60 |
+
```
|
61 |
+
|
62 |
+
## 简介
|
63 |
+
|
64 |
+
**CFGPT**是一个开源的语言模型,首先通过在收集和清理的中国金融文本数据(CFData-pt)上进行继续预训练,包括金融领域特定数据(公告、金融文章、金融考试、金融新闻、金融研究论文)和通用数据(维基百科),然后使用知识密集的指导调整数据(CFData-sft)进行微调。
|
65 |
+
我们使用CFBenchmark-Basic进行初步评估。与几个具有相似参数的基线模型相比,CFGPT在识别,分类和生成任务上表现优越。
|
66 |
+
|
67 |
+
在这个仓库中,我们将分享以下LoRA有监督微调的模型。
|
68 |
+
|
69 |
+
- [Supervised Finetuned Model (Lora)](https://huggingface.co/TongjiFinLab/CFGPT1-sft-7B-LoRA): 基于我们继续预训练模型的由PEFT(LoRA)训练的适配器模型权重。
|
70 |
+
|
71 |
+
## 如何使用
|
72 |
+
|
73 |
+
**1. 准备代码和环境**
|
74 |
+
|
75 |
+
克隆[CFGPT]()的仓库,创建一个Python环境,并通过以下命令激活它:
|
76 |
+
```bash
|
77 |
+
git clone https://github.com/TongjiFinLab/CFGPT.git
|
78 |
+
cd CFGPT
|
79 |
+
conda create -n env_name python=3.10
|
80 |
+
source activate env_name
|
81 |
+
pip install -r requirements.txt
|
82 |
+
```
|
83 |
+
|
84 |
+
**2. 使用 CFGPT1-sft-7B-LoRA**
|
85 |
+
|
86 |
+
```python
|
87 |
+
from transformers import AutoModel, AutoTokenizer
|
88 |
+
from peft import PeftModel
|
89 |
+
base_model = 'TongjiFinLab/CFGPT1-pt-7B'
|
90 |
+
lora_weights = 'TongjiFinLab/CFGPT1-sft-7B-LoRA'
|
91 |
+
device_map = 'cuda:0'
|
92 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model, trust_remote_code=True)
|
93 |
+
model = AutoModel.from_pretrained(
|
94 |
+
base_model,
|
95 |
+
trust_remote_code=True,
|
96 |
+
device_map=device_map,
|
97 |
+
torch_dtype=torch.bfloat16
|
98 |
+
)
|
99 |
+
model = PeftModel.from_pretrained(
|
100 |
+
model,
|
101 |
+
lora_weights,
|
102 |
+
device_map=device_map,
|
103 |
+
)
|
104 |
+
model = model.eval()
|
105 |
+
inputs = tokenizer("""你是一名金融从业者,请对这篇新闻进行情感分析。请从(中性、积极、消极)中选取答案。新闻内容:挖贝快讯:特步国际发布2023年第二季度中国内地业务营运状况,披露截至2023年6月30日止3个月零售销售实现高双位数同比增长(包括线上线下渠道),零售折扣水平约七五折。同时,2022年7月MSCI首次予以特步ESG评级,一年后评级表现即迎来提升。明晟MSCI上调特步ESG评级,由“BB”升至“BBB���。\n回答:""", return_tensors='pt').to(device_map)
|
106 |
+
pred = model.generate(**inputs, max_new_tokens=64, do_sample=False, repetition_penalty=1.0)
|
107 |
+
print(tokenizer.decode(pred.cpu()[0], skip_special_tokens=True).split('回答:')[1])
|
108 |
+
```
|