首页 科技周边 人工智能 如何衡量大语模型的响应的可靠性

如何衡量大语模型的响应的可靠性

Feb 25, 2025 pm 10:50 PM

>大语言模型(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's
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> ) 模型。知识蒸馏是一种机器学习技术,旨在将大型预培训模型的学习“教师模型”转移到较小的“学生模型”中。 如何衡量大语模型的响应的可靠性

这是> 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格式,我们还需要从其网站上安装命令行工具。 将导入以下库:>

下一步将涉及使用python's

beautifuresoup

库从给定URL刮除数据,使用

> pdfkit
pip 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
登录后复制
登录后复制
>现在,我们将定义一个自定义事件处理程序,,它来自基本事件处理程序类。该处理程序由LLM完成的结束触发,并从响应元数据中提取可信赖性分数。辅助功能,display_response,显示LLM的响应以及其可信赖性分数。 >现在,我们将通过从给定的URL中刮除数据来生成PDF。为了进行演示,我们将仅从这篇Wikipedia文章中报道有关大语言模型的文章(
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 python库来解析HTML内容,从而从给定的URL中删除了数据。通过将协议相关URL转换为绝对值的HTML含量可以清除。随后,使用

pdfkit 从刮擦数据中生成pdf(s)后,我们使用> llamaparse

来解析这些PDF。我们设置了解析指令,以以降价格式提取内容,并在文档名称和页码上分析文档。这些提取的实体(页面)称为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. 。解析器在提取的节点上迭代,并通过附加引用标头来更新每个节点的元数据,该引用标头促进后来引用。

>现在,我们创建一个矢量商店和一个查询引擎。我们定义了一个客户提示模板,以指导LLM回答问题的行为。最后,我们使用创建索引创建一个查询引擎来回答查询。对于每个查询,我们根据查询的语义相似性从矢量存储中检索了前3个节点。 LLM使用这些检索的节点生成最终答案。 现在,让我们测试一些查询及其相应的可信度分数的抹布。

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输出的可靠性,并在需要的情况下确定人类验证的优先级。对于错误或不可靠的响应可能会产生严重后果的关键领域,这一点尤其重要。

这就是所有人!如果您喜欢这篇文章,请在>中关注我,> linkedIn

以上是如何衡量大语模型的响应的可靠性的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

最佳AI艺术生成器(免费付款)创意项目 最佳AI艺术生成器(免费付款)创意项目 Apr 02, 2025 pm 06:10 PM

本文回顾了AI最高的艺术生成器,讨论了他们的功能,对创意项目的适用性和价值。它重点介绍了Midjourney是专业人士的最佳价值,并建议使用Dall-E 2进行高质量的可定制艺术。

开始使用Meta Llama 3.2 -Analytics Vidhya 开始使用Meta Llama 3.2 -Analytics Vidhya Apr 11, 2025 pm 12:04 PM

Meta的Llama 3.2:多模式和移动AI的飞跃 Meta最近公布了Llama 3.2,这是AI的重大进步,具有强大的视觉功能和针对移动设备优化的轻量级文本模型。 以成功为基础

最佳AI聊天机器人比较(Chatgpt,Gemini,Claude&amp;更多) 最佳AI聊天机器人比较(Chatgpt,Gemini,Claude&amp;更多) Apr 02, 2025 pm 06:09 PM

本文比较了诸如Chatgpt,Gemini和Claude之类的顶级AI聊天机器人,重点介绍了其独特功能,自定义选项以及自然语言处理和可靠性的性能。

Chatgpt 4 o可用吗? Chatgpt 4 o可用吗? Mar 28, 2025 pm 05:29 PM

Chatgpt 4当前可用并广泛使用,与诸如ChatGpt 3.5(例如ChatGpt 3.5)相比,在理解上下文和产生连贯的响应方面取得了重大改进。未来的发展可能包括更多个性化的间

顶级AI写作助理来增强您的内容创建 顶级AI写作助理来增强您的内容创建 Apr 02, 2025 pm 06:11 PM

文章讨论了Grammarly,Jasper,Copy.ai,Writesonic和Rytr等AI最高的写作助手,重点介绍了其独特的内容创建功能。它认为Jasper在SEO优化方面表现出色,而AI工具有助于保持音调的组成

构建AI代理的前7个代理抹布系统 构建AI代理的前7个代理抹布系统 Mar 31, 2025 pm 04:25 PM

2024年见证了从简单地使用LLM进行内容生成的转变,转变为了解其内部工作。 这种探索导致了AI代理的发现 - 自主系统处理任务和最少人工干预的决策。 Buildin

向员工出售AI策略:Shopify首席执行官的宣言 向员工出售AI策略:Shopify首席执行官的宣言 Apr 10, 2025 am 11:19 AM

Shopify首席执行官TobiLütke最近的备忘录大胆地宣布AI对每位员工的基本期望是公司内部的重大文化转变。 这不是短暂的趋势。这是整合到P中的新操作范式

选择最佳的AI语音生成器:评论的顶级选项 选择最佳的AI语音生成器:评论的顶级选项 Apr 02, 2025 pm 06:12 PM

本文评论了Google Cloud,Amazon Polly,Microsoft Azure,IBM Watson和Discript等高级AI语音生成器,重点介绍其功能,语音质量和满足不同需求的适用性。

See all articles