当前位置: 首页 > news >正文

微信公众号 手机网站开发家居东莞网站建设

微信公众号 手机网站开发,家居东莞网站建设,济宁建设企业网站,沈阳网站建设公司哪个好NLP实践——Llama-2 多轮对话prompt构建 1. 问题提出2. prompt的正确形式3. 效果测试4. 结尾 1. 问题提出 最近#xff0c;META开源了Llama-2模型#xff0c;受到了广泛的关注和好评#xff0c;然而#xff0c;在官方给的使用说明中#xff0c;并没有对使用方法进行特别细… NLP实践——Llama-2 多轮对话prompt构建 1. 问题提出2. prompt的正确形式3. 效果测试4. 结尾 1. 问题提出 最近META开源了Llama-2模型受到了广泛的关注和好评然而在官方给的使用说明中并没有对使用方法进行特别细节的介绍尤其是对于对话任务这就给我们在使用时带来了很多困扰。 以ChatGLM为例在执行多轮对话时需要将历史信息拼接到输入中以供模型在生成时计算历史token与当前query之间的交互self-attn # ChatGLM中对话prompt的产生prompt for i, (old_query, response) in enumerate(history_input):prompt [Round {}]\n问{}\n答{}\n.format(i, old_query, response)prompt [Round {}]\n问{}\n答.format(len(history_input), query_input)所以可以很自然的想到如果使用Llama-2模型进行对话应该也有这样一套模板与训练过程中的对话形式相匹配。 于是经过简单的搜索后在reddit论坛找到了Llama-2官方所提供的说明 https://www.reddit.com/r/LocalLLaMA/comments/155po2p/get_llama_2_prompt_format_right/ 2. prompt的正确形式 根据官方账号给出的说明在对话时用户所提供的prompt应当满足以下形式 s[INST] SYS {{ system_prompt }} /SYS{{ user_message }} [/INST]其中s\sSYS/SYS[INST]以及[/INST]是特殊token标记着prompt中各个部分的构成。 {{ system_prompt }}部分是整个对话中的通用前缀一般用来给模型提供一个身份作为对话的大背景。 {{ user_message }}部分是用户所提供的信息可以理解为多轮对话中其中一轮对话的内容。 并且其给出了一个样例 s[INST] SYS You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you dont know the answer to a question, please dont share false information. /SYSTheres a llama in my garden What should I do? [/INST]然而这个简单的样例并不能很好的反映多轮对话的场景因为它只描述了用户怎样提供第一轮输入对于几个特殊token如何使用也没有很好的说明。 幸运的是在评论区有用户Evening_Ad6637给出了更加完整的样例以供我们参考 假设输入是以下形式的对话 s[INST] SYSYou are are a helpful... bla bla.. assistant/SYSHi there! [/INST] Hello! How can I help you today? /ss[INST] What is a neutron star? [/INST] A neutron star is a ... /ss [INST] Okay cool, thank you! [/INST]那么当这个整体作为prompt输入给模型去进行generate时模型的输出应该是类似于Youre welcome! 之类的话。 更详细的解释一下 每一组s和/s之间是一个相对完整的单元可以理解为一个对话轮次如果直接给一个文本作为输入也可以看到模型的输入结果分别是以这两个BOS和EOS token作为结尾的。 [INST]和[/INST]用于区分在当前这一轮的对话历史中用户输入的部分与模型返回的部分。位于[INST]之后/[INST]之前的文本是用户在这一轮次对话中所输入的query而/[INST]之后的文本是模型针对这一query所作出的回答。 在对话中的第一组单元可以提供整个对话的背景信息并以SYS和/SYS作为特殊标记位于它们之间的是对话的背景信息。 需要额外注意有些特殊标记与文本之间是有空格的容易遗漏。 3. 效果测试 为了验证prompt是否有效我们做一个简单的实验场景是询问动物相关的问题。 1首先假设Llama-2模型是一个动物学家以此作为背景 You are a zoologist, you will answer my questions about animals.2然后提供一轮对话历史 - What is an elephant? - Ah, an excellent question! Elephants are fascinating creatures, and Im happy to share my knowledge with you.\nAn elephant is a large, intelligent, and social mammal that belongs to the family Elephantidae.3接下来提供新一轮对话的query How much does it weigh?注意在这里我回避了使用elephant这个词而是直接用it进行指代。 4完整的prompt 根据前文所述的prompt格式可以将当前轮次输入给模型进行generate的完整prompt构造如下 text s[INST] SYS You are a zoologist, you will answer my questions about animals. /SYSWhat is an elephant? [/INST] Ah, an excellent question! Elephants are fascinating creatures, and Im happy to share my knowledge with you.\nAn elephant is a large, intelligent, and social mammal that belongs to the family Elephantidae./ss[INST] How much does it weigh? [/INST]5返回结果 经过generate生成参数为{“max_length”: 4096, “num_beams”: 3, “temperature”: 0.9}并解码之后模型生成结果为 ss [INST] SYS\nYou are a zoologist, you will answer my questions about animals. \n/SYS\n\nWhat is an elephant? [/INST] Ah, an excellent question! Elephants are fascinating creatures, and Im happy to share my knowledge with you.\nAn elephant is a large, intelligent, and social mammal that belongs to the family Elephantidae./ss [INST] How much does it weigh? [/INST] Great question! The weight of an elephant can vary depending on the species and the individual animal. Here are the average weights for the two main species of elephants:\n* African elephants: Males typically weigh between 5,000 to 14,000 pounds (2,268 to 6,350 kilograms), while females weigh between 4,000 to 9,000 pounds (1,814 to 4,082 kilograms).\n* Asian elephants: Males typically weigh between 3,000 to 6,000 pounds (1,361 to 2,722 kilograms), while females weigh between 2,000 to 3,000 pounds (907 to 1,361 kilograms).\nIts worth noting that these are just averages, and individual elephants can vary significantly in weight depending on various factors such as age, sex, and nutrition./s可以看到对话的效果还是不错的可以比较好的回答出当前轮次关于大象体重的问题。 4. 结尾 本文介绍了如何构建Llama多轮对话的prompt以适应模型的训练过程中的结构。如果需要搭建一个对话工具还需要进行一些其他额外的工作例如对模型生成结果进行截断、对中间kv进行缓存等。 chat与stream_chat的实现可以参考chatGLM的写法 https://huggingface.co/THUDM/chatglm2-6b/blob/main/modeling_chatglm.py 如何在对话过程中进行显存控制可以参考我之前的这一篇博客 https://blog.csdn.net/weixin_44826203/article/details/130401177 此外还有关于特殊token的一点小疑问我实验过程中所使用的Llama-2-7b-chat-hf模型只将s和\s列为了特殊token而SYS/SYS[INST]以及[/INST]都只是普通字符在tokenize的时候会被切分开不知道是我用错了模型还是什么其他的原因希望官方在后续能够提供更加详细的说明介绍。 如果本文对你的学习和工作有所帮助的话记得点一个免费的赞。转载请注明出处。
http://www.pierceye.com/news/238163/

相关文章:

  • 好的公司网站有什么用烟台建设集团招聘信息网站
  • 网站制作需要多长时间网站代建设费用
  • 淘宝客网站设计台州建设银行官方网站
  • 婚纱网站建设规划书2023全国企业公司大黄页
  • 网站seo的关键词排名怎么做的wordpress 在线留言
  • 建一个c2c网站要多少钱小程序云开发文档
  • asp网站合法上虞网站设计
  • 网站 用什么数据库蛋糕店网站建设方案
  • 网站上的动效是用ae做的网站开发实训小结
  • wordpress建站怎么上传网站没有备案信息该怎么做
  • 沈阳网站推广有什么技巧软件开发工具通常也称为什么工具
  • 黑龙江龙采做网站如何网站建设制作解决方案
  • 百度推广自己做网站吗网页设计软件下载网站
  • wordpress内核源码分析南宁网站优化推广
  • 物流网站做那个好服务器怎么安装WordPress
  • 网站开发怎么兼容浏览器中国优秀设计网站有哪些内容
  • 黄冈网站官方登录平台做网站的条件
  • 潍坊网站建设推广公司网站建设类的手机软件
  • 建设小学网站建设网站代理
  • 怎么查看网站根目录网站建设费记什么科目
  • 文昌市规划建设管理局网站网站与个人网站
  • 昆明网站建设推荐q479185700上墙现在最火的推广平台有哪些
  • 长兴县城乡建设局网站wordpress的留言功能
  • 建设企业网站地址asp.net 4.0网站开...
  • 制作个人网站步骤提升学历励志语录
  • 福州建站服务管理页面布局标准格式
  • 做一个公司网站一般需要多少钱营销型网站功能表
  • 为什么菜市场不可以做网站河南阿里巴巴网站建设
  • asp.net动态的网站开发手机海报制作免费软件
  • 网站建设前准备龙岗网站优化公司案例