欢迎光临散文网 会员登陆 & 注册

中文金融知识问答神器!LLaMA智能系统微调模型教学全解析

2023-07-30 17:17 作者:汀丶人工智能  | 我要投稿

基于中文金融知识的 LLaMA 系微调模型的智能问答系统:LLaMA大模型训练微调推理等详细教学

基于 LLaMA 系基模型经过中文金融知识指令精调/指令微调(Instruct-tuning) 的微调模型。通过中文金融公开问答数据+爬取的金融问答数据构建指令数据集,并在此基础上对 LLaMA 系模型进行了指令微调,提高了 LLaMA 在金融领域的问答效果。

基于已有数据和继续爬取的中文金融数据,将继续利用 GPT3.5/4.0 API 构建高质量的数据集,另在中文知识图谱-金融、CFLEB 金融数据集等数据上进一步扩充高质量指令数据集。

  • 基于 Chinese-LLaMA 和中文金融数据进行指令微调的模型。

  • 基于 Meta-LLaMA 和中文金融数据进行指令微调的模型。

1. 环境安装

首先安装依赖包,python环境建议3.9+

pip install -r requirements.txt

其次安装 lfs 方便本地下载 LLaMa 大模型

git lfs install # 下载7B模型到本地 bash ./base_models/load.sh

2.模型下载

LoRA 权重可以通过 Huggingface 下载,结构如下:

    Fin-Alpaca-LoRA-7B-Meta/        - adapter_config.json   # LoRA权重配置文件        - adapter_model.bin     # LoRA权重文件


3.Inference:单模型推理-多模型对比

目前在./instruction_data/infer.json中提供了一些测试用例,也可替换成其它的数据集但注意格式保持一致

运行infer脚本

#单模型推理 bash ./scripts/infer.sh #多模型对比 bash ./scripts/comparison_test.sh

4.数据集构建

此前版本采用了公开和爬取的中文金融领域问答数据,涉及到保险、理财、股票、基金、贷款、信用卡、社保等。

指令数据示例如下:

问题:办理商业汇票应遵守哪些原则和规定?

针对此前数据仍存在不准确和类型单一等不完善的地方;目前我们利用GPT3.5/4.0 接口进一步优化数据、并扩充中文金融知识库,设置多种Prompt形式、multi-task形式拓展丰富指令数据集,实现金融领域多业务场景覆盖。

最新模型情况:(即将发布,敬请期待~)

5.微调Finetune

若想用自己的数据集微调 LLaMA,请按照./instruction_data/fin_data.json的格式构建自己的数据集

运行 finetune 脚本

bash ./scripts/finetune.sh

6.训练细节

6.1 计算资源需求

目前训练设备为一张A100-SXM-80GB显卡,训练总轮次10轮。batchsize=64的情况下显存占用在40G左右、batchsize=96的情况下显存占用在65G左右。预计3090/4090显卡(24GB显存)以上显卡可以较好支持,根据显存大小来调整batch_size。

6.2实验记录

6.3 模型效果对比




7.提示词模板

此目录包含用于 LoRA 微调 LLaMa 模型的提示的模板样式。

  • Format

模板是通过一个JSON文件描述的,该文件包含以下键:

  • prompt_input: The template to use when input is not None. Uses {instruction} and {input} placeholders.

  • prompt_no_input: The template to use when input is None. Uses {instruction} placeholders.

  • description: A short description of the template, with possible use cases.

  • response_split: The text to use as separator when cutting real response from the model output.

No {response} placeholder was used, since the response is always the last element of the template and is just to be concatenated to the rest.

7.1模板案例

The default template, used unless otherwise specified, is alpaca.json

{    "description": "Template used by Alpaca-LoRA.",    "prompt_input": "Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\n{instruction}\n\n### Input:\n{input}\n\n### Response:\n",    "prompt_no_input": "Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\n{instruction}\n\n### Response:\n",    "response_split": "### Response:"     }

7.2 现有模板

7.2.1 alpaca

到目前为止,用于通用LoRA微调的默认模板。

7.2.2 alpaca_legacy

原始羊驼使用的旧模板,响应字段后没有“\n”。保留以供参考和实验。

7.2.3 alpaca_short

一个修剪过的羊驼模板,它似乎也表现得很好,并保留了一些 tokens。使用默认模板创建的模型似乎也可以通过短时间查询。

8.提示构建模块

  • prompter.py

Prompter class, a template manager.

from utils.prompter import Prompter

[项目链接跳转]https://blog.csdn.net/sinat_39620217/article/details/132007040

更多优质内容请关注公号:汀丶人工智能;会提供一些相关的资源和优质文章,免费获取阅读。



中文金融知识问答神器!LLaMA智能系统微调模型教学全解析的评论 (共 条)

分享到微博请遵守国家法律