当前位置:   article > 正文

Is Temperature the Creativity Parameter of Large Language Models?阅读笔记

Is Temperature the Creativity Parameter of Large Language Models?阅读笔记

最近有小伙伴来问LLM的参数该如何设计,废话不多说来看看paper吧。首先,常见的可以进行调参的几个值有temperature,top-p和top-k。今天这篇文章是关于temperature的。

原文链接:https://arxiv.org/abs/2405.00492

temperature如果用简单的一句话来说,就是:Controls randomness, higher values increase diversity。数值越高,输出的结果多样性越大。大家其实直接用这个标准拿去参考调整参数就行。其实大部分的人都是这么做的,我们先来看一下openai commutiy上讨论的帖子:Cheat Sheet: Mastering Temperature and Top_p in ChatGPT API - API - OpenAI Developer Forum。这个回答者,还给出了一个不同use case情况下的参数设置参考,当然具体情况还是要看实验结果的哈。

然后2024年五月出的这篇文章,研究工作比较新了,我们先来看一下文章的摘要部分给出的结论:

Here, we investigate this claim using a narrative generation task with a predetermined fixed context, model and prompt. Specifically, we present an empirical analysis of the LLM output for different temperature values using four necessary conditions for creativity in narrative generation: novelty, typicality, cohesion, and coherence. We find that temperature is weakly correlated with novelty, and unsurprisingly, moderately correlated with incoherence, but there is no relationship with either cohesion or typicality. However, the influence of temperature on creativity is far more nuanced and weak than suggested by the “creativity parameter” claim; overall results suggest that the LLM generates slightly more novel outputs as temperatures get higher. Finally, we discuss ideas to allow more controlled LLM creativity, rather than relying on chance via changing the temperature parameter.

文章测试的实验是用固定的上下文、大语言基座模型、提示词来进行文本生成任务(叙事生成,即生成连贯有意义的故事)。作者从novelty新颖性、typicality典型性、cohesion凝聚性和coherence连贯性,这四个方面来看这个creativity的情况。结果,他们发现temperature这个参数和novelty弱相关,与不连贯性中等相关,与凝聚性和典型性无关。虽然temperature被视为creativity parameter,但是看起来并不是所谓意义上的那个creative。

首先,如果我们要去改变一个大语言模型的效果,有三个方式可以去调整,分别是训练数据(从最开始就构建或者后面进行微调),in-context learning(few-shot learning,简而言之,在prompt中添加示例),以及不同的超参数设置。Temperature是模型中的一个超参数,用于调节采样过程中的随机性,即下面这个softmax公式里的t,softmax大家都知道,是深度学习里非常常见的一个函数了,会在分类场景里,把数值给他映射到0-1的空间,如果是多分类,概率的和就是1啦。

然后,咱们放到GPT模型的尾端,当我要预测下一个词的时候,我需要计算每个单词成为下一个单词的概率,然后找到最大概率的那个词,作为我的下一个单词(所有词的概率加在一起是1)。咱们回到公式,你看分母就是词所有的和,分子是当前词。这个时候咱们的temperature,t成了一个分母,温度 t>1 时,高概率的值会降低,低概率的值会增加,导致概率分布更加平坦。温度 t<1 时,高概率的值会增加,低概率的值会降低,使得分布更加陡峭。分布陡峭,指的是我很明确就知道我要选那个概率最大的词,但是如果大家都姿色平平,那我可能就需要雨露均沾,哪个都可以试试。

如果你想看Temperature变化时候的可视化,可以看看这个网站(https://www.wpsshop.cn/w/煮酒与君饮/article/detail/824801

推荐阅读
相关标签
  

闽ICP备14008679号