如何衡量大语模型的响应的可靠性
>大语言模型(LLM)的基本原理非常简单:根据培训数据中的统计模式,以一系列单词来预测下一个单词(或令牌)。但是,当它可以执行许多惊人的任务,例如文本摘要,想法产生,集思广益,代码生成,信息处理和内容创建等令人惊叹的任务时,这种看似简单的功能就非常复杂。也就是说,LLM没有任何记忆,除了坚持其基本功能外,他们实际上“理解”了任何东西:预测下一个单词。
下一字预测的过程是概率的。 LLM必须从概率分布中选择每个单词。在此过程中,它们通常会产生错误,捏造或不一致的内容,以尝试产生连贯的响应并填补外观合理但不正确的信息的空白。这种现象称为幻觉,这是LLM的不可避免的,众所周知的特征,需要验证和证实其产出。 使LLM与外部知识源一起工作的检索增强生成(RAG)方法在某种程度上可以最大程度地减少幻觉,但不能完全消除它们。尽管高级破布可以提供文本引用和URL,但验证这些参考可能会忙碌而耗时。因此,我们需要一个客观的标准来评估LLM响应的可靠性或可信度,无论是根据自己的知识还是外部知识基础(RAG)产生的。 在本文中,我们将讨论如何通过值得信赖的语言模型来评估LLM的输出,该模型为LLM的输出分配分数。我们将首先讨论如何使用值得信赖的语言模型将分数分配给LLM的答案并解释可信度。随后,我们将与Llamaparse和Llamaindex一起开发一个例子抹布,以评估抹布的可信度答案。
本文的整个代码可在github的jupyter笔记本中找到。>
>将可信度分数分配给LLM的答案
>演示我们如何为LLM的响应分配一个可信度分数,我将使用清洁行的可信语言模型(TLM)。这样的TLM结合了不确定性量化
>和>一致性分析来计算LLM响应的可信值分数和解释。
pip install --upgrade cleanlab-studio
>清洁列表支持几个专有模型,例如'gpt-4o','gpt-> gpt-4o-mini ',' o1-preview ',' claude-3-sonnet',''claude-3.5-sonnet ',, ‘claude-3.5-sonnet-v2'等。这是TLM将Trustworhiness分数分配给GPT-4O的答案的方式。值得信赖的评分范围从0到1,其中较高的值表示更高的可信度。
from cleanlab_studio import Studio
studio = Studio("<CLEANLAB_API_KEY>") # Get your API key from above
tlm = studio.TLM(options={"log": ["explanation"], "model": "gpt-4o"}) # GPT, Claude, etc
#set the prompt
out = tlm.prompt("How many vowels are there in the word 'Abracadabra'.?")
#the TLM response contains the actual output 'response', trustworthiness score and explanation
print(f"Model's response = {out['response']}")
print(f"Trustworthiness score = {out['trustworthiness_score']}")
print(f"Explanation = {out['log']['explanation']}")
上面的代码测试了GPT-4O对“
>可以看出,最先进的语言模型如何用于此类简单任务并产生错误的输出。在这里,对于的响应和可信度得分。 Model's response = The word "Abracadabra" contains 6 vowels. The vowels are: A, a, a, a, a, and a.
Trustworthiness score = 0.6842228802750124
Explanation = This response is untrustworthy due to a lack of consistency in possible responses from the model. Here's one inconsistent alternate response that the model considered (which may not be accurate either):
5.
> claude-3.5-sonnet-v2
产生正确的输出。让我们将两个模型的回答与另一个问题进行比较。Model's response = Let me count the vowels in 'Abracadabra':
A-b-r-a-c-a-d-a-b-r-a
The vowels are: A, a, a, a, a
There are 5 vowels in the word 'Abracadabra'.
Trustworthiness score = 0.9378276048845285
Explanation = Did not find a reason to doubt trustworthiness.
>
这是两个模型的响应:>
>我们还可以为开源LLMS生成可信赖的评分。让我们检查一下最近大肆宣传的开源LLM:DeepSeek-R1。我将基于Meta'sfrom cleanlab_studio import Studio
import markdown
from IPython.core.display import display, Markdown
# Initialize the Cleanlab Studio with API key
studio = Studio("<CLEANLAB_API_KEY>") # Replace with your actual API key
# List of models to evaluate
models = ["gpt-4o", "claude-3.5-sonnet-v2"]
# Define the prompt
prompt_text = "Which one of 9.11 and 9.9 is bigger?"
# Loop through each model and evaluate
for model in models:
tlm = studio.TLM(options={"log": ["explanation"], "model": model})
out = tlm.prompt(prompt_text)
md_content = f"""
## Model: {model}
**Response:** {out['response']}
**Trustworthiness Score:** {out['trustworthiness_score']}
**Explanation:** {out['log']['explanation']}
---
"""
display(Markdown(md_content))
llama-3.3–70b-Instruct Model > DeepSeek-r1-Distill-lalama-70b> ) 模型。知识蒸馏是一种机器学习技术,旨在将大型预培训模型的学习“教师模型”转移到较小的“学生模型”中。
这是> deepSeek-r1-distill-lalama-70b型号的输出
开发一个值得信赖的抹布import streamlit as st
from langchain_groq.chat_models import ChatGroq
import os
os.environ["GROQ_API_KEY"]=st.secrets["GROQ_API_KEY"]
# Initialize the Groq Llama Instant model
groq_llm = ChatGroq(model="deepseek-r1-distill-llama-70b", temperature=0.5)
prompt = "Which one of 9.11 and 9.9 is bigger?"
# Get the response from the model
response = groq_llm.invoke(prompt)
#Initialize Cleanlab's studio
studio = Studio("226eeab91e944b23bd817a46dbe3c8ae")
cleanlab_tlm = studio.TLM(options={"log": ["explanation"]}) #for explanations
#Get the output containing trustworthiness score and explanation
output = cleanlab_tlm.get_trustworthiness_score(prompt, response=response.content.strip())
md_content = f"""
## Model: {model}
**Response:** {response.content.strip()}
**Trustworthiness Score:** {output['trustworthiness_score']}
**Explanation:** {output['log']['explanation']}
---
"""
display(Markdown(md_content))
>我们现在将开发一个抹布,以演示如何衡量抹布中LLM响应的可信度。将通过从给定链接中刮擦数据,以降价格式解析并创建向量存储。
需要为下一个代码安装以下库。>
>要将html渲染为PDF格式,我们还需要从其网站上安装命令行工具。
将导入以下库:>
pip install --upgrade cleanlab-studio
>清洁列表支持几个专有模型,例如'gpt-4o','gpt-> gpt-4o-mini ',' o1-preview ',' claude-3-sonnet',''claude-3.5-sonnet ',, ‘claude-3.5-sonnet-v2'等。这是TLM将Trustworhiness分数分配给GPT-4O的答案的方式。值得信赖的评分范围从0到1,其中较高的值表示更高的可信度。
from cleanlab_studio import Studio studio = Studio("<CLEANLAB_API_KEY>") # Get your API key from above tlm = studio.TLM(options={"log": ["explanation"], "model": "gpt-4o"}) # GPT, Claude, etc #set the prompt out = tlm.prompt("How many vowels are there in the word 'Abracadabra'.?") #the TLM response contains the actual output 'response', trustworthiness score and explanation print(f"Model's response = {out['response']}") print(f"Trustworthiness score = {out['trustworthiness_score']}") print(f"Explanation = {out['log']['explanation']}")上面的代码测试了GPT-4O对“
Model's response = The word "Abracadabra" contains 6 vowels. The vowels are: A, a, a, a, a, and a. Trustworthiness score = 0.6842228802750124 Explanation = This response is untrustworthy due to a lack of consistency in possible responses from the model. Here's one inconsistent alternate response that the model considered (which may not be accurate either): 5.
> claude-3.5-sonnet-v2
产生正确的输出。让我们将两个模型的回答与另一个问题进行比较。Model's response = Let me count the vowels in 'Abracadabra': A-b-r-a-c-a-d-a-b-r-a The vowels are: A, a, a, a, a There are 5 vowels in the word 'Abracadabra'. Trustworthiness score = 0.9378276048845285 Explanation = Did not find a reason to doubt trustworthiness.>
这是两个模型的响应:
from cleanlab_studio import Studio import markdown from IPython.core.display import display, Markdown # Initialize the Cleanlab Studio with API key studio = Studio("<CLEANLAB_API_KEY>") # Replace with your actual API key # List of models to evaluate models = ["gpt-4o", "claude-3.5-sonnet-v2"] # Define the prompt prompt_text = "Which one of 9.11 and 9.9 is bigger?" # Loop through each model and evaluate for model in models: tlm = studio.TLM(options={"log": ["explanation"], "model": model}) out = tlm.prompt(prompt_text) md_content = f""" ## Model: {model} **Response:** {out['response']} **Trustworthiness Score:** {out['trustworthiness_score']} **Explanation:** {out['log']['explanation']} --- """ display(Markdown(md_content))llama-3.3–70b-Instruct Model

这是> deepSeek-r1-distill-lalama-70b型号的输出
开发一个值得信赖的抹布import streamlit as st from langchain_groq.chat_models import ChatGroq import os os.environ["GROQ_API_KEY"]=st.secrets["GROQ_API_KEY"] # Initialize the Groq Llama Instant model groq_llm = ChatGroq(model="deepseek-r1-distill-llama-70b", temperature=0.5) prompt = "Which one of 9.11 and 9.9 is bigger?" # Get the response from the model response = groq_llm.invoke(prompt) #Initialize Cleanlab's studio studio = Studio("226eeab91e944b23bd817a46dbe3c8ae") cleanlab_tlm = studio.TLM(options={"log": ["explanation"]}) #for explanations #Get the output containing trustworthiness score and explanation output = cleanlab_tlm.get_trustworthiness_score(prompt, response=response.content.strip()) md_content = f""" ## Model: {model} **Response:** {response.content.strip()} **Trustworthiness Score:** {output['trustworthiness_score']} **Explanation:** {output['log']['explanation']} --- """ display(Markdown(md_content))
>我们现在将开发一个抹布,以演示如何衡量抹布中LLM响应的可信度。将通过从给定链接中刮擦数据,以降价格式解析并创建向量存储。
需要为下一个代码安装以下库。

下一步将涉及使用python's
beautifuresoup库从给定URL刮除数据,使用
> pdfkitpip install llama-parse llama-index-core llama-index-embeddings-huggingface llama-index-llms-cleanlab requests beautifulsoup4 pdfkit nest-asyncio保存删除的数据,然后从pdf中解析数据( s)使用
> llamaparse降低文件,这是一个使用LLMS构建的Genai-native文档解析平台,用于LLM用例。
>我们将首先配置Cleanlabtlm和嵌入模型( huggingface 嵌入模型baai/bge-small-en-v1.5 )的LLM要计算刮擦数据的嵌入以创建向量存储。
pip install --upgrade cleanlab-studio>现在,我们将定义一个自定义事件处理程序,
from cleanlab_studio import Studio studio = Studio("<CLEANLAB_API_KEY>") # Get your API key from above tlm = studio.TLM(options={"log": ["explanation"], "model": "gpt-4o"}) # GPT, Claude, etc #set the prompt out = tlm.prompt("How many vowels are there in the word 'Abracadabra'.?") #the TLM response contains the actual output 'response', trustworthiness score and explanation print(f"Model's response = {out['response']}") print(f"Trustworthiness score = {out['trustworthiness_score']}") print(f"Explanation = {out['log']['explanation']}")Creative Commons Attribution-ShareAlike 4.0许可证
)。> >
note:建议读者始终仔细检查他们将要刮擦的内容/数据的状态,并确保允许他们这样做。
以下代码通过提出HTTP请求并使用> BeautifulSoup pdfkit。
从刮擦数据中生成pdf(s)后,我们使用> llamaparse
>现在,我们创建一个矢量商店和一个查询引擎。我们定义了一个客户提示模板,以指导LLM回答问题的行为。最后,我们使用创建索引创建一个查询引擎来回答查询。对于每个查询,我们根据查询的语义相似性从矢量存储中检索了前3个节点。 LLM使用这些检索的节点生成最终答案。
现在,让我们测试一些查询及其相应的可信度分数的抹布。
这就是所有人!如果您喜欢这篇文章,请在>中关注我,和> linkedIn 。Model's response = Let me count the vowels in 'Abracadabra':
A-b-r-a-c-a-d-a-b-r-a
The vowels are: A, a, a, a, a
There are 5 vowels in the word 'Abracadabra'.
Trustworthiness score = 0.9378276048845285
Explanation = Did not find a reason to doubt trustworthiness.
from cleanlab_studio import Studio
import markdown
from IPython.core.display import display, Markdown
# Initialize the Cleanlab Studio with API key
studio = Studio("<CLEANLAB_API_KEY>") # Replace with your actual API key
# List of models to evaluate
models = ["gpt-4o", "claude-3.5-sonnet-v2"]
# Define the prompt
prompt_text = "Which one of 9.11 and 9.9 is bigger?"
# Loop through each model and evaluate
for model in models:
tlm = studio.TLM(options={"log": ["explanation"], "model": model})
out = tlm.prompt(prompt_text)
md_content = f"""
## Model: {model}
**Response:** {out['response']}
**Trustworthiness Score:** {out['trustworthiness_score']}
**Explanation:** {out['log']['explanation']}
---
"""
display(Markdown(md_content))
>为LLM的响应分配一个可信度分数,无论是通过直接推理还是通过抹布生成,都有助于定义AI输出的可靠性,并在需要的情况下确定人类验证的优先级。对于错误或不可靠的响应可能会产生严重后果的关键领域,这一点尤其重要。
以上是如何衡量大语模型的响应的可靠性的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undress AI Tool
免费脱衣服图片

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Stock Market GPT
人工智能驱动投资研究,做出更明智的决策

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

该项目被称为“硅中的FOMC”,以数字方式重现联邦公开市场委员会(美国中央银行的决策部门)的会议,AI代理代表实际的董事会成员。研究小组为INDI提供了每个代理数据

阅读了不断扩展的提名人名单的介绍,其中包含包装构成法庭裁决的法律档案,归因于真正的作者的假牌书以及使用AI的Airbnb主持人制作图像,暗示客人造成了损害,他们造成了损害。

与此同时,传统存储协议正被更新的技术所取代,这些新技术更能满足可扩展、高性能驱动的AI工作负载需求。面向AI的存储解决方案正越来越多地选择对象存储,而非传统的块存储和文件存储。这一转变颇具讽刺意味,因为对象存储最初是作为一种可扩展、持久且低成本的平台而开发的,主要用于常规的备份、归档、媒体内容以及云规模的数据湖。然而,与在大规模并行处理需求下不堪重负的传统文件和块存储系统不同,对象存储提供了AI应用所需的横向扩展能力和性能表现。MinIO 成立于十多年前,是对象存储市场早期的领军企业。该公司将对

这种转变的心理影响是深远的。多年来,辅助技术一直繁琐,污名化和僵化,使用户成为一种尺寸合适的模具。但是AI正在重写这个故事,提供个性化的解决方案t

一辆没有任何乘客的Waymo车辆沿着坦佩(Tempe)的亚利桑那州立大学(Arizona State University)附近的农村路(Rural Road)行驶,当时它开始放慢脚步以右转到停车场,这很想准备拿起下一个骑手。 Waymo确认转弯信号

有趣的是,新的研究表明,当今AI聊天机器人最常见的用途之一是情感和心理健康支持。许多用户发现,他们可能会犹豫与朋友,家人,o讨论深刻的个人问题更容易开放

这是否可以实现还有待观察,但是Forbes对最新版本的FSD的评估发现它仍然容易出错。在洛杉矶,住宅区和高速公路的90分钟试驾期间,具有T的2024型Y

无论财务损失如何,科技巨头都将全力以赴。 Bain&Company最近的分析警告说,这种不懈的推动可能导致重大的长期挑战。该报告表明,AI的计算需求是
