人工智能, 生活

本地模型在温度为零和相同提示词下结果不一致的问题

这里使用 Ollama 调用本地的大语言模型,参考这篇:使用Ollama在本地运行开源大语言模型。经过测试,发现在温度为零的情况下,如果连续使用相同的提示词,第一次对话和后续对话的结果会出现不一致。这可能是 Ollama 内部机制的问题,触发了缓存,不清楚是故意设计的还是小 Bug。目前的解决方法是:在两次相同提示词对话的中间加入一个其他的对话。以下是测试的例子和对应的结果。

测试例子1:

def ollama_chat(prompt):
    import ollama
    response = ollama.chat(model="qwen2.5:3b", messages=[{"role": "user", "content": prompt}], stream=True, options={"temperature": 0})
    for part in response:
        print(part['message']['content'], end='', flush=True)
    print('\n')

for _ in range(5):
    ollama_chat("一句话说下人工智能")

运行结果:

人工智能是模拟、扩展和拓展人类智能的理论、方法、技术及应 用系统的一门综合学科。

人工智能是模拟、扩展和延伸人类智能的理论、方法、技术及应 用系统的总称。

人工智能是模拟、扩展和延伸人类智能的理论、方法、技术及应 用系统的总称。

人工智能是模拟、扩展和延伸人类智能的理论、方法、技术及应 用系统的总称。

人工智能是模拟、扩展和延伸人类智能的理论、方法、技术及应 用系统的总称。

测试例子2:

def ollama_chat(prompt):
    import ollama
    response = ollama.chat(model="qwen2.5:3b", messages=[{"role": "user", "content": prompt}], stream=True, options={"temperature": 0})
    for part in response:
        print(part['message']['content'], end='', flush=True)
    print('\n')

for _ in range(5):
    ollama_chat("一句话说下人工智能")
    ollama_chat("你好")

运行结果:

人工智能是模拟、扩展和拓展人类智能的理论、方法、技术及应 用系统的一门综合学科。

你好!有什么我可以帮助你的吗?

人工智能是模拟、扩展和拓展人类智能的理论、方法、技术及应 用系统的一门综合学科。

你好!有什么我可以帮助你的吗?

人工智能是模拟、扩展和拓展人类智能的理论、方法、技术及应 用系统的一门综合学科。

你好!有什么我可以帮助你的吗?

人工智能是模拟、扩展和拓展人类智能的理论、方法、技术及应 用系统的一门综合学科。

你好!有什么我可以帮助你的吗?

人工智能是模拟、扩展和拓展人类智能的理论、方法、技术及应 用系统的一门综合学科。

你好!有什么我可以帮助你的吗?
12 次浏览

【说明:本站主要是个人的一些笔记和代码分享,内容可能会不定期修改。为了使全网显示的始终是最新版本,这里的文章未经同意请勿转载。引用请注明出处:https://www.guanjihuan.com

发表评论

您的邮箱地址不会被公开。 必填项已用 * 标注

Captcha Code