【笔记】Prompting Large Language Models with Answer Heuristics forKnowledge-based VQA

背景

GPT-3没有被完全激活发挥出实力,主要限制有两点:

1.GPT-3应该摒弃一些无用信息,关注问题本身所关注的信息。“一群人在城市广场上行走”对回答“这些树结出什么果实”这个问题毫无帮助。在这种情况下,GPT-3不得不做出一个漫无目的和有偏见的猜测来回答这个问题。”

 2.GPT-3采用了少量的学习范式,需要一些上下文中的例子来适应新的任务。因此,这些示例的选择对于模型性能至关重要。

{few-shot:GPT-3只需要在推理时将任务的几个例子与作为提示的输入连接起来,并且不需要参数更新。}

本文思路

1.首先将一组示例传入VQA模型,得到一组案例。

 如:图片是一个老人面前一个生日蛋糕,问题是老人在吹什么?然后VQA生成的答案有蜡烛、生日、火。

问题、语义、候选答案都作为提示输入gpt-3,最终得出想要的答案。

依据上图,最终结果用公式表示为:

 由于GPT-3本质上不理解图像,因此需要使用现成的off-the-shelf captioning模型将图像转换为文字提示(PICa):

PICa的完整提示由一个固定的提示头、几个上下文中的示例和一个测试输入组成。此提示被输入GPT-3以进行答案预测。

阶段一:答案启发式生成

 首先解释一下VQA模型一般包含两个子模型,一个作用是embeding生成融合特征z,一个是分类头,用于生成答案词汇y。

首先第一个子模型,用于生成融合特征:

第二个子模型:生成候选词汇答案:

 作者将以上模型作为对比的方案,加入GPT-3的指引,验证有效性。

下面是作者初步操作:

制作e集合,其实就是few-shot中的support set。

生成的example首先肯定需要候选答案词汇,作者选择y中TopK得分的:

 

 这就是生成的提示示例(w为词汇,y为得分),但是还有一点,是选择哪些图片来当作示例呐?

作者说:

“我们推测这些融合特征位于一个潜在的答案空间中,该空间包含给定图像-问题对的答案的丰富语义。”

“如果z和zi在潜在空间中接近,他们更有可能共享相似的答案和图像问题输入。”

于是作者计算了test(测试案例,也就是few-shot中的query)同其他vq对的融合特征的余弦距离,选取TopN最接近的。

 

 当然,作者提到,这些z特征是可以被提前计算好的。

阶段二:启发式增强提示

向上面图二中展示的,下一个流程就是生成提示增强gpt-3预测。

也就是这一部分:

虽然可以看到给gpt-3提供了候选答案,但是gpt3同样可以选择生成新答案。

 

 最后不管是e集合还是test,输入gpt-3的格式是这样的:

其中confidence会帮助gpt-3关注更有利的候选答案, 作者会进行多次操作输入gpt-3,投票选出结果:

 

### Chain-of-Thought Prompting Mechanism in Large Language Models In large language models, chain-of-thought prompting serves as a method to enhance reasoning capabilities by guiding the model through structured thought processes. This approach involves breaking down complex problems into simpler components and providing step-by-step guidance that mirrors human cognitive processing. The creation of these prompts typically includes selecting examples from training datasets where each example represents part of an overall problem-solving process[^2]. By decomposing tasks into multiple steps, this technique encourages deeper understanding and more accurate predictions compared to traditional methods. For instance, when faced with multi-hop question answering or logical deduction challenges, using such chains allows models not only to generate correct answers but also articulate intermediate thoughts leading up to those conclusions. Such transparency facilitates better interpretability while improving performance on various NLP benchmarks. ```python def create_chain_of_thought_prompt(task_description, examples): """ Creates a chain-of-thought prompt based on given task description and examples. Args: task_description (str): Description of the task at hand. examples (list): List containing tuples of input-output pairs used for demonstration purposes. Returns: str: Formatted string representing the final prompt including both instructions and sample cases. """ formatted_examples = "\n".join([f"Input: {ex[0]}, Output: {ex[1]}" for ex in examples]) return f""" Task: {task_description} Examples: {formatted_examples} Now try solving similar questions following above pattern. """ # Example usage examples = [ ("What color do you get mixing red and blue?", "Purple"), ("If it rains tomorrow, will we have our picnic?", "No") ] print(create_chain_of_thought_prompt("Solve logic puzzles", examples)) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值