基于知识增强的LLM智能体规划
<p align="center"> <a href="https://arxiv.org/abs/2403.03101">📄论文</a> • <a href="https://www.zjukg.org/project/KnowAgent/">🌐网站</a> </p> </div> 我们的开发基于几个关键步骤:首先,我们创建了一个广泛的行动知识库,汇集了与特定任务相关的行动规划知识。这个数据库作为外部信息库,指导模型的行动生成过程。随后,通过将行动知识转化为文本,我们使模型能够深入理解并利用这些知识来创建行动轨迹。最后,通过知识性自学习阶段,我们利用模型迭代过程中开发的轨迹来不断提高其对行动知识的理解和应用。这个过程不仅增强了智能体的规划能力,还提高了它们在复杂情况下的应用潜力。
要开始使用KnowAgent,请按以下简单步骤进行安装:
git clone https://github.com/zjunlp/KnowAgent.git cd KnowAgent pip install -r requirements.txt
我们已将HotpotQA和ALFWorld数据集分别放在Path_Generation/alfworld_run/data
和Path_Generation/hotpotqa_run/data
下。对于进 一步的配置,我们建议继续进行ALFWorld和FastChat的原始设置。
规划路径生成过程是KnowAgent的核心部分。你可以在Path_Generation
目录中找到运行规划路径生成的脚本,具体是run_alfworld.sh
和run_hotpotqa.sh
。这些脚本可以使用bash命令执行。要根据你的需求调整脚本,你可以修改mode
参数在训练(train
)和测试(test
)模式之间切换,并更改llm_name
参数以使用不同的LLM:
cd Path_Generation
# 使用HotpotQA进行训练
python run_hotpotqa.py --llm_name llama-2-13b --max_context_len 4000 --mode train --output_path ../Self-Learning/trajs/
# 使用HotpotQA进行测试
python run_hotpotqa.py --llm_name llama-2-13b --max_context_len 4000 --mode test --output_path output/
# 使用ALFWorld进行训练
python alfworld_run/run_alfworld.py --llm_name llama-2-13b --mode train --output_path ../Self-Learning/trajs/
# 使用ALFWorld进行测试
python alfworld_run/run_alfworld.py --llm_name llama-2-13b --mode test --output_path output/
在此我们发布了在过滤前由Llama-{7,13,70}b-chat合成的轨迹,可在Google Drive获取。
获得规划路径和相应轨迹后,知识性自学习过程开始。首先使用Self-Learning
目录中的脚本(如traj_reformat.sh
)将生成的轨迹转换为Alpaca格式。对于初始迭代,使用:
cd Self-Learning
# 对于HotpotQA
python train/Hotpotqa_reformat.py --input_path trajs/KnowAgentHotpotQA_llama-2-13b.jsonl --output_path train/datas
# 对于ALFWorld
python train/ALFWorld_reformat.py --input_path trajs/KnowAgentALFWorld_llama-2-13b.jsonl --output_path train/datas
对于后续迭代,在运行traj_reformat.sh
之前,需要使用traj_merge_and_filter.sh
进行基于知识的轨迹过滤和合并:
python trajs/traj_merge_and_filter.py \
--task HotpotQA \
--input_path1 trajs/datas/KnowAgentHotpotQA_llama-2-13b_D0.jsonl \
--input_path2 trajs/datas/KnowAgentHotpotQA_llama-2-13b_D1.jsonl \
--output_path trajs/datas
接下来,通过运行train.sh
和train_iter.sh
开始自学习,参考Self-Learning/train.sh
和Self-Learning/train_iter.sh
中的脚本:
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 deepspeed train/train_lora.py \
--model_name_or_path llama-2-13b-chat\
--lora_r 8 \
--lora_alpha 16 \
--lora_dropout 0.05 \
--data_path datas/data_knowagent.json \
--output_dir models/Hotpotqa/M1 \
--num_train_epochs 5 \
--per_device_train_batch_size 2 \
--per_device_eval_batch_size 1 \
--gradient_accumulation_steps 1 \
--evaluation_strategy "no" \
--save_strategy "steps" \
--save_steps 10000 \
--save_total_limit 1 \
--learning_rate 1e-4 \
--weight_decay 0. \
--warmup_ratio 0.03 \
--lr_scheduler_type "cosine" \
--logging_steps 1 \
--fp16 True \
--model_max_length 4096 \
--gradient_checkpointing True \
--q_lora False \
--deepspeed /data/zyq/FastChat/playground/deepspeed_config_s3.json \
--resume_from_checkpoint False
@article{zhu2024knowagent, title={KnowAgent: 基于知识增强的LLM智能体规划}, author={朱宇奇 and 乔硕飞 and 欧怡欣 and 邓叔敏 and 张宁豫 and 吕世伟 and 沈玥 and 梁磊 and 顾锦杰 and 陈华钧}, journal={arXiv预印本 arXiv:2403.03101}, year={2024} }
我们对以下项目的创建者和贡献者表示感谢,这些项目对KnowAgent的开发产生了重大影响:
我们衷心感谢所有贡献者对这个领域做出的宝贵贡献!
我们将提供长期维护以修复错误和解决问题。因此,如果您有任何问题,请向我们提出问题。
AI数字人视频 创作平台
Keevx 一款开箱即用的AI数字人视频创作平台,广泛适用于电商广告、企业培训与社媒宣传,让全球企业与个人创作者无需拍摄剪辑,就能快速生成多语言、高质量的专业视频。
一站式AI创作平台
提供 AI 驱动的图片、视频生成及数字人等功能,助力创意创作
AI办公助手,复杂任务高效处理
AI办公助手,复杂任务高效处理。办公效率低?扣子空间AI助手支持播客生成、PPT制作、网页开发及报告写作,覆盖科研、商业、舆情等领域的专家Agent 7x24小时响应,生活工作无缝切换,提升50%效率!
AI辅助编程,代码自动修复
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。