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

Prompt工程学习之自我一致性

自我一致性 (Self-consistency)

  • 概念:该技术通过对同一问题采样不同的推理路径,并通过多数投票选择最一致的答案,来解决大语言模型(LLM)输出的可变性问题。通过使用不同的温度(temperature)或采样设置生成多条推理路径,然后聚合最终答案,自洽性能够提高复杂推理任务的准确性。从本质上讲,这是一种针对大语言模型输出的集成方法。
  • 原理:由于复杂问题存在多种合理推理路径,不同路径可通过不同思考过程抵达同一正确答案。自洽性通过聚合这些路径,抵消单一路径的偏差,从而提升准确性。
  • 目标:通过采样多样化推理路径并聚合结果,提升模型推理的准确性和可靠性。
  • 总结:用于替代链式思维提示(chain-of-thought prompting)中的贪心解码。该方法通过采样多样化推理路径并聚合最一致答案,提升复杂推理任务表现。

关键步骤

自洽性方法核心逻辑

  • 步骤 1:对同一问题,使用不同采样设置(如温度参数)生成多条不同的推理路径,而非仅采用贪心解码的单一路径。
  • 步骤 2:通过边缘化(marginalizing)采样的推理路径,选择最一致的答案(如通过多数投票等聚合方式)。

复杂推理问题通常存在多种合理的思考方式,最终指向唯一正确答案,多样化路径可提升答案的可靠性。

案例

这是一个测试方法,用于测试邮件分类的一致性(self-consistency)。主要通过对同一封邮件进行多次分类,采用多数投票的方式来确定最终分类结果。
设置温度参数 temperature(1.0) 以增加输出的随机性,采用多种不同的推理路径得到罪过,最终通过投票的方式聚合结果得到一致的答案

    @Testpublic void testSelfConsistency() throws Exception{String email = """Hi,I have seen you use Wordpress for your website. A great opensource content management system. I have used it in the pasttoo. It comes with lots of great user plugins. And it's prettyeasy to set up.I did notice a bug in the contact form, which happens whenyou select the name field. See the attached screenshot of meentering text in the name field. Notice the JavaScript alertbox that I inv0k3d.But for the rest it's a great website. I enjoy reading it. Feelfree to leave the bug in the website, because it gives me moreinteresting things to read.Cheers,Harry the Hacker.""";int importantCount = 0;int notImportantCount = 0;// Run the model 5 times with the same inputfor (int i = 0; i < 5; i++) {EmailClassification output = openAiChatClient.prompt().user(u -> u.text("""Email: {email}Classify the above email as IMPORTANT or NOT IMPORTANT. Let'sthink step by step and explain why.""").param("email", email)).options(ChatOptions.builder().temperature(1.0)  // Higher temperature for more variation.build()).call().entity(EmailClassification.class);System.out.println(output.reasoning);// Count resultsif (output.classification() == EmailClassification.Classification.IMPORTANT) {importantCount++;} else {notImportantCount++;}}// Determine the final classification by majority voteString finalClassification = importantCount > notImportantCount ?"IMPORTANT" : "NOT IMPORTANT";System.out.println(finalClassification);}record EmailClassification(Classification classification, String reasoning) {enum Classification {IMPORTANT, NOT_IMPORTANT}}

参考

1.spring-ai self consistency: https://docs.spring.io/spring-ai/reference/api/chat/prompt-engineering-patterns.html#_2_6_self_consistency
2.Self-Consistency Improves Chain of Thought Reasoning in Language Models,https://arxiv.org/abs/2203.11171

相关文章:

  • 双指针详解
  • 《第五人格》暑期活动前瞻爆料:39赛季精华、限定时装返场、新玩法攻略
  • JavaScript 数组学习总结
  • 获取wordpress某个栏目的内容数量
  • 服务网格技术深度解析:Istio vs Linkerd的选型对比
  • 当前市场环境下,软件行业的突围之道:技术演进与商业模式重构
  • 异或和之差-字典树
  • Web后端开发(请求、响应)
  • 开启二进制日志 MySQL显示关闭,关闭二进制日志 MySQL恢复正常
  • 国防科技大学计算机基础慕课课堂学习笔记
  • 查看进程线程的方法
  • Hibernate Validator 数据验证
  • 曼昆《经济学原理》第九版 第八章税收的成本
  • 持续交付的进化:从DevOps到AI驱动的IT新动能
  • Zustand 第二章(状态处理)
  • BOM(Browser Object Model)核心对象手册
  • Windows设置之网络路由
  • Vue2面试题(一)
  • Java核心技术-卷I-读书笔记(第十二版)
  • 从0开始学习R语言--Day20-ARIMA与格兰杰因果检验
  • 免费ppt模板在线下载/seo内容优化方法
  • 手机网站推广怎么做/seo需要会什么
  • 网站建设副业/优化网站的软件下载
  • php动态网站开发唐四薪/可以发外链的平台
  • 如何增加网站收录/千锋教育学费多少
  • wordpress+手机站/网络关键词排名软件