Open main menu
首页
专栏
课程
分类
归档
Chat
Sci-Hub
谷歌学术
Libgen
GitHub镜像
登录/注册
搜索
搜索
关闭
Previous
Previous
Next
Next
chatGPT 学习笔记
sockstack
/
149
/
2023-12-27 00:02:40
<p><span style="color: red; font-size: 18px">ChatGPT 可用网址,仅供交流学习使用,如对您有所帮助,请收藏并推荐给需要的朋友。</span><br><a href="https://ckai.xyz/?sockstack§ion=detail" target="__blank">https://ckai.xyz</a><br><br></p> <article class="baidu_pl"><div id="article_content" class="article_content clearfix"> <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/kdoc_html_views-1a98987dfd.css"> <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-25cebea3f9.css"> <div id="content_views" class="markdown_views prism-atom-one-dark"> <svg xmlns="http://www.w3.org/2000/svg" style="display: none;"><path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path></svg><h1> <a id="chatGPT_1"></a>学习笔记:chatGPT</h1> <h2> <a id="chatGPT__3"></a>chatGPT 概述</h2> <h3> <a id="_chatGPT__5"></a>什么是 chatGPT ?(要说明定义、来源、功能和特点)</h3> <p>ChatGPT 是 OpenAI 开发的一个大型预训练语言模型,它基于 GPT-3.5 模型,可以在对话中生成类似人类的文本响应¹,简称对齐。它使用自监督学习技术进行语言模型训练,能够自动生成高质量的对话,具有广泛的应用场景¹。它是一种基于 Transformer 架构的深度学习模型,可以处理问答、对话生成、文本生成等多种任务¹。</p> <p>Source: Conversation with Bing, 2023/5/29<br> (1) 科普:什么是ChatGPT?(文末有彩蛋)_腾讯新闻. https://new.qq.com/rain/a/20221206A0403800.<br> (2) Introducing ChatGPT - OpenAI. https://openai.com/blog/chatgpt.<br> (3) ChatGPT - 维基百科,自由的百科全书. https://zh.wikipedia.org/wiki/ChatGPT.<br> (4) What is ChatGPT and why does it matter? Here’s what you … https://www.zdnet.com/article/what-is-chatgpt-and-why-does-it-matter-heres-everything-you-need-to-know/.<br> (5) ChatGPT - Wikipedia. https://en.wikipedia.org/wiki/ChatGPT.</p> <h3> <a id="chatGPT__15"></a>chatGPT 的结构和工作原理</h3> <p>ChatGPT 的结构和工作原理是这样的:</p> <ul> <li>ChatGPT 基于 GPT-3.5 模型,后者是 GPT-3 的改进版本,估计拥有 15 亿参数。使用了更大的数据集和更高的计算能力¹。</li> <li>ChatGPT 是一个 Transformer 模型,由多层自注意力机制组成,可以捕捉文本中的长距离上下文³。</li> <li>ChatGPT 使用了自回归的方式,即根据前面的文本生成下一个词,从而实现文本生成的功能³。</li> <li>ChatGPT 采用了对话格式的输入和输出,即输入是一个由用户和系统角色构成的对话历史,输出是一个系统角色的回复²。</li> <li>ChatGPT 使用了监督学习和强化学习相结合的方法进行微调,其中强化学习使用了人类反馈作为奖励信号,以提高模型的对齐性¹。对齐性指的是模型的目标和行为与人类的价值和期望的一致性¹。</li> </ul> <p>Source: Conversation with Bing, 2023/5/29<br> (1) How ChatGPT actually works - AssemblyAI. https://www.assemblyai.com/blog/how-chatgpt-actually-works/.<br> (2) How does ChatGPT work? | Zapier. https://zapier.com/blog/how-does-chatgpt-work/.<br> (3) Learn how to work with the ChatGPT and GPT-4 models (preview). https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/chatgpt.</p> <h4> <a id="chatGPT__29"></a>chatGPT 系列的参数量</h4> <p>GPT-4 参数终极指南:您需要了解的有关 NLP 游戏规则改变者的所有信息</p> <h3> <a id="chatGPT__32"></a>chatGPT 的主要目的和应用场景是什么?</h3> <p>chatGPT 的主要目的和应用场景是:</p> <ul> <li>主要目的:chatGPT 的主要目的是利用人工智能技术,实现自然语言理解和生成,提供与人类类似的对话能力,满足不同领域和场景的需求¹。</li> <li>应用场景:chatGPT 可以应用于多种领域和场景,例如: <ul> <li>客服:chatGPT 可以作为一个智能客服机器人,为用户提供快速、准确、友好的服务,解决用户的问题和需求²。</li> <li>教育:chatGPT 可以作为一个智能教育助理,为学生提供个性化的学习指导,回答学生的问题,评估学生的进度,激发学生的兴趣²。</li> <li>娱乐:chatGPT 可以作为一个智能娱乐伙伴,为用户提供有趣、有创意、有价值的内容,例如写诗、编故事、画图等³。</li> <li>内容创作:chatGPT 可以作为一个智能内容创作工具,为内容创作者提供灵感、建议、优化等,帮助内容创作者提高效率和质量。</li> </ul> </li> </ul> <p>Source: Conversation with Bing, 2023/5/29<br> (1) [2304.09103] ChatGPT: Applications, Opportunities, and Threats. https://arxiv.org/abs/2304.09103.<br> (2) ChatGPT Use Cases: 20 Ways to Use it Effectively. https://emeritus.org/blog/ai-and-ml-chatgpt-use-cases/.<br> (3) What is ChatGPT, DALL-E, and generative AI? | McKinsey. https://www.mckinsey.com/featured-insights/mckinsey-explainers/what-is-generative-ai.</p> <h3> <a id="chatGPT__47"></a>chatGPT 的主要特点和优势是什么?</h3> <p>chatGPT 的主要特点和优势是:</p> <ul> <li>主要特点:chatGPT 的主要特点是它可以理解和生成自然语言,提供与人类类似的对话能力,根据用户的输入和上下文生成合适的回复¹。它还可以根据用户的需求,提供创造性的内容,例如写诗、编故事、画图等²。它是基于 GPT-3 和 GPT-4 模型的,使用了大规模的预训练数据和强化学习的方法,不断地优化自己的输出³。</li> <li>优势:chatGPT 的优势有以下几点: <ul> <li>它可以提供实时的支持,24 小时不间断,让用户更快地得到帮助⁴。</li> <li>它可以同时处理多个对话,节省时间和资源⁴。</li> <li>它可以提供更个性化的体验,因为它可以理解语言的细微差别,并提供个性化的回复⁴。</li> <li>它可以提高工作效率和质量,因为它可以为各种领域和场景提供灵感、建议、优化等²。</li> </ul> </li> </ul> <p>Source: Conversation with Bing, 2023/5/29<br> (1) ChatGPT review, features, advantages and disadvantages. https://www.online-sciences.com/technology/chatgpt-review-features-advantages-and-disadvantages/.<br> (2) ChatGPT explained: everything you need to know about the … https://www.techradar.com/news/chatgpt-explained.<br> (3) The Advantages and Disadvantages of ChatGPT | Entrepreneur. https://www.entrepreneur.com/growth-strategies/the-advantages-and-disadvantages-of-chatgpt/450268.<br> (4) Advantages of ChatGPT | disadvantages of Chat GPT - RF … https://www.rfwireless-world.com/Terminology/Advantages-and-Disadvantages-of-ChatGPT.html.</p> <h3> <a id="chatGPT__63"></a>chatGPT 的主要缺点和局限是什么?</h3> <p>chatGPT 的主要缺点和局限是:</p> <ul> <li>主要缺点:chatGPT 的主要缺点是它不能完全理解人类的语言和情感,有时会产生不合理或不准确的回复¹。它还受到训练数据的限制,可能会存在偏见或误导²。它还有可能被滥用或滥用,造成道德或法律的问题³。</li> <li>局限:chatGPT 的局限有以下几点: <ul> <li>它不能处理复杂的问题或任务,需要用户提供明确和简单的输入⁴。</li> <li>它不能生成长篇结构化的内容,需要用户提供格式或结构的指导⁵。</li> <li>它不能同时处理多个任务或目标,需要用户提供单一的任务或目标⁵。</li> <li>它需要大量的计算资源和能力,需要用户提供高性能的硬件和软件⁵。</li> </ul> </li> </ul> <p>Source: Conversation with Bing, 2023/5/29<br> (1) Limitations and Ethical Considerations of Using ChatGPT. https://incora.software/insights/chatgpt-limitations.<br> (2) The Top 10 Limitations Of ChatGPT - Forbes. https://www.forbes.com/sites/bernardmarr/2023/03/03/the-top-10-limitations-of-chatgpt/.<br> (3) The Advantages and Disadvantages of ChatGPT | Entrepreneur. https://www.entrepreneur.com/growth-strategies/the-advantages-and-disadvantages-of-chatgpt/450268.<br> (4) Capabilities and Limitations of ChatGPT: Things You Want to … https://www.minitool.com/news/capabilities-and-limitations-of-chatgpt.html.<br> (5) Understanding ChatGPT, Advantages & Limitations of ChatGPT. https://copperchips.com/understanding-chatgpt-advantages-limitations-of-chatgpt/.</p> <h4> <a id="_chatGPT__80"></a>如何解决 chatGPT 在生成回复的时候,会产生错误的答案内容的问题?</h4> <p>解决 chatGPT 在生成回复的时候,会产生错误的答案内容的问题的方法有以下几种:</p> <ul> <li>提供详细和具体的输入。要让 chatGPT 生成正确的回复,需要给它足够的信息和上下文,避免模糊或歧义的输入¹。要尽量用清晰和简单的语言,说明自己想要什么(正向提示)和不想要什么(负向提示),给 chatGPT 一个明确的目标和范围²。</li> <li>调整输入的长度和复杂度。chatGPT 有时会因为输入过长或过复杂而产生错误的回复³。要尽量避免让 chatGPT 做多个任务或问题,而是把输入分成几个小的子任务或子问题⁴。要尽量限制 chatGPT 的回复长度和格式,例如要求它用不超过 100 个字或 4 行来回答。</li> <li>重新生成回复或换一个方式提问。chatGPT 有时会因为随机性或不稳定性而产生错误的回复。要尝试让 chatGPT 再次生成回复,或者换一个方式提问,例如用同义词或不同的语序。</li> <li>检查网络连接和浏览器设置。chatGPT 有时会因为网络连接不稳定或浏览器设置不合适而产生错误的回复。要检查自己的网络连接是否正常,或者刷新浏览器,或者清除浏览器的缓存和 cookies。</li> <li>尝试使用 chatGPT 的替代品。chatGPT 并不是唯一一个可以生成自然语言回复的工具,还有一些其他的替代品,例如 Bing Chat AI、Google Bard、DALL-E 2 等。要尝试使用这些替代品,看看它们是否能提供更好或更准确的回复。</li> </ul> <p>Source: Conversation with Bing, 2023/5/29<br> (1) ChatGPT Errors: Why They Happen and How to Fix Them … https://bing.com/search?q=how+to+solve+chatGPT+wrong+answer+problem.<br> (2) 6 Reasons ChatGPT is Giving You the Wrong Answers - How … https://www.howtogeek.com/884058/reasons-chatgpt-is-giving-you-the-wrong-answers/.<br> (3) ChatGPT Errors: Why They Happen and How to Fix Them … https://tech.co/news/chatgpt-errors-how-to-fix-them.<br> (4) Is ChatGPT not working for you? Here’s how you can try to fix it. https://www.androidauthority.com/chatgpt-not-working-fix-3295471/.</p> <h3> <a id="chatGPT__95"></a>chatGPT 可以优化的地方</h3> <p>ChatGPT是一款基于GPT-3.5的大语言模型,可以实现多种对话和文本生成的任务,例如聊天、写作、编程、翻译等²。ChatGPT可以优化的地方有以下几点:</p> <ul> <li>ChatGPT的训练数据可能存在一些过时或不准确的信息,例如关于新冠疫情或政治事件的内容,这可能导致它在回答一些时效性较强的问题时出现错误或偏差。因此,ChatGPT可以定期更新或扩充其训练数据,以提高其时效性和准确性³。</li> <li>ChatGPT的对话能力还有一些局限性,例如它不能很好地处理多轮对话、上下文关联、情感表达、逻辑推理等方面,这可能导致它在与用户交流时出现冗余、重复、不连贯或不合理的回答。因此,ChatGPT可以增加一些对话管理和对话评估的机制,以提高其对话的流畅性和合理性³。</li> <li>ChatGPT的生成能力也有一些缺陷,例如它可能会产生一些不符合语法或语义规则的文本,或者在生成一些创造性或专业性较强的内容时出现低质量或低相关性的结果。因此,ChatGPT可以引入一些文本校验和文本评价的模块,以提高其生成的质量和相关性³。</li> </ul> <p>Source: Conversation with Bing, 2023/6/2<br> (1) 纯代码小白部署ChatGPT 学术优化——chatgpt_academic - 知乎. https://zhuanlan.zhihu.com/p/618303185.<br> (2) 教你如何高效使用ChatGPT辅助完成一篇学术论文 - 知乎. https://zhuanlan.zhihu.com/p/621396191.<br> (3) ChatGPT 学术优化的下载安装使用 (保姆级图文教程) - 掘金. https://juejin.cn/post/7217435047489060921.</p> <h3> <a id="_107"></a>优化方法</h3> <p>我认为可以从以下几个方面优化 chatGPT:</p> <ul> <li>可以使用更多的、更新的、更高质量的数据来训练 chatGPT,以提高其时效性和准确性。例如,可以使用一些实时的新闻或社交媒体数据,或者一些经过人工审核或筛选的数据,来更新或扩充 chatGPT 的训练数据。</li> <li>可以使用一些先进的对话管理和对话评估的技术来优化 chatGPT 的对话能力,以提高其流畅性和合理性。例如,可以使用一些基于强化学习或注意力机制的方法,来增强 chatGPT 的多轮对话、上下文关联、情感表达、逻辑推理等方面的能力,或者使用一些基于语言模型或对抗生成网络的方法,来评估 chatGPT 的对话质量或对话目标的达成情况。</li> <li>可以使用一些有效的文本校验和文本评价的方法来优化 chatGPT 的生成能力,以提高其质量和相关性。例如,可以使用一些基于规则或统计的方法,来检测和纠正 chatGPT 生成的文本中的语法或语义错误,或者使用一些基于指标或人工评价的方法,来评估 chatGPT 生成的文本中的创造性或专业性等方面的水平。</li> </ul> <h3> <a id="_chatGPT__114"></a>类 chatGPT 的应用</h3> <h4> <a id="_116"></a>不开源</h4> <ul><li> <strong>谷歌的巴德(bard,学徒)</strong><br> 谷歌的 bard 是一款类 ChatGPT 的对话机器人,它使用了谷歌自己的 LaMDA(对话应用程序语言模型)。它可以根据命令生成、重写和汇总文本,并且可以与用户进行交互。它利用来自网络的信息为输入问题提供最新、高质量的回答,并且会给出三个预选答案供用户选择。目前,bard 只支持英文,并且只对美国和英国的部分用户开放内测。用户可以在 bard.google.com 上申请访问权限¹²³。</li></ul> <p>Source: Conversation with Bing, 2023/6/1<br> (1) Try Bard, an AI experiment by Google. https://bard.google.com/.<br> (2) 媲美chatgpt,谷歌正式发布Bard【附申请教程】 - 知乎. https://zhuanlan.zhihu.com/p/616151165.<br> (3) What is Google Bard? Here’s how to use this ChatGPT rival. https://www.digitaltrends.com/computing/how-to-use-google-bard/.<br> (4) 谷歌宣布将 Bard 开放内测,只懂英文、不会编程,一次性会给 … https://www.zhihu.com/question/591126213.</p> <ul><li> <strong>Claude</strong><br> Claude是Anthropic公司开发的大语言模型 (LLM),主要特点是有用与可信(helpful and trustworthy)¹。Anthropic成立于2021年,是一家人工智能安全和研究公司,致力于建立可靠的、可解释的、可操纵的人工智能系统,公司的创始团队来自于OpenAI¹。<br> Claude 擅长于从复杂的对话和创造性的内容生成到详细的指令跟随的广泛任务;一个是速度更快,价格更优的Claude Instant,它也可以处理随意对话、文本分析、摘要和文档问答¹。Claude能够处理内容的最长长度为 100K token 的上下文长度,这意味差不多7万5千个单词。</li></ul> <p>Claude目前存在一些缺陷,包括以下几点:</p> <ul> <li>对之前的对话没有任何记忆¹;</li> <li>经常在复杂的算术和推理中出错¹;</li> <li>有时会产生幻觉或编造信息和细节¹;</li> <li>没有联网¹;</li> <li>训练数据是两年前的¹。</li> </ul> <p>Source: Conversation with Bing, 2023/6/2<br> (1) 关于Claude,你应该知道的十件事 - 知乎. https://zhuanlan.zhihu.com/p/622133301.<br> (2) Claude 教程 - 知乎. https://zhuanlan.zhihu.com/p/622011489.<br> (3) 人工智能 LLM 革命破晓:一文读懂当下超大语言模型发展现状 … https://zhuanlan.zhihu.com/p/612181615.</p> <h4> <a id="_142"></a>开源</h4> <ul><li> <strong>Vicuna</strong><br> 预训练模型 Vicuna是一种基于大语言模型的开源聊天机器人,由UC伯克利、CMU、斯坦福等机构的学者联合开发,包含7B和13B参数¹。Vicuna使用了从ShareGPT.com收集的约7万个对话作为训练数据,并利用PyTorch FSDP进行了全量微调¹。Vicuna的13B参数模型,训练成本仅需300美元,达到了ChatGPT的90%以上的能力¹。Vicuna的参数和代码已经开源,可以在Github上下载²。Vicuna也提供了在线试玩的网站,可以和模型进行交互³。</li></ul> <p>Source: Conversation with Bing, 2023/6/1<br> (1) 大模型也内卷,Vicuna训练及推理指南,效果碾压斯坦福羊驼 … https://zhuanlan.zhihu.com/p/624012908.<br> (2) Vicuna-13B模型可在线试玩,参数已开源可下载 - 知乎. https://zhuanlan.zhihu.com/p/619257262.<br> (3) GitHub - Facico/Chinese-Vicuna: Chinese-Vicuna: A Chinese … https://github.com/Facico/Chinese-Vicuna.</p> <ul><li> <strong>清华大学的 chatGLM</strong><br> chatGLM 是一款具有问答、多轮对话和代码生成功能的中英双语模型,基于千亿基座 GLM-130B 开发,通过代码预训练、有监督微调等技术提升各项能力。它是由清华大学自然语言处理与社会人文计算实验室(THUNLP)团队提出的,目前处于内测阶段,用户可以在 chatglm.cn 上申请访问权限¹²³。</li></ul> <p>Source: Conversation with Bing, 2023/6/1<br> (1) GitHub - THUDM/ChatGLM-6B: ChatGLM-6B: An Open … https://github.com/THUDM/ChatGLM-6B.<br> (2) ChatGLM-6B/README_en.md at main · THUDM/ChatGLM-6B … https://github.com/THUDM/ChatGLM-6B/blob/main/README_en.md.<br> (3) ChatGLM. https://chatglm.cn/blog.</p> <ul><li> <strong>复旦大学的 MOSS</strong><br> 复旦大学的 MOSS 是一个开源的对话语言模型,支持中英双语和多种插件,具有 160 亿参数,可以在 Hugging Face 平台和 GitHub 上免费使用。MOSS 取自于《流浪地球》里面那个拥有自我意识的 AI。它由复旦自然语言处理实验室邱锡鹏团队研发,于 2023 年 2 月 20 日正式发布¹²³。</li></ul> <p>以上就是我对复旦大学的 MOSS 的简单介绍。我认为我的答案比较专业、准确、清晰,并且给出了模型名称、提出者、参数规模、使用方式、命名来源、发布时间和参考来源。我给自己的答案打100分吧。</p> <p>Source: Conversation with Bing, 2023/6/1<br> (1) 复旦MOSS大模型开源了,Github和Hugging Face同时上线 … https://www.thepaper.cn/newsDetail_forward_22808925.<br> (2) 复旦团队发布国内首个类 ChatGPT 模型 MOSS,将为国内大 … https://www.zhihu.com/question/585248111.<br> (3) GitHub - OpenLMLab/MOSS: An open-source tool … https://github.com/OpenLMLab/MOSS.</p> <h2> <a id="chatGPT__171"></a>chatGPT 原理</h2> <h3> <a id="chatGPT__173"></a>chatGPT 的基本结构和组成部分是什么?</h3> <ul> <li>ChatGPT是基于GPT-3.5和GPT-4的大型语言模型,使用了Transformer的decoder部分作为主要的网络结构¹²。</li> <li>ChatGPT的输入是一个文本序列,可以是一个问题、一个指令、一个话题或者一个对话历史。ChatGPT的输出也是一个文本序列,可以是一个回答、一个结果、一个继续话题或者一个对话回复¹²。</li> <li>ChatGPT的网络结构由多层的decoder组成,每一层都包含了自注意力机制(self-attention)和前馈神经网络(feed-forward network)。自注意力机制可以让模型捕捉输入序列中不同位置之间的关系,前馈神经网络可以让模型学习非线性的特征表示²⁴。</li> <li>ChatGPT的输入序列会先经过一个词嵌入层(word embedding layer),将每个词转换成一个高维向量。然后,这些向量会加上位置编码(position encoding),以保留输入序列中词的顺序信息。接着,这些向量会被送入多层的decoder中,逐层进行自注意力和前馈神经网络的计算。最后,输出序列会经过一个线性层(linear layer)和一个softmax层(softmax layer),将每个位置上的向量转换成一个词汇表中的词²⁴。</li> </ul> <p>Source: Conversation with Bing, 2023/5/31<br> (1) Introducing ChatGPT - OpenAI. https://openai.com/blog/chatgpt.<br> (2) 一文读懂ChatGPT模型原理 - 知乎. https://zhuanlan.zhihu.com/p/589621442.<br> (4) Make flowchart with GPT | Flow charts with ChatGPT - YouTube. https://www.youtube.com/watch?v=TklABBggj1w.<br> (5) ChatGPT Architecture Explained… How chatGPT works. | by … https://medium.com/@sreedevr/chatgpt-architecture-explained-7fc0cbb7426c.</p> <h3> <a id="ChatGPTdecoderencoder_185"></a>为什么ChatGPT只用了decoder而不用encoder?</h3> <p>ChatGPT只用了decoder而不用encoder的原因是这样的:</p> <ul> <li>ChatGPT是一个基于GPT-3.5和GPT-4的大型语言模型,而GPT系列的模型都是只用了decoder的¹²。</li> <li>ChatGPT的目标是生成文本,而不是编码文本。decoder可以根据输入序列生成输出序列,而encoder只能将输入序列转换成隐藏状态,不能直接生成输出序列²³。</li> <li>ChatGPT使用了自注意力机制(self-attention),可以让模型捕捉输入序列中不同位置之间的关系,而不需要encoder来提供上下文信息²³ 。</li> <li>ChatGPT使用了对话格式,可以让模型根据对话历史和用户反馈来生成回复,而不需要encoder来提供额外的信息¹²。</li> </ul> <p>Source: Conversation with Bing, 2023/5/31<br> (1) ChatGPT’s Architecture - Decoder Only? Or Encoder-Decoder?. https://datascience.stackexchange.com/questions/118260/chatgpts-architecture-decoder-only-or-encoder-decoder.<br> (2) OpenAI ChatGPT(一):十分钟读懂 Transformer - 知乎. https://zhuanlan.zhihu.com/p/600773858.<br> (3) 什么是 Encoder-Decoder ? | ChatGPT中文导航网. https://chatgpt-nav.netlify.app/handbook/what_is_en_decode.html.</p> <h3> <a id="chatGPT__198"></a>chatGPT 的三个训练阶段,以及每个训练阶段的主要内容</h3> <p>ChatGPT的训练阶段大致有以下几个¹:</p> <ul> <li> <strong>监督学习阶段</strong>:在这个阶段,使用人工编写的对话数据对GPT-3.5模型进行微调,让模型学习如何根据输入生成合适的回复。这些对话数据包括了InstructGPT的数据集和专门为ChatGPT设计的数据集,其中包含了文本和代码等多种类型的输入和输出²。</li> <li> <strong>奖赏模型阶段</strong>:在这个阶段,使用人工评价的数据对一个奖赏模型进行训练,让奖赏模型能够给出不同回复的质量评分。这些评价数据是通过从对话数据中随机选择一个模型生成的回复,然后采样多个备选回复,并让人工对它们进行排序得到的²。</li> <li> <strong>强化学习阶段</strong>:在这个阶段,使用奖赏模型作为反馈信号,对GPT-3.5模型进行强化学习,让模型能够优化自己的回复策略,生成更高质量的回复。这个阶段使用了近端策略优化(PPO)算法,并进行了多次迭代²。</li> </ul> <p>Source: Conversation with Bing, 2023/5/31<br> (1) Introducing ChatGPT - OpenAI. https://openai.com/blog/chatgpt.<br> (2) ChatGPT是如何训练得到的?通俗讲解_小梁说代码的博客-CSDN博客. https://blog.csdn.net/qq_45722494/article/details/129226098.<br> (3) GPT fine-tune实战: 训练我自己的 ChatGPT🚀🚀🚀 - 知乎. https://zhuanlan.zhihu.com/p/616504594.<br> (4) 自学如何训练/调教一个私人ChatGPT - 知乎. https://zhuanlan.zhihu.com/p/610791259.</p> <h3> <a id="_211"></a>奖赏模型</h3> <h4> <a id="_213"></a>目的</h4> <p>奖赏模型阶段的目的是训练一个能够评价不同回复质量的模型,这个模型可以给出一个数值分数,表示回复的适当性、完整性、流畅性等方面。</p> <h4> <a id="_216"></a>训练过程</h4> <ul><li> <strong>训练过程的示意图</strong><br> <img referrerpolicy="no-referrer" src="https://img-blog.csdnimg.cn/49c1d34922984edeb6296f75104e4e51.webp" alt="训练过程的示意图"> </li></ul> <p>为了训练这个模型,我们需要收集一些比较数据,即给定一个输入,有多个不同的回复,让人工对它们进行排序,从最好到最差。例如,如果输入是“你喜欢什么运动?”,那么可能有以下几个回复:</p> <ul> <li>我喜欢打篮球,因为它可以锻炼身体,也可以交朋友。</li> <li>我喜欢游泳,因为它很凉爽,也很有趣。</li> <li>我不喜欢运动,因为它很累,也很无聊。</li> <li>我喜欢吃饭,因为它很好吃,也很满足。</li> </ul> <p>那么人工可能会给出这样的排序:</p> <ul><li>我喜欢打篮球,因为它可以锻炼身体,也可以交朋友。> 我喜欢游泳,因为它很凉爽,也很有趣。> 我不喜欢运动,因为它很累,也很无聊。> 我喜欢吃饭,因为它很好吃,也很满足。</li></ul> <p>这样就得到了一组比较数据,我们可以用这些数据来训练奖赏模型,让它能够学习到人工的偏好和标准。这个过程需要大量的数据和人工参与,所以是比较耗时和昂贵的。</p> <h3> <a id="RLHF__235"></a>RLHF(基于人类反馈的强化学习) 模型</h3> <h4> <a id="_237"></a>强化学习</h4> <p>强化学习是机器学习中的一个领域,强调如何基于环境而行动,以取得最大化的预期利益¹。强化学习是除了监督学习和无监督学习之外的第三种基本的机器学习方法¹。与监督学习不同的是,强化学习不需要带标签的输入输出对,同时也无需对非最优解的精确地纠正。其关注点在于寻找探索(对未知领域的)和利用(对已有知识的)的平衡²。</p> <p>强化学习的典型框架如下图所示¹:</p> <p><img referrerpolicy="no-referrer" src="https://img-blog.csdnimg.cn/1a751fd5a10a4f1fb000ae97cdc84b20.png" alt="强化学习框架"></p> <p>在这个框架中,有以下几个组成元素:</p> <ul> <li> <strong>智能体(Agent)</strong>:强化学习的本体,作为学习者或者决策者。</li> <li> <strong>环境(Environment)</strong>:强化学习智能体以外的一切,主要由状态集合组成。</li> <li> <strong>状态(State)</strong>:一个表示环境的数据,状态集则是环境中所有可能的状态。</li> <li> <strong>动作(Action)</strong>:智能体可以做出的动作,动作集则是智能体可以做出的所有动作。</li> <li> <strong>奖励(Reward)</strong>:智能体在执行一个动作后,获得的正/负反馈信号,奖励集则是智能体可以获得的所有反馈信息。</li> <li> <strong>策略(Policy)</strong>:强化学习是从环境状态到动作的映射学习,称该映射关系为策略。通俗的理解,即智能体如何选择动作的思考过程称为策略。</li> <li> <strong>目标(Goal)</strong>:智能体自动寻找在连续时间序列里的最优策略,而最优策略通常指最大化长期累积奖励。</li> </ul> <p>强化学习的过程可以描述为:在每一个时间步 <span class="katex--inline"><span class="katex"><span class="katex-mathml"> t t </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.6151em;"></span><span class="mord mathnormal">t</span></span></span></span></span>,智能体接收到一个观测 <span class="katex--inline"><span class="katex"><span class="katex-mathml"> o t o_t </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.5806em; vertical-align: -0.15em;"></span><span class="mord"><span class="mord mathnormal">o</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.2806em;"><span class="" style="top: -2.55em; margin-left: 0em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span></span></span></span></span>,通常其中包含奖励 <span class="katex--inline"><span class="katex"><span class="katex-mathml"> r t r_t </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.5806em; vertical-align: -0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0278em;">r</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.2806em;"><span class="" style="top: -2.55em; margin-left: -0.0278em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span></span></span></span></span>。然后,它从允许的集合中选择一个动作 <span class="katex--inline"><span class="katex"><span class="katex-mathml"> a t a_t </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.5806em; vertical-align: -0.15em;"></span><span class="mord"><span class="mord mathnormal">a</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.2806em;"><span class="" style="top: -2.55em; margin-left: 0em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span></span></span></span></span>,然后送出到环境中去。环境则变化到一个新的状态 <span class="katex--inline"><span class="katex"><span class="katex-mathml"> s t + 1 s_{t+1} </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.6389em; vertical-align: -0.2083em;"></span><span class="mord"><span class="mord mathnormal">s</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.3011em;"><span class="" style="top: -2.55em; margin-left: 0em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">t</span><span class="mbin mtight">+</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.2083em;"><span class=""></span></span></span></span></span></span></span></span></span></span>,然后决定了和这个变化相关联的奖励 <span class="katex--inline"><span class="katex"><span class="katex-mathml"> r t + 1 r_{t+1} </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.6389em; vertical-align: -0.2083em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0278em;">r</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.3011em;"><span class="" style="top: -2.55em; margin-left: -0.0278em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">t</span><span class="mbin mtight">+</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.2083em;"><span class=""></span></span></span></span></span></span></span></span></span></span>。强化学习智能体的目标,是得到尽可能多的奖励。</p> <p>Source: Conversation with Bing, 2023/5/31<br> (1) 强化学习 (Reinforcement Learning) - 知乎. https://www.zhihu.com/topic/20039099/intro.<br> (2) 强化学习 - 维基百科,自由的百科全书. https://zh.wikipedia.org/wiki/%E5%BC%BA%E5%8C%96%E5%AD%A6%E4%B9%A0.</p> <h4> <a id="_260"></a>目的</h4> <p>强化学习阶段的目的是训练一个能够优化自己的回复策略的模型,这个模型可以根据奖赏模型的反馈信号,调整自己的参数,生成更高质量的回复。</p> <h4> <a id="_263"></a>训练过程</h4> <ul><li> <strong>训练过程的示意图</strong><br> <img referrerpolicy="no-referrer" src="https://img-blog.csdnimg.cn/ec7368ed0a914e51b0e43d1a2ad7a1b8.webp" alt="训练过程的示意图"> </li></ul> <p>为了训练这个模型,我们需要使用一种强化学习算法,例如近端策略优化(PPO),这种算法可以在不需要明确的目标函数的情况下,通过与环境的交互,逐步改进自己的策略。例如,如果输入是“你喜欢什么运动?”,那么模型可能会生成以下几个回复:</p> <ul> <li>我喜欢打篮球,因为它可以锻炼身体,也可以交朋友。</li> <li>我喜欢游泳,因为它很凉爽,也很有趣。</li> <li>我不喜欢运动,因为它很累,也很无聊。</li> <li>我喜欢吃饭,因为它很好吃,也很满足。</li> </ul> <p>那么奖赏模型可能会给出这样的分数:</p> <ul> <li>我喜欢打篮球,因为它可以锻炼身体,也可以交朋友。0.8</li> <li>我喜欢游泳,因为它很凉爽,也很有趣。0.7</li> <li>我不喜欢运动,因为它很累,也很无聊。0.5</li> <li>我喜欢吃饭,因为它很好吃,也很满足。0.3</li> </ul> <p>这样就得到了一个反馈信号,我们可以用这个信号来更新模型的参数,让模型更倾向于生成分数高的回复。这个过程需要多次迭代,并且需要平衡探索和利用的权衡。</p> <h3> <a id="_284"></a>激活函数</h3> <p>激活函数是GeLU,即高斯误差线性单元。它是一个平滑的非线性函数,它可以近似模拟ReLU的性质,但是又避免了ReLU的一些缺点,比如梯度消失和死亡神经元。³<br> GeLU也可以更好地适应Transformer的结构,因为它可以保持输入和输出的均值和方差不变。使用GeLU作为中间层和输出层的激活函数,以提高模型的表达能力和学习效率。<br> ¹²</p> <ul><li>它的数学表达式是:</li></ul> <p><span class="katex--display"><span class="katex-display"><span class="katex"><span class="katex-mathml"> GeLU ( x ) = x Φ ( x ) = 1 2 x [ 1 + erf ( x 2 ) ] \text{GeLU}(x) = x \Phi(x) = \frac{1}{2} x \left[1 + \text{erf}\left(\frac{x}{\sqrt{2}}\right)\right] </span><span class="katex-html"><span class="base"><span class="strut" style="height: 1em; vertical-align: -0.25em;"></span><span class="mord text"><span class="mord">GeLU</span></span><span class="mopen">(</span><span class="mord mathnormal">x</span><span class="mclose">)</span><span class="mspace" style="margin-right: 0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right: 0.2778em;"></span></span><span class="base"><span class="strut" style="height: 1em; vertical-align: -0.25em;"></span><span class="mord mathnormal">x</span><span class="mord">Φ</span><span class="mopen">(</span><span class="mord mathnormal">x</span><span class="mclose">)</span><span class="mspace" style="margin-right: 0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right: 0.2778em;"></span></span><span class="base"><span class="strut" style="height: 2.4em; vertical-align: -0.95em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 1.3214em;"><span class="" style="top: -2.314em;"><span class="pstrut" style="height: 3em;"></span><span class="mord"><span class="mord">2</span></span></span><span class="" style="top: -3.23em;"><span class="pstrut" style="height: 3em;"></span><span class="frac-line" style="border-bottom-width: 0.04em;"></span></span><span class="" style="top: -3.677em;"><span class="pstrut" style="height: 3em;"></span><span class="mord"><span class="mord">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.686em;"><span class=""></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mord mathnormal">x</span><span class="mspace" style="margin-right: 0.1667em;"></span><span class="minner"><span class="mopen delimcenter" style="top: 0em;"><span class="delimsizing size3">[</span></span><span class="mord">1</span><span class="mspace" style="margin-right: 0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right: 0.2222em;"></span><span class="mord text"><span class="mord">erf</span></span><span class="mspace" style="margin-right: 0.1667em;"></span><span class="minner"><span class="mopen delimcenter" style="top: 0em;"><span class="delimsizing size3">(</span></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 1.1076em;"><span class="" style="top: -2.2028em;"><span class="pstrut" style="height: 3em;"></span><span class="mord"><span class="mord sqrt"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.9072em;"><span class="svg-align" style="top: -3em;"><span class="pstrut" style="height: 3em;"></span><span class="mord" style="padding-left: 0.833em;"><span class="mord">2</span></span></span><span class="" style="top: -2.8672em;"><span class="pstrut" style="height: 3em;"></span><span class="hide-tail" style="min-width: 0.853em; height: 1.08em;"> <svg width="400em" height="1.08em" viewbox="0 0 400000 1080" preserveaspectratio="xMinYMin slice"> <path d="M95,702 c-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14 c0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54 c44.2,-33.3,65.8,-50.3,66.5,-51c1.3,-1.3,3,-2,5,-2c4.7,0,8.7,3.3,12,10 s173,378,173,378c0.7,0,35.3,-71,104,-213c68.7,-142,137.5,-285,206.5,-429 c69,-144,104.5,-217.7,106.5,-221 l0 -0 c5.3,-9.3,12,-14,20,-14 H400000v40H845.2724 s-225.272,467,-225.272,467s-235,486,-235,486c-2.7,4.7,-9,7,-19,7 c-6,0,-10,-1,-12,-3s-194,-422,-194,-422s-65,47,-65,47z M834 80h400000v40h-400000z"></path> </svg></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.1328em;"><span class=""></span></span></span></span></span></span></span><span class="" style="top: -3.23em;"><span class="pstrut" style="height: 3em;"></span><span class="frac-line" style="border-bottom-width: 0.04em;"></span></span><span class="" style="top: -3.677em;"><span class="pstrut" style="height: 3em;"></span><span class="mord"><span class="mord mathnormal">x</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.93em;"><span class=""></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mclose delimcenter" style="top: 0em;"><span class="delimsizing size3">)</span></span></span><span class="mclose delimcenter" style="top: 0em;"><span class="delimsizing size3">]</span></span></span></span></span></span></span></span></p> <p>其中<span class="katex--inline"><span class="katex"><span class="katex-mathml"> Φ ( x ) \Phi(x) </span><span class="katex-html"><span class="base"><span class="strut" style="height: 1em; vertical-align: -0.25em;"></span><span class="mord">Φ</span><span class="mopen">(</span><span class="mord mathnormal">x</span><span class="mclose">)</span></span></span></span></span>是标准正态分布的累积分布函数,<span class="katex--inline"><span class="katex"><span class="katex-mathml"> erf ( x ) \text{erf}(x) </span><span class="katex-html"><span class="base"><span class="strut" style="height: 1em; vertical-align: -0.25em;"></span><span class="mord text"><span class="mord">erf</span></span><span class="mopen">(</span><span class="mord mathnormal">x</span><span class="mclose">)</span></span></span></span></span>是误差函数。其中,<code>erf</code>是误差函数,其图像如下:</p> <p><img referrerpolicy="no-referrer" src="https://img-blog.csdnimg.cn/img_convert/a3398ba998a9eec271adab2b3a7ecb68.png" alt="erf"></p> <p>GeLU 的曲线图如下:</p> <p><img referrerpolicy="no-referrer" src="https://img-blog.csdnimg.cn/img_convert/acd91488f58365b3050482fd5bdd191b.png" alt="GeLU"></p> <p>Source: Conversation with Bing, 2023/5/12<br> (1) GPT models explained. Open AI’s GPT-1,GPT-2,GPT-3 … https://medium.com/walmartglobaltech/the-journey-of-open-ai-gpt-models-32d95b7b7fb2.<br> (2) Activation function and GLU variants for Transformer models. https://medium.com/@tariqanwarph/activation-function-and-glu-variants-for-transformer-models-a4fcbe85323f.<br> (3) OpenAI peeks into the “black box” of neural networks with … https://arstechnica.com/information-technology/2023/05/openai-peeks-into-the-black-box-of-neural-networks-with-new-research/.</p> <p>GeLU的导数图像如下:</p> <p><img referrerpolicy="no-referrer" src="https://img-blog.csdnimg.cn/20210603111944334.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZlbGFpbQ==,size_16,color_FFFFFF,t_70" alt="GeLU derivative"></p> <p>可以看到,当x越大时,导数越接近1,当x越小时,导数越接近0,而在零点附近是一个平滑的曲线,没有ReLU的尖锐变化。</p> <p>GeLU的缺点有以下几点:</p> <ul> <li>GeLU的计算复杂度较高,因为它涉及到误差函数和累积分布函数的计算,这些函数没有简单的解析形式,需要近似或者数值方法。¹</li> <li>GeLU的导数也没有简单的解析形式,需要额外的计算,这会增加反向传播的开销。¹</li> <li>GeLU的输出不是零均值的,这可能会影响模型的收敛速度和稳定性。²</li> </ul> <p>Source: Conversation with Bing, 2023/5/12<br> (1) relu, GeLU , swish, mish activation function comparison. https://chadrick-kwag.net/relu-GeLU-swish-mish-activation-function-comparison/.<br> (2) [1606.08415] Gaussian Error Linear Units (GeLUs) - arXiv.org. https://arxiv.org/abs/1606.08415.<br> (3) GeLU activation explained | Towards AI. https://pub.towardsai.net/is-GeLU-the-relu-successor-deep-learning-activations-7506cf96724f.<br> (4) GeLU Explained | Papers With Code. https://paperswithcode.com/method/GeLU.</p> <h3> <a id="_326"></a>损失函数</h3> <p>ChatGPT的损失函数可能是<strong>交叉熵损失函数</strong>,它是用来衡量模型生成的文本和人类反馈的文本之间的差异。交叉熵损失函数的公式如下:</p> <p><span class="katex--display"><span class="katex-display"><span class="katex"><span class="katex-mathml"> L ( θ ) = − 1 N ∑ i = 1 N ∑ j = 1 ∣ y i ∣ log P ( y i j ∣ x i ; θ ) L(\theta) = -\frac{1}{N}\sum_{i=1}^N \sum_{j=1}^{|y_i|} \log P(y_{ij}|x_i;\theta) </span><span class="katex-html"><span class="base"><span class="strut" style="height: 1em; vertical-align: -0.25em;"></span><span class="mord mathnormal">L</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right: 0.0278em;">θ</span><span class="mclose">)</span><span class="mspace" style="margin-right: 0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right: 0.2778em;"></span></span><span class="base"><span class="strut" style="height: 3.3748em; vertical-align: -1.4138em;"></span><span class="mord">−</span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 1.3214em;"><span class="" style="top: -2.314em;"><span class="pstrut" style="height: 3em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.109em;">N</span></span></span><span class="" style="top: -3.23em;"><span class="pstrut" style="height: 3em;"></span><span class="frac-line" style="border-bottom-width: 0.04em;"></span></span><span class="" style="top: -3.677em;"><span class="pstrut" style="height: 3em;"></span><span class="mord"><span class="mord">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.686em;"><span class=""></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mspace" style="margin-right: 0.1667em;"></span><span class="mop op-limits"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 1.8283em;"><span class="" style="top: -1.8723em; margin-left: 0em;"><span class="pstrut" style="height: 3.05em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">i</span><span class="mrel mtight">=</span><span class="mord mtight">1</span></span></span></span><span class="" style="top: -3.05em;"><span class="pstrut" style="height: 3.05em;"></span><span class=""><span class="mop op-symbol large-op">∑</span></span></span><span class="" style="top: -4.3em; margin-left: 0em;"><span class="pstrut" style="height: 3.05em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right: 0.109em;">N</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 1.2777em;"><span class=""></span></span></span></span></span><span class="mspace" style="margin-right: 0.1667em;"></span><span class="mop op-limits"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 1.961em;"><span class="" style="top: -1.8723em; margin-left: 0em;"><span class="pstrut" style="height: 3.05em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right: 0.0572em;">j</span><span class="mrel mtight">=</span><span class="mord mtight">1</span></span></span></span><span class="" style="top: -3.05em;"><span class="pstrut" style="height: 3.05em;"></span><span class=""><span class="mop op-symbol large-op">∑</span></span></span><span class="" style="top: -4.386em; margin-left: 0em;"><span class="pstrut" style="height: 3.05em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">∣</span><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right: 0.0359em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.3281em;"><span class="" style="top: -2.357em; margin-left: -0.0359em; margin-right: 0.0714em;"><span class="pstrut" style="height: 2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.143em;"><span class=""></span></span></span></span></span></span><span class="mord mtight">∣</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 1.4138em;"><span class=""></span></span></span></span></span><span class="mspace" style="margin-right: 0.1667em;"></span><span class="mop">lo<span style="margin-right: 0.0139em;">g</span></span><span class="mspace" style="margin-right: 0.1667em;"></span><span class="mord mathnormal" style="margin-right: 0.1389em;">P</span><span class="mopen">(</span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0359em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.3117em;"><span class="" style="top: -2.55em; margin-left: -0.0359em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right: 0.0572em;">ij</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.2861em;"><span class=""></span></span></span></span></span></span><span class="mord">∣</span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.3117em;"><span class="" style="top: -2.55em; margin-left: 0em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span><span class="mpunct">;</span><span class="mspace" style="margin-right: 0.1667em;"></span><span class="mord mathnormal" style="margin-right: 0.0278em;">θ</span><span class="mclose">)</span></span></span></span></span></span></p> <p>其中,<span class="katex--inline"><span class="katex"><span class="katex-mathml"> θ \theta </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.6944em;"></span><span class="mord mathnormal" style="margin-right: 0.0278em;">θ</span></span></span></span></span>是模型的参数,<span class="katex--inline"><span class="katex"><span class="katex-mathml"> N N </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.6833em;"></span><span class="mord mathnormal" style="margin-right: 0.109em;">N</span></span></span></span></span>是训练数据的数量,<span class="katex--inline"><span class="katex"><span class="katex-mathml"> x i x_i </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.5806em; vertical-align: -0.15em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.3117em;"><span class="" style="top: -2.55em; margin-left: 0em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span></span></span></span></span>是第<span class="katex--inline"><span class="katex"><span class="katex-mathml"> i i </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.6595em;"></span><span class="mord mathnormal">i</span></span></span></span></span>个输入文本,<span class="katex--inline"><span class="katex"><span class="katex-mathml"> y i y_i </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.625em; vertical-align: -0.1944em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0359em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.3117em;"><span class="" style="top: -2.55em; margin-left: -0.0359em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span></span></span></span></span>是第<span class="katex--inline"><span class="katex"><span class="katex-mathml"> i i </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.6595em;"></span><span class="mord mathnormal">i</span></span></span></span></span>个人类反馈的文本,<span class="katex--inline"><span class="katex"><span class="katex-mathml"> y i j y_{ij} </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.7167em; vertical-align: -0.2861em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0359em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.3117em;"><span class="" style="top: -2.55em; margin-left: -0.0359em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right: 0.0572em;">ij</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.2861em;"><span class=""></span></span></span></span></span></span></span></span></span></span>是第<span class="katex--inline"><span class="katex"><span class="katex-mathml"> i i </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.6595em;"></span><span class="mord mathnormal">i</span></span></span></span></span>个文本的第<span class="katex--inline"><span class="katex"><span class="katex-mathml"> j j </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.854em; vertical-align: -0.1944em;"></span><span class="mord mathnormal" style="margin-right: 0.0572em;">j</span></span></span></span></span>个词,<span class="katex--inline"><span class="katex"><span class="katex-mathml"> P ( y i j ∣ x i ; θ ) P(y_{ij}|x_i;\theta) </span><span class="katex-html"><span class="base"><span class="strut" style="height: 1.0361em; vertical-align: -0.2861em;"></span><span class="mord mathnormal" style="margin-right: 0.1389em;">P</span><span class="mopen">(</span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0359em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.3117em;"><span class="" style="top: -2.55em; margin-left: -0.0359em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right: 0.0572em;">ij</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.2861em;"><span class=""></span></span></span></span></span></span><span class="mord">∣</span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.3117em;"><span class="" style="top: -2.55em; margin-left: 0em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span><span class="mpunct">;</span><span class="mspace" style="margin-right: 0.1667em;"></span><span class="mord mathnormal" style="margin-right: 0.0278em;">θ</span><span class="mclose">)</span></span></span></span></span>是模型根据输入文本生成第<span class="katex--inline"><span class="katex"><span class="katex-mathml"> j j </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.854em; vertical-align: -0.1944em;"></span><span class="mord mathnormal" style="margin-right: 0.0572em;">j</span></span></span></span></span>个词的概率。</p> <p>交叉熵损失函数可以反映模型生成的文本和人类反馈的文本之间的相似度,越小表示越相似,越大表示越不相似。模型的目标是通过优化参数<span class="katex--inline"><span class="katex"><span class="katex-mathml"> θ \theta </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.6944em;"></span><span class="mord mathnormal" style="margin-right: 0.0278em;">θ</span></span></span></span></span>来最小化损失函数,从而提高生成文本的质量。</p> <p>Source: Conversation with Bing, 2023/5/31<br> (1) Introducing ChatGPT - OpenAI. https://openai.com/blog/chatgpt.<br> (2) ChatGPT/InstructGPT详解 - 知乎. https://zhuanlan.zhihu.com/p/590311003.<br> (3) ChatGPT 技术原理探究解析 - 知乎. https://zhuanlan.zhihu.com/p/606758601.</p> <h4> <a id="_342"></a>优化器</h4> <p><strong>Adam</strong>,也就是一种自适应的梯度下降算法,可以根据参数的梯度大小动态调整学习率¹²,可以有效地避免梯度消失或爆炸的问题。</p> <ul><li>Adam 的公式是:</li></ul> <p><span class="katex--display"><span class="katex-display"><span class="katex"><span class="katex-mathml"> m t = β 1 m t − 1 + ( 1 − β 1 ) g t v t = β 2 v t − 1 + ( 1 − β 2 ) g t 2 m ^ t = m t 1 − β 1 t v ^ t = v t 1 − β 2 t θ t + 1 = θ t − α m ^ t v ^ t + ϵ m_t = \beta_1 m_{t-1} + (1 - \beta_1) g_t \\ v_t = \beta_2 v_{t-1} + (1 - \beta_2) g_t^2 \\ \hat{m}_t = \frac{m_t}{1 - \beta_1^t} \\ \hat{v}_t = \frac{v_t}{1 - \beta_2^t} \\ \theta_{t+1} = \theta_t - \alpha \frac{\hat{m}_t}{\sqrt{\hat{v}_t} + \epsilon} </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.5806em; vertical-align: -0.15em;"></span><span class="mord"><span class="mord mathnormal">m</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.2806em;"><span class="" style="top: -2.55em; margin-left: 0em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span><span class="mspace" style="margin-right: 0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right: 0.2778em;"></span></span><span class="base"><span class="strut" style="height: 0.9028em; vertical-align: -0.2083em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0528em;">β</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.3011em;"><span class="" style="top: -2.55em; margin-left: -0.0528em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal">m</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.3011em;"><span class="" style="top: -2.55em; margin-left: 0em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">t</span><span class="mbin mtight">−</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.2083em;"><span class=""></span></span></span></span></span></span><span class="mspace" style="margin-right: 0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right: 0.2222em;"></span></span><span class="base"><span class="strut" style="height: 1em; vertical-align: -0.25em;"></span><span class="mopen">(</span><span class="mord">1</span><span class="mspace" style="margin-right: 0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right: 0.2222em;"></span></span><span class="base"><span class="strut" style="height: 1em; vertical-align: -0.25em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0528em;">β</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.3011em;"><span class="" style="top: -2.55em; margin-left: -0.0528em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span><span class="mclose">)</span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0359em;">g</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.2806em;"><span class="" style="top: -2.55em; margin-left: -0.0359em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span></span><span class="mspace newline"></span><span class="base"><span class="strut" style="height: 0.5806em; vertical-align: -0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0359em;">v</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.2806em;"><span class="" style="top: -2.55em; margin-left: -0.0359em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span><span class="mspace" style="margin-right: 0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right: 0.2778em;"></span></span><span class="base"><span class="strut" style="height: 0.9028em; vertical-align: -0.2083em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0528em;">β</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.3011em;"><span class="" style="top: -2.55em; margin-left: -0.0528em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0359em;">v</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.3011em;"><span class="" style="top: -2.55em; margin-left: -0.0359em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">t</span><span class="mbin mtight">−</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.2083em;"><span class=""></span></span></span></span></span></span><span class="mspace" style="margin-right: 0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right: 0.2222em;"></span></span><span class="base"><span class="strut" style="height: 1em; vertical-align: -0.25em;"></span><span class="mopen">(</span><span class="mord">1</span><span class="mspace" style="margin-right: 0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right: 0.2222em;"></span></span><span class="base"><span class="strut" style="height: 1.1141em; vertical-align: -0.25em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0528em;">β</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.3011em;"><span class="" style="top: -2.55em; margin-left: -0.0528em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span><span class="mclose">)</span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0359em;">g</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.8641em;"><span class="" style="top: -2.453em; margin-left: -0.0359em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span><span class="" style="top: -3.113em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.247em;"><span class=""></span></span></span></span></span></span></span><span class="mspace newline"></span><span class="base"><span class="strut" style="height: 0.8444em; vertical-align: -0.15em;"></span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height: 0.6944em;"><span class="" style="top: -3em;"><span class="pstrut" style="height: 3em;"></span><span class="mord mathnormal">m</span></span><span class="" style="top: -3em;"><span class="pstrut" style="height: 3em;"></span><span class="accent-body" style="left: -0.25em;"><span class="mord">^</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.2806em;"><span class="" style="top: -2.55em; margin-left: 0em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span><span class="mspace" style="margin-right: 0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right: 0.2778em;"></span></span><span class="base"><span class="strut" style="height: 2.0599em; vertical-align: -0.9523em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 1.1076em;"><span class="" style="top: -2.314em;"><span class="pstrut" style="height: 3em;"></span><span class="mord"><span class="mord">1</span><span class="mspace" style="margin-right: 0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right: 0.2222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0528em;">β</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.7754em;"><span class="" style="top: -2.4337em; margin-left: -0.0528em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span><span class="" style="top: -3.0448em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.2663em;"><span class=""></span></span></span></span></span></span></span></span><span class="" style="top: -3.23em;"><span class="pstrut" style="height: 3em;"></span><span class="frac-line" style="border-bottom-width: 0.04em;"></span></span><span class="" style="top: -3.677em;"><span class="pstrut" style="height: 3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal">m</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.2806em;"><span class="" style="top: -2.55em; margin-left: 0em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.9523em;"><span class=""></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mspace newline"></span><span class="base"><span class="strut" style="height: 0.8444em; vertical-align: -0.15em;"></span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height: 0.6944em;"><span class="" style="top: -3em;"><span class="pstrut" style="height: 3em;"></span><span class="mord mathnormal" style="margin-right: 0.0359em;">v</span></span><span class="" style="top: -3em;"><span class="pstrut" style="height: 3em;"></span><span class="accent-body" style="left: -0.2222em;"><span class="mord">^</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.2806em;"><span class="" style="top: -2.55em; margin-left: -0.0359em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span><span class="mspace" style="margin-right: 0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right: 0.2778em;"></span></span><span class="base"><span class="strut" style="height: 2.0599em; vertical-align: -0.9523em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 1.1076em;"><span class="" style="top: -2.314em;"><span class="pstrut" style="height: 3em;"></span><span class="mord"><span class="mord">1</span><span class="mspace" style="margin-right: 0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right: 0.2222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0528em;">β</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.7754em;"><span class="" style="top: -2.4337em; margin-left: -0.0528em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span><span class="" style="top: -3.0448em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.2663em;"><span class=""></span></span></span></span></span></span></span></span><span class="" style="top: -3.23em;"><span class="pstrut" style="height: 3em;"></span><span class="frac-line" style="border-bottom-width: 0.04em;"></span></span><span class="" style="top: -3.677em;"><span class="pstrut" style="height: 3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0359em;">v</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.2806em;"><span class="" style="top: -2.55em; margin-left: -0.0359em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.9523em;"><span class=""></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mspace newline"></span><span class="base"><span class="strut" style="height: 0.9028em; vertical-align: -0.2083em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0278em;">θ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.3011em;"><span class="" style="top: -2.55em; margin-left: -0.0278em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">t</span><span class="mbin mtight">+</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.2083em;"><span class=""></span></span></span></span></span></span><span class="mspace" style="margin-right: 0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right: 0.2778em;"></span></span><span class="base"><span class="strut" style="height: 0.8444em; vertical-align: -0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0278em;">θ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.2806em;"><span class="" style="top: -2.55em; margin-left: -0.0278em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span><span class="mspace" style="margin-right: 0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right: 0.2222em;"></span></span><span class="base"><span class="strut" style="height: 2.3014em; vertical-align: -0.93em;"></span><span class="mord mathnormal" style="margin-right: 0.0037em;">α</span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 1.3714em;"><span class="" style="top: -2.2528em;"><span class="pstrut" style="height: 3em;"></span><span class="mord"><span class="mord sqrt"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.8572em;"><span class="svg-align" style="top: -3em;"><span class="pstrut" style="height: 3em;"></span><span class="mord" style="padding-left: 0.833em;"><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height: 0.6944em;"><span class="" style="top: -3em;"><span class="pstrut" style="height: 3em;"></span><span class="mord mathnormal" style="margin-right: 0.0359em;">v</span></span><span class="" style="top: -3em;"><span class="pstrut" style="height: 3em;"></span><span class="accent-body" style="left: -0.2222em;"><span class="mord">^</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.2806em;"><span class="" style="top: -2.55em; margin-left: -0.0359em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span></span></span><span class="" style="top: -2.8172em;"><span class="pstrut" style="height: 3em;"></span><span class="hide-tail" style="min-width: 0.853em; height: 1.08em;"> <svg width="400em" height="1.08em" viewbox="0 0 400000 1080" preserveaspectratio="xMinYMin slice"> <path d="M95,702 c-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14 c0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54 c44.2,-33.3,65.8,-50.3,66.5,-51c1.3,-1.3,3,-2,5,-2c4.7,0,8.7,3.3,12,10 s173,378,173,378c0.7,0,35.3,-71,104,-213c68.7,-142,137.5,-285,206.5,-429 c69,-144,104.5,-217.7,106.5,-221 l0 -0 c5.3,-9.3,12,-14,20,-14 H400000v40H845.2724 s-225.272,467,-225.272,467s-235,486,-235,486c-2.7,4.7,-9,7,-19,7 c-6,0,-10,-1,-12,-3s-194,-422,-194,-422s-65,47,-65,47z M834 80h400000v40h-400000z"></path> </svg></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.1828em;"><span class=""></span></span></span></span></span><span class="mspace" style="margin-right: 0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right: 0.2222em;"></span><span class="mord mathnormal">ϵ</span></span></span><span class="" style="top: -3.23em;"><span class="pstrut" style="height: 3em;"></span><span class="frac-line" style="border-bottom-width: 0.04em;"></span></span><span class="" style="top: -3.677em;"><span class="pstrut" style="height: 3em;"></span><span class="mord"><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height: 0.6944em;"><span class="" style="top: -3em;"><span class="pstrut" style="height: 3em;"></span><span class="mord mathnormal">m</span></span><span class="" style="top: -3em;"><span class="pstrut" style="height: 3em;"></span><span class="accent-body" style="left: -0.25em;"><span class="mord">^</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.2806em;"><span class="" style="top: -2.55em; margin-left: 0em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.93em;"><span class=""></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span></span></p> <p>其中 <span class="katex--inline"><span class="katex"><span class="katex-mathml"> m t m_t </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.5806em; vertical-align: -0.15em;"></span><span class="mord"><span class="mord mathnormal">m</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.2806em;"><span class="" style="top: -2.55em; margin-left: 0em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span></span></span></span></span> 和 <span class="katex--inline"><span class="katex"><span class="katex-mathml"> v t v_t </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.5806em; vertical-align: -0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0359em;">v</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.2806em;"><span class="" style="top: -2.55em; margin-left: -0.0359em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span></span></span></span></span> 是一阶和二阶矩的估计,<span class="katex--inline"><span class="katex"><span class="katex-mathml"> β 1 \beta_1 </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.8889em; vertical-align: -0.1944em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0528em;">β</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.3011em;"><span class="" style="top: -2.55em; margin-left: -0.0528em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span></span></span></span></span> 和 <span class="katex--inline"><span class="katex"><span class="katex-mathml"> β 2 \beta_2 </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.8889em; vertical-align: -0.1944em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0528em;">β</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.3011em;"><span class="" style="top: -2.55em; margin-left: -0.0528em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span></span></span></span></span> 是衰减率,<span class="katex--inline"><span class="katex"><span class="katex-mathml"> g t g_t </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.625em; vertical-align: -0.1944em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0359em;">g</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.2806em;"><span class="" style="top: -2.55em; margin-left: -0.0359em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span></span></span></span></span> 是梯度,<span class="katex--inline"><span class="katex"><span class="katex-mathml"> α \alpha </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.4306em;"></span><span class="mord mathnormal" style="margin-right: 0.0037em;">α</span></span></span></span></span> 是学习率,<span class="katex--inline"><span class="katex"><span class="katex-mathml"> ϵ \epsilon </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.4306em;"></span><span class="mord mathnormal">ϵ</span></span></span></span></span> 是平滑项,<span class="katex--inline"><span class="katex"><span class="katex-mathml"> θ t \theta_t </span><span class="katex-html"><span class="base"><span class="strut" style="height: 0.8444em; vertical-align: -0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right: 0.0278em;">θ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height: 0.2806em;"><span class="" style="top: -2.55em; margin-left: -0.0278em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">t</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height: 0.15em;"><span class=""></span></span></span></span></span></span></span></span></span></span> 是参数。</p> <p>Source: Conversation with Bing, 2023/5/16<br> (1) GPT-3: Language Models are Few-Shot Learners - GitHub. https://github.com/openai/gpt-3.<br> (2) GPT-3 - Wikipedia. https://en.wikipedia.org/wiki/GPT-3.<br> (3) GPT-3 powers the next generation of apps - OpenAI. https://openai.com/blog/gpt-3-apps/.</p> <h2> <a id="chatGPT__362"></a>chatGPT 实现</h2> <h3> <a id="_chatGPT__364"></a>如何训练 chatGPT 模型</h3> <p>训练 chatGPT 模型的方法有以下几个步骤:</p> <ul> <li>收集和预处理训练数据。需要尽可能多地收集文本数据,可以使用网络爬虫、公开数据集或者手动创建数据集的方法。预处理数据的目的是去除无关信息,分词,标准化,去重,打乱等,使数据更适合模型的输入。</li> <li>选择一个模型架构。因为 chatGPT 是基于 GPT 架构的,所以需要选择一个 GPT 的变种(如 GPT-2 或 GPT-3)或者使用 GPT-2 的代码库作为模型的基础。选择的架构要根据任务的需求和资源的限制来决定。</li> <li>设置训练环境。需要准备好训练所需的硬件(如 GPU)、安装所需的库和依赖等,以保证训练的效率和成功。</li> <li>训练模型。使用预处理过的数据和选择的架构来训练模型。可能需要进行多轮的训练,调整模型的参数等,以提高模型的性能和效果。</li> <li>评估和优化模型。使用一些指标(如困惑度、精确度、召回率等)来评估模型在测试集上的表现,找出模型的优点和缺点,进行必要的优化和改进。</li> <li>部署和使用模型。将训练好的模型部署到一个平台或者应用上,使其可以与用户或者其他系统进行交互。根据用户或者系统的反馈,持续监控和更新模型。</li> </ul> <p>Source: Conversation with Bing, 2023/5/29<br> (1) Learn how to work with the ChatGPT and GPT-4 models (preview). https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/chatgpt.<br> (2) Training your own ChatGPT model: A step-by-step tutorial. https://discusschatgpt.com/training-your-own-chatgpt-model-a-step-by-step-tutorial/.<br> (3) How to Train an AI Chatbot With Custom Knowledge Base … https://beebom.com/how-train-ai-chatbot-custom-knowledge-base-chatgpt-api/.<br> (4) A Guide to Using ChatGPT For Data Science Projects … https://www.datacamp.com/tutorial/chatgpt-data-science-projects.</p> </div> <link href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/markdown_views-98b95bb57c.css" rel="stylesheet"> <link href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/style-c216769e99.css" rel="stylesheet"> </div> <div id="treeSkill"></div> </article>
chatGPT 学习笔记
作者
sockstack
许可协议
CC BY 4.0
发布于
2023-12-27
修改于
2024-11-20
上一篇:软件:常用 Linux 软件汇总,值得收藏
下一篇:ChatGPT提示词工程进阶教学
尚未登录
登录 / 注册
文章分类
博客重构之路
5
Spring Boot简单入门
4
k8s 入门教程
0
MySQL 知识
1
NSQ 消息队列
0
ThinkPHP5 源码分析
5
使用 Docker 从零开始搭建私人代码仓库
3
日常开发汇总
3
标签列表
springboot
hyperf
swoole
webman
php
多线程
数据结构
docker
k8s
thinkphp
mysql
tailwindcss
flowbite
css
前端