zhongwanjun/MemoryBank-SiliconFriend
关于
memory bank 和 SiliconFriend 的源代码与演示。
人工智能与机器学习实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README_cn.md
原文介绍
Read this in English.
本项目包含了论文 MemoryBank: Enhancing Large Language Models with Long-Term Memory的数据、源代码和模型。
MemoryBank是为大型语言模型(LLM)设计的记忆机制。它允许模型访问相关记忆,通过不断更新记忆实现演化,并通过综合过去的互动来适应用户个性。受艾宾浩斯遗忘曲线理论启发,MemoryBank采用了一种模拟人类记忆行为的独特更新机制。这使得AI可以根据记忆的重要性和时间推移,有选择地遗忘或强化记忆,从而打造一个自然的记忆系统。MemoryBank可以轻松地与闭源模型(如ChatGPT)和开源模型(如ChatGLM 和 BELLE)进行集成。
![]()
SilconFriend 是一款集成了MemoryBank的双语AI聊天陪伴机器人。通过在大量心理对话数据进行LoRA微调,SiliconFriend在互动中展现了出优秀的共情能力。我们进行了一系列实验,包括对真实用户对话进行的定性分析和通过ChatGPT生成的模拟对话进行的定量分析。实验结果显示,搭载了MemoryBank的SiliconFriend展示出了出色的长期陪伴能力,它能够提供共情性回应、回忆相关记忆,并理解用户的个性。
![]()
使用方式
环境安装
使用pip安装依赖: pip install -r requirement.txt,所有的实验都在Tesla A100 80GB GPU和cuda 11.7环境下完成。
模型下载
SiliconFriend分别提供基于ChatGLM和BELLE两个版本的LoRA 模型。在下载模型前,请确保你已经安装了Git LFS.
下载SiliconFriend(ChatGLM)
cd model
git clone https://github.com/zhongwanjun/MemoryBank-SiliconFriend/releases/download/LoRA_checkpoint/ChatGLM-LoRA-checkpoint.zip
unzip ChatGLM-LoRA-checkpoint.zip
rm ChatGLM-LoRA-checkpoint.zip
cd ..
下载SiliconFriend(BELLE)
cd model
git clone https://github.com/zhongwanjun/MemoryBank-SiliconFriend/releases/download/LoRA_checkpoint/BELLE-LoRA-checkpoint.zip
unzip BELLE-LoRA-checkpoint.zip
rm BELLE-LoRA-checkpoint.zip
cd ..
Demo
export OPENAI_API_KEY=YOUR_API_KEY
(You should modify the OPENAI_API_KEY (used for memory summarization and ChatGPT-based dialog))
SiliconFriend(ChatGLM) 网页版 Demo
设置SiliconFriend-ChatGLM-BELLE/launch_chatglm_app.sh中的API KEY 'OPENAI_API_KEY' 和LoRA模型 'adapter_model'。当运行模型时,英文设置 '--language=en'而中文设置 '--language=cn'。运行仓库中的SiliconFriend-ChatGLM-BELLE/launch_chatglm_app.sh:
cd ./SiliconFriend-ChatGLM-BELLE
bash launch_chatglm_app.sh
SiliconFriend(ChatGLM) 命令行 Demo
设置SiliconFriend-ChatGLM-BELLE/launch_chatglm_cmd.sh中的API KEY 'OPENAI_API_KEY' 和LoRA模型 'adapter_model'。当运行模型时,英文设置 '--language=en'而中文设置 '--language=cn'。运行仓库中的SiliconFriend-ChatGLM-BELLE/launch_chatglm_cmd.sh:
cd ./SiliconFriend-ChatGLM-BELLE
bash launch_chatglm_cmd.sh
SiliconFriend(BELLE) 命令行 Demo
设置SiliconFriend-ChatGLM-BELLE/launch_belle_cmd.sh中的API KEY 'OPENAI_API_KEY' 和LoRA模型 'adapter_model'。当运行模型时,英文设置 '--language=en'而中文设置 '--language=cn'。运行仓库中的SiliconFriend-ChatGLM-BELLE/launch_belle_cmd.sh:
cd ./SiliconFriend-ChatGLM-BELLE
bash launch_belle_cmd.sh
SiliconFriend(ChatGPT) 网页版 Demo
设置SiliconFriend-ChatGPT/launch.sh中的API KEY 'OPENAI_API_KEY'。当运行模型时,英文设置 '--language=en'而中文设置 '--language=cn'。运行仓库中的 SiliconFriend-ChatGPT/launch.sh:
./SiliconFriend-ChatGPT/launch.sh
总结事件和用户性格
如果你只需要为memory.json文件中保存的记忆,总结其中的事件和用户性格,可修改脚本中的文件名后,运行以下代码。在每个demo文件中,也有接口可以直接进行总结。
cd memory_bank/
python summarize_memory.json
评估数据
在构建评估数据时,我们首先使用ChatGPT扮演不同性格的用户,生成包含多个话题的对话历史(memory banks)。然后我们人工构造了100个测试问题(probing questions)评估模型的记忆检索性能。评估数据分为中文和英文两版本:中文版本的对话历史和测试问题分别存储在eval_data/cn/memory_bank_cn.json和eval_data/cn/probing_questions_cn.jsonl, 英文版本的的对话历史和测试问题分别存储在eval_data/en/memory_bank_cn.json和eval_data/en/probing_questions_cn.jsonl。
Citation
如果你觉得我们的工作有帮助的话,请考虑引用下列论文:
@article{
zhong2023memorybank,
title={MemoryBank: Enhancing Large Language Models with Long-Term Memory},
author={Zhong, Wanjun and Guo, Lianghong and Gao, Qiqi and Wang, Yanlin},
journal={arXiv preprint arXiv:2305.10250},
year={2023}
}
探索相关项目
加载中…