OctSum
00:00 / 14:23

Hamel Husain · 14:23

You probably know if you're building an AI product, you need a way to measure if the thing is good or not. Now on this channel, we talk a lot about evals, but I realize that a lot of people don't know what evals are and they're very new to the subject. And I want to do a very gentle introduction that just goes over some of the important concepts in evals. So let's dive in. First, we'll discuss the difference between product-specific evals and foundation model benchmarks. Now, foundation model benchmarks are basically general intelligence tests. Think about the SAT or an IQ test, and it's just trying to test the model's general intelligence. Whereas product-specific evals are very specific to your product or task that you want to achieve. So let's say you have some kind of AI assistant whose job is to help people with orders, let's say for e-commerce. You want to have an eval for specific tasks like ability to cancel orders correctly. You can see a user might ask, "Cancel my order. " It goes through your agent. There might be context that needs to be pulled. There might be multiple calls to. of the LLM, and then you have an outcome that you can measure, has the order been canceled? And that's a very different exercise than foundation model benchmarks.

如果你在打造AI产品,你大概知道需要一种方法来衡量它做得好不好。 在这个频道上,我们经常谈论evals,但我意识到很多人并不了解evals是什么,对这个主题还很陌生。 我想做一个非常温和的入门介绍,梳理一下evals中的一些重要概念。 那我们开始吧。 首先,我们将讨论产品专用evals和基础模型基准测试之间的区别。 基础模型基准测试基本上就是通用智能测试。 可以想想SAT或智商测试,它只是在测试模型的通用智能。 而产品专用evals则非常针对你的产品或你想要完成的任务。 比如说,你有一个AI助手,它的工作是帮助人们处理订单,假设是电子商务场景。 你会希望为一些具体任务设置eval,比如能否正确取消订单。 你可以看到,用户可能会问:“取消我的订单。” "请求会经过你的智能体。 可能需要调取一些上下文信息。 可能会多次调用 LLM,然后得到一个可以衡量的结果:订单是否已被取消? 这与基础模型基准测试是非常不同的工作。

So examples of foundation model benchmarks are things like MMLU, Terminal Bench, Humanity's Last Exam, and usually see these foundation model benchmarks presented like this with a Pareto chart. And the Pareto chart has performance on the Y axis and cost on the X axis. And this can be flipped, but the idea is the same. Basically, with AI, there's usually a cost-performance trade-off, meaning the longer you spend thinking or the more tokens you spend, the better you can often perform on a task. So there's a trade-off. When it comes to product-specific evals, you'll find that the Pareto frontier becomes very different. Those gray dots, some of them that were at the bottom below, they will rise to the top because your task-specific performance is usually very different than this general intelligence test.

基础模型基准测试的例子包括MMLU、Terminal Bench、Humanity's Last Exam等,通常这些基础模型基准测试会以帕累托图的形式呈现。 帕累托图的纵轴是性能,横轴是成本。 这两个轴也可以颠倒,但核心思想是相同的。 基本上,在AI领域通常存在成本与性能之间的权衡,也就是说,思考时间越长或消耗的token越多,模型往往在任务上表现越好。 所以这里存在一种权衡。 在涉及特定产品的评估时,你会发现帕累托前沿变得非常不同。 那些灰色的点,其中一些原本位于下方,它们会升到顶部,因为你的特定任务表现通常与这种通用智能测试大不相同。

So when a user interacts with your application, for example, for a chatbot, there's a number of things that happen in context. context that the LLM sees. And a conversation can often look like this, where a user asks a question, the agent looks at the system prompt, it might make a tool call, there might be a tool call result, and the assistant may reply, and there might be follow-up questions and goes on and on. You'll see this in chatbots all the time. Basically, a trace is a comprehensive record of everything that happened in a user session. Now, it doesn't have to be a chatbot, it can be any AI workflow, but you are capturing everything. You're capturing all the prompts, all the context, tool calls, tool calls results, anything that the AI sees in order to solve the problem, including any sub-agents. You need to instrument your code. You want to store those traces somewhere, usually in a database. And then you also want to have some kind of trace viewer that allows you to see these traces in a human-readable way so that you can review them. You'll use traces to find issues in your application.

所以当用户与你的应用交互时,例如使用聊天机器人,上下文中会发生许多事情。 也就是LLM所看到的上下文。 一段对话通常可能是这样的:用户提出一个问题,智能体查看系统提示词,可能进行一次工具调用,可能会有工具调用结果,助手随后回复,接着可能还有后续问题,如此不断持续下去。 你在聊天机器人中经常会看到这种情况。 基本上,追踪记录(trace)是用户会话中所发生的一切的完整记录。 现在,它不一定是聊天机器人,可以是任何AI工作流,但你要捕获的是全部内容。 你需要捕获所有提示词、所有上下文、工具调用、工具调用结果,以及AI为解决问题所看到的任何内容,包括任何子智能体。 你需要对代码进行插桩(埋点)。 你需要将这些追踪记录存储在某处,通常是数据库中。 然后,你还需要某种追踪查看器,使你能够以人类可读的方式查看这些追踪记录,从而进行审查。 你将利用追踪记录发现应用中的问题。

You'll use these same traces to also test changes that you may want to make, and then debug failures. So again, here is a trace. It might look something like this. And what you want to do when you annotate a trace is just describe what went wrong. So in this case, there is a tool call where the cancellation failed, but the assistant still gave the user a message of your order is canceled. So you would want to write some notes like, hey, we said it was canceled, but it's not. Then you can ask AI to help you group failures. And what you're looking for is themes of failures or categories or a taxonomy, whatever you want to call it, but you want to group your failures. For example, you might have false confirmations, like we just saw, or you might have wrong orders or missed handoffs. You want to get an idea of the patterns that exist in your data. Those false confirmations, they might actually have two different distinct groups in there, like a tool call is failed or the tool is never called. And you might want to break that out, but you need to review these groups and refine them a bit until you're satisfied with these groups. After you've created these groups, the next thing you want to do is do some very simple analysis.

你还会使用这些相同的追踪记录来测试你可能想做的更改,然后调试失败案例。 所以,这里再次展示一条追踪记录。 它可能看起来像这样。 当你为追踪记录添加标注时,你要做的就是描述出了什么问题。 比如在这个例子中,有一次工具调用失败了,取消操作没有成功,但助手仍然向用户回复“您的订单已取消”。 所以你会想写一些备注,比如:嘿,我们说已经取消了,但实际上并没有。 然后你可以让AI帮你对失败案例进行分组。 你要找的是失败的主题或类别,或者说分类体系,叫法随你,但你要把失败案例分组。 例如,你可能会有虚假确认的情况,就像我们刚才看到的那样,也可能有错误的指令或遗漏的交接。 你要对数据中存在的模式有一个大致了解。 那些虚假确认其实可能包含两个不同的组别,比如工具调用失败,或者工具根本没有被调用。 你可能想把它们拆分出来,但需要审视这些分组并加以完善,直到你对它们满意为止。 创建好这些分组后,下一步是做一些非常简单的分析。

My recommendation is to start with counting. You can just count the failures in each of the groups. You can let that guide you towards what you should work on next. The next natural question is, How do you know what traces to even look at? Should you just keep annotating them randomly? How do you make good use of your time here? And that's when we get into sampling traces. And there's lots of different ways to do this. There's a spectrum from exploring your traces, so using random sampling, and that's where you are going to learn the most because you're trying to explore unknown unknowns. You're trying to look for new problems. There's also clustering, where you can group your traces into similar themes and explore what might be going wrong in a more structured way. You can also use data analysis, which is you can compute statistics about your traces like number of turns, latency, number of tool calls, so on and so forth. And you can see if there's any outliers, and that could give you clues on promising things to explore. When you're starting out, you should do more exploration. As you gain more experience in the data set or in the problem, you can use more signals. But you always want to do some level of exploration at all times.

我的建议是从计数开始。 你可以直接统计每个组中的失败数量。 这些数字可以帮助你决定接下来应该优先处理什么。 接下来自然的问题是:你到底该看哪些轨迹? 难道就随机地一直标注下去吗? 你要如何把时间用在刀刃上? 这就涉及到对轨迹进行采样。 采样的方法有很多种。 从探索你的轨迹,即使用随机采样,到其他方法,形成一个谱系;随机采样是你学到最多的方式,因为你要探索未知的未知问题。 你要寻找新的问题。 还有聚类,你可以把轨迹归入相似的主题,从而以更有结构的方式探索可能出现的问题。 你还可以使用数据分析,即计算轨迹的统计指标,比如对话轮数、延迟、工具调用次数等等。 你可以观察是否存在异常值,这可能为你指明值得探索的方向。 刚开始的时候,你应该多做一些探索。 随着你对数据集或问题积累更多经验,就可以使用更多的信号。 但无论何时,你都应该保持一定程度的探索。

Synthetic data is very limited, and you shouldn't reach for it first, but it is a good tool to have in your tool belt. So how does synthetic data work? You get an AI to generate user inputs. You don't want to generate an entire trace synthetically. What you want to do is generate the input to your system. That can be a user message or if it's an AI workflow that's not a chatbot, it can be whatever the input to your system is that AI is receiving. For example, cancel my order and put that synthetic input into your application and then log the trace. And then of course, after you have this trace, then you can go on to human review. One good way to generate higher quality synthetic data is to think about the various scenarios that you want to simulate. For example, when it comes to canceling your order, let's say you want to fill in that scenario with more data. There might be different scenarios that apply here. For example, what does canceling your order look like before shipping or after shipping or what if the order is unclear or what if the order number is unclear? These are all different scenarios that might actually happen. And what you want to do again is you want to review all of these to make sure they make sense. AI will gladly produce synthetic inputs that are very clear like cancel order. number 42, but users, they'll say stuff like, please cancel the blue one. And you know, the problem is there's no order number here. So you might want to think about what kind of synthetic queries you want to generate. You want to generate synthetic queries or synthetic inputs that match what users are going to do in production or that's going to match the messiness of the real world.

合成数据非常有限,不应该首先就去使用它,但它是你工具箱里一个很好的工具。 那么合成数据是如何工作的呢? 你让AI生成用户输入。 你不需要以合成方式生成整个追踪记录。 你要做的是生成系统的输入。 如果是聊天机器人,那就是用户消息;如果是非聊天机器人的AI工作流,那就是AI接收到的任何系统输入。 例如,“取消我的订单”,然后将这个合成输入放入你的应用程序,并记录追踪记录。 当然,在获得这条追踪记录之后,你就可以进入人工审核了。 生成更高质量合成数据的一个好方法,是思考你想要模拟的各种场景。 例如,就取消订单而言,假设你想为这个场景补充更多数据。 这里可能适用不同的场景。 例如,取消订单在发货前、发货后是什么样子,或者订单不明确、订单号不清楚的情况又是怎样? 这些都是可能真实发生的不同场景。 而你要再次做的是审查所有这些场景,确保它们合乎情理。 AI很乐意生成非常清晰的合成输入,比如“取消订单”。 “42号”,但用户会说类似“请取消蓝色那个”之类的话。 而问题在于,这里并没有订单号。 所以你可能需要想清楚想要生成什么样的合成查询。 你希望生成的合成查询或合成输入,要符合用户在生产环境中实际会做的事情,或者要能匹配现实世界的杂乱情况。

Another place where synthetic data is really useful is retrieval or RAG. And so the way it works is you start with your corpus of documents. So let's say, for example, this is the return policy. And what you do is you have an LLM generate a plausible question that can be answered by that document. So for example, how long do you have to return items? And your task is to retrieve this document given this question. So you're going in reverse.

合成数据另一个非常有用的地方是检索或RAG。 具体的做法是,先从你的文档语料库开始。 比如说,这是退货政策。 接着你让一个LLM生成一个合理的问题,而这个问题可以由该文档回答。 例如:退货需要在多长时间内完成? 你的任务是根据这个问题检索出这份文档。 所以你是在反向操作。

Look, I know we're going through this stuff really fast. If you want more details about how to validate your product with evals, I'll leave a link in the comments. I'll give you a lot more detail into these concepts. Now you're ready to create automated evals. Automated evals can take many forms, but it's. Essentially what you're doing is grading traces. And those grading of traces can be done offline or you can stream production data through an eval and have it be graded. And so there's many ways to grade a trace. So you can write code to assert something about a trace. Let's say like it shouldn't contain a certain user ID or it shouldn't contain a certain tool call. You can check to see whether that trace has some kind of failure mode. The other kinds of ways of grading a trace, one is a classifier. So you can use something like a decision model or a normal classifier to classify if a trace is good or bad. Or you can use an LLM as a judge. Now I recommend using an LLM as a judge as a classifier too, to say if some trace is either pass or fail. Highly recommend binary scores because if you try to output a more complicated score like something on a range of one to five or zero to a hundred, nobody knows what that means and that gets very complicated later on when it comes time to validating these automated evals. So you don't want to do that. You want these binary pass and. fail.

听着,我知道我们讲得很快。 如果你想更详细地了解如何用evals验证你的产品,我会在评论区留下链接。 我会更深入地讲解这些概念。 现在你已经准备好创建自动化evals了。 自动化evals可以有多种形式,但其本质是: 对trace进行评分。 这种trace评分可以离线完成,也可以将生产数据流式输入eval中进行评分。 因此,对trace评分的方法有很多种。 你可以编写代码来断言trace的某些内容。 比如它不应包含某个用户ID,或者不应包含某个特定的工具调用。 你也可以检查该trace是否存在某种失败模式。 评估轨迹的其他方式之一是分类器。 因此,你可以使用决策模型或普通分类器之类的方法,来判断一条轨迹是好还是坏。 或者,你也可以使用LLM作为评判者。 我推荐将LLM作为评判者同时用作分类器,用来判断某条轨迹是通过还是失败。 强烈推荐使用二元评分,因为如果你尝试输出更复杂的分数,比如一到五分或零到一百分,没人知道这意味着什么,而且等到后面需要验证这些自动化评估时,问题会变得非常复杂。 所以你不应该这样做。 你需要的是这种二元的通过和 失败。

So when it comes to trusting these automated evals, you have some kind of ground truth. And the ground truth is usually coming from a human, and you want to have labeled some data. And you might have done this during error analysis, you might have labeled data elsewhere, but you want to go through an exercise of labeling some data. And AI can help you label this data. There's techniques that you can use to quickly label data, have AI propose labels, and you accept them. And you'll have different kinds of errors. You'll have missed failures. So these are things you didn't catch. And then you'll have false alarms, the things that are marked as a failure, but they're really not. So you can split your data set into three pieces. The first piece is a train set, and the train set can be used as examples in your prompts. Your LLM as a judge or decision model will have a prompt with instructions saying what is good and bad. And in that prompt, you also want to show some examples. And you can pull these examples from this training set. Another segment of your data that you want to hold aside is your dev set. Now, this dev set is where you're going to tune. in your model. This can be roughly 40% of your data set. And what you can do here is observe the agreement or disagreement between the human and the evaluator. And what you want to do is then keep refining your prompt until this gets better and keep hill climbing uh towards making these two as aligned as possible. And AI is really good at this. There's algorithms that can help you with this. Now, the only trick is you don't want to overfit. It's very easy to overfit and make your automated eval really good on this dev set. And you don't want to do that. You want to make sure that this eval works outside the dev set. And so that's why you set aside this final test set. And on the final test set, what you do is you take your finished prompt and then you do a final check on how well the human and the evaluator agree with each other.

因此,在信任这些自动化评估时,你需要某种真实标准(ground truth)。 而这个真实标准通常来自人工,你需要标注一些数据。 你可能在错误分析过程中已经做过这项工作,也可能在其他地方标注过数据,但你仍然需要完成一次标注数据的练习。 AI可以帮助你标注这些数据。 有一些技术可以帮助你快速标注数据:让AI提出标签,然后你接受这些标签。 你会遇到不同类型的错误。 你会有漏检的失败。 也就是你没有发现的问题。 然后还会有误报,即被标记为失败,但实际上并不是失败的情况。 因此,你可以把数据集分成三部分。 第一部分是训练集,训练集可以用作提示词中的示例。 你的LLM评判者或决策模型的提示词中会包含说明,指明什么是好的,什么是坏的。 在那个提示词中,你还想展示一些示例。 你可以从这个训练集中提取这些示例。 你想单独留出的另一部分数据是你的开发集。 现在,这个开发集是你用来调优的地方。 在你的模型中。 它大约可以占你数据集的40%。 你在这里要做的是观察人工评审与评估器之间的一致或不一致之处。 接下来你要做的是不断优化你的提示词,直到结果变好,并持续逐步改进,力求使两者尽可能一致。 而AI在这方面非常擅长。 有一些算法可以帮助你完成这项工作。 现在,唯一需要注意的是不要过拟合。 很容易过拟合,使你的自动化评估在这个开发集上表现非常好。 而你不希望这样。 你要确保这个评估在开发集之外也能有效。 所以这就是为什么你要留出这个最终测试集。 在最终测试集上,你要用完成的提示词进行最后检验,看看人工评审与评估器之间的一致程度如何。

And if this is good, then you know that you haven't overfit. If this is bad, then you know you've overfitted and then you need to do this whole thing again. So after you've created these automated evals and you trust them, now you can deploy them in different places. So you can put automated evals in CI/CD. You can have your automated evals. Evals monitor production traffic and tell you in real time or near real time where errors are occurring. Or you can also make some of these evals guardrails. So guardrails are just things that sit in the request response path and block things from reaching the user. They usually are blocking unsafe things from reaching the user.

如果结果良好,那么你就知道没有过拟合。 如果结果不好,那么说明你已经过拟合,需要把整个过程重新做一遍。 因此,在你创建了这些自动化评估并且信任它们之后,现在就可以把它们部署到不同的场景中。 例如,你可以把自动化评估放入CI/CD中。 你可以使用自动化评估。 评估会监控生产环境的流量,并实时或近实时地告诉你错误发生在哪里。 你也可以把其中一些评估变成护栏。 所以护栏就是位于请求和响应路径上的组件,负责阻止某些内容传递给用户。 它们通常用于阻止不安全的内容传递给用户。

So now that you've learned about automated evals, the next thing I want to do is cover some big traps that you're likely to fall into if you're dealing with evals or even if someone else on your team is writing the evals. And the first trap is using generic metrics. You don't want to ever use generic metrics. You'll see scores on a range of one to five. They don't really make sense. If you think about it, what is four point two versus four point five versus three point nine? Like what does it even mean? It's not actionable. What you want to do instead is measure specific failures to your product that are actionable. And so back to the order cancellation example, what you want to do is have evals that capture whether or not this task is happening successfully. Now evals. are expensive. They take time and resources to build and maintain, and you can't build an eval for everything. If you tried to do that, you would run out of time and money really fast. There are some rules of thumb you should think about when it comes time to deciding whether or not you should build an eval for a problem you are observing.

既然你已经了解了自动化评估,接下来我想讲讲在处理评估时很可能会陷入的几个大陷阱,即使是团队中其他人在编写评估,这些陷阱也同样值得注意。 第一个陷阱是使用通用指标。 你永远不应该使用通用指标。 你会看到一些在一到五分之间的评分。 这些分数其实没什么实际意义。 仔细想想,4.2分、4.5分和3.9分分别代表什么? 它们到底意味着什么呢? 这些分数无法指导行动。 你应该做的是衡量产品中具体的、可以采取行动的失败情况。 回到订单取消的例子,你应该设计评估来检查这项任务是否成功完成。 现在来说评估。 评估的成本很高。 构建和维护评估需要耗费时间和资源,而且你不可能为所有问题都建立评估。 如果你试图这样做,很快就会耗尽时间和金钱。 当你需要决定是否为所观察到的某个问题建立评估时,有一些经验法则值得考虑。

One is try to observe the problem. So either you found the problem in your traces or you're able to reproduce the problem. It's also okay to brainstorm potential things that can go wrong. And it's okay to worry about problems that haven't happened yet. If you are worried about those problems, you need to be able to reproduce it in your system. Another thing you want to think about is, is this problem something you're going to iterate on? Evals are best for things where you'll need to iterate and you don't know how to fix off the bat. That eval is going to give you a lot of value because it'll give you signal so that you can do a lot of experiments to try out things in order to fix a problem. Evals should help you guide product decision making. There should be some threshold over which something is good enough to ship, and you need to encode that into your. Your evals. It takes some discipline to have binary outputs in your evals to say something passes or fails, but you need to figure out what is good enough to ship, and you need to be very clear on what constitutes a pass versus a fail. The most important thing to know about evals is you should be using evals to make your product better. That's the whole point. You're not making evals for evals' sake. Whenever you make a change to, let's say, your prompt or code, you can run your evals, and then you can decide whether those changes are good or not. Now, you don't have to do this manually. You can also automate this process, and a lot of people have done this. You can have your agent automatically try to hill climb by running evals and seeing what fails, and then iterating on your system. Now, you have to be careful when you do this. You have to have a pretty good set of evals that are comprehensive and span the space of things that can go wrong, so that your agent doesn't try to hack this metric, do really well on evals at the expense of something else. I recommend not just letting an agent go at it by themselves. What happens. happens in a lot of these self-improving systems is that this agent will try to improve the prompt. What I recommend is having a human review the prompt that the agent comes up with and then simplifying or cleaning up the prompt and getting ideas from the prompt rather than just adopting whatever the agent proposes here blindly. One thing you're going to want to do here is make sure you check your system's behavior on unseen test cases. Another way to make your product better by using evals is to explore different models, especially using a smaller model for a specific task. And what you can do is measure your tasks on both cost and quality using your evals to measure quality. You can take important tasks and set a minimum quality bar, and then you can see if for current tasks, when moving to a smaller model, can you keep the same or higher quality but just decrease the cost? And this is a very common thing to do, often a low-hanging fruit after you have evals. There's a lot of things I haven't covered here, for example, how to evaluate retrieval, which is a. deep subject on its own, as well as a whole bunch of other stuff. But these are the concepts I think that you should pay attention to if you're first learning about evals. If you're just getting started with the evals and you made it all the way through this video and you want to learn more, a good next video to watch is this AI evals tier list. I go through a bunch of common pitfalls people make with evals and I rank them. And it's a good way to quickly learn how you can not waste time when doing evals.

第一步是尝试观察问题。 所以,要么你在追踪记录中发现了问题,要么你能够重现这个问题。 头脑风暴可能出错的各种情况也没问题。 担心那些尚未发生的问题也是可以的。 如果你担心这些问题,就需要能够在自己的系统中重现它们。 另一件需要考虑的事是:这个问题是你需要反复迭代改进的吗? 评估最适合那些需要反复迭代、而且一开始就不知道如何解决的问题。 这种评估会带来很大价值,因为它能提供信号,让你进行大量实验,尝试各种方法来解决问题。 评估应该帮助你指导产品决策。 应当设定一个阈值,超过它就说明某个东西足够好、可以发布,并且你需要把这个阈值编码进你的 评估中。 评估中使用二元输出(即判定通过或失败)需要一定的纪律性,但你必须确定什么样的水平足以发布,并且非常清楚什么算通过、什么算失败。 关于评估,最重要的一点是:你应该利用评估来让产品变得更好。 这才是全部的意义所在。 你不是为了评估而做评估。 每当你对比如提示词或代码做出修改时,都可以运行评估,然后判断这些修改是否有效。 不过,你不必手动完成这一切。 你也可以将这个过程自动化,很多人都已经这样做了。 你可以让智能体通过运行评估、查看哪些地方失败,然后迭代优化系统,自动进行爬山式优化。 不过,做这件事时你必须小心。 你需要一套相当完善的评估集,它要全面覆盖各种可能出错的情况,这样你的智能体才不会去钻这个指标的空子,在其他方面有所牺牲的情况下,只为了在评估中取得很高的分数。 我建议不要只让智能体自己去做。 会发生什么呢? 在很多这类自我改进系统中,智能体会尝试改进提示词。 我的建议是让人工审查智能体提出的提示词,然后精简或整理它,并从中获取思路,而不是盲目采纳智能体提出的任何修改。 这里有一件事你需要做:确保检查系统在未见过的测试用例上的表现。 利用评估来改进产品的另一种方式,是探索不同的模型,尤其是为特定任务使用较小的模型。 你可以用评估来衡量质量,同时衡量任务的成本和质量。 你可以选取重要任务并设定一个最低质量标准,然后看看对于当前任务,切换到较小的模型时,能否保持相同或更高的质量,同时降低成本。 这是一件很常见的事情,通常在有了评估之后,它是一个唾手可得的优化点。 还有很多我没有在这里讲到的内容,例如如何评估检索,这本身是一个 很深入的独立课题,此外还有许多其他内容。 但这些是我认为你初学评估时应该关注的概念。 如果你刚开始接触评估,并且看完了这个视频想进一步学习,接下来可以看看这个“AI评估梯队排名”视频。 我会讲解人们在评估中常犯的一些陷阱,并对它们进行排名。 这是一个快速了解如何在做评估时避免浪费时间的好方法。

Overview

本视频面向刚接触 AI 评估的读者,系统梳理了评估的核心概念和实践流程。视频首先区分产品专用评估与基础模型通用基准,指出前者应围绕具体任务结果衡量产品表现。随后依次介绍追踪记录(trace)、错误分析、抽样方法、合成数据和自动化评估,其中包括用二元标签校准 LLM 评判器、划分训练集、开发集和测试集以防过拟合。最后讨论常见误区,如使用泛化的 1 到 5 分指标、过早构建评估,以及让智能体无人监督地针对指标优化。视频的核心观点是:评估的目的是让产品变得更好,而不是为评估而评估。整体脉络清晰,适合作为入门指南。

Chapters

00:00 产品评估与基础模型基准的区别

基础模型基准(如 MMLU、Terminal Bench、Humanity's Last Exam)测试的是模型的通用智能,常以帕累托图展示性能与成本之间的权衡。产品专用评估则针对具体任务。以电商订单助手为例,评估应检验能否正确取消订单,并以订单是否真的被取消作为可衡量的结果。这类评估与通用基准的侧重点完全不同。

开场提出AI产品需要衡量好坏
说明本频道讨论评估主题
介绍本次讲解的评估核心概念
进入正题的过渡画面
提出产品评估与基础模型基准的区别

01:08 产品任务场景下的帕累托前沿变化

通用基准中,AI 通常存在成本与性能的权衡:思考越久或消耗的 token 越多,任务表现往往越好。在产品专用评估中,帕累托前沿会明显不同。原本位于底部的一些模型,在特定任务上的表现会显著提升,因为任务专属表现与通用智能测试的结果往往差异很大。

基准测试以帕累托图呈现的整体示意
帕累托图的纵轴为性能、横轴为成本
产品任务评测下帕累托前沿的变化
灰色点位上升到前沿的变化

01:52 追踪记录(Trace)的定义与实现

一次对话中,用户提问、智能体读取系统提示词、工具调用及其结果、助手回复和后续追问会依次出现,这些内容都构成模型可见的上下文。追踪记录是用户会话的完整记录,应包括所有提示词、上下文、工具调用与结果,以及子智能体的活动。实现时需要对代码进行埋点,将记录存入数据库,并配备可供人工阅读的追踪查看器。追踪既用于发现问题、测试改动,也用于调试失败案例。

追踪记录的核心定义:用户会话中发生的全部内容
章节代表画面
可供人工阅读和审查追踪记录的查看器

02:51 错误分析:标注、分组与计数

错误分析从标注追踪开始,即用文字描述哪里出错。例如取消订单的工具调用失败,但助手仍告诉用户订单已取消,这种“错误确认”应被记录下来。随后可借助 AI 对失败案例进行分组,形成主题或分类体系,例如错误确认、错订单或漏交接,并根据数据模式细分类别,如工具调用失败与工具从未被调用。分组需要经过人工审核和反复修订。分组完成后,最简单的分析方法是统计各组的失败数量,以此决定下一步的优化重点。

展示待标注的追踪记录(trace)画面
追踪中工具调用失败但助手仍回复订单已取消的错误输出

03:51 追踪抽样策略

面对大量追踪,需要决定优先查看哪些。抽样方法可以从随机抽样的探索,到基于聚类的主题分组,再到统计指标(如对话轮数、延迟、工具调用次数)的异常值分析。随机抽样最能发现未知的未知问题,异常值则能提供值得深入研究的线索。项目初期应以探索为主,随着对数据和问题的熟悉,可以更多依赖各类信号,但始终需要保留一定程度的探索。

抽样策略频谱概览(从探索式随机抽样到结构化方法)

04:54 合成数据的生成与场景设计

合成数据有明显局限,不应优先使用,但可作为补充工具。做法是让 AI 生成系统的输入,例如用户消息或非聊天型工作流的输入,而不是整条追踪。生成后将输入送入应用并记录追踪,之后再进行人工审核。提高质量的方法是先设计场景,例如订单在发货前或发货后取消,订单信息不清或订单号缺失等。AI 容易生成过于清晰的指令,如“取消 42 号订单”,而真实用户可能说“取消那个蓝色的”,因此合成查询应贴近真实使用中的杂乱情况。

合成输入需贴近真实世界的杂乱表达(无明确视觉画面,代表性锚点)

06:19 检索(RAG)场景下的合成数据

在检索增强生成(RAG)场景中,合成数据的做法与对话场景相反。先从文档语料库出发,例如一份退货政策,再让 LLM 生成能够由该文档回答的合理问题,如“退货期限是多久”。评估任务则是根据该问题检索出对应文档,因此流程是“反向”的。

文档语料中的退货政策示例

06:44 自动化评估:评判方式与二元评分

自动化评估的本质是对追踪进行评分,可以离线运行,也可以让生产数据流经评估器实时评分。评分方式包括:用代码断言追踪中是否包含某用户 ID 或某工具调用;用经典分类器或判别模型判断好坏;用 LLM 作为评判器。视频特别推荐使用二元通过或不通过的评分。如果采用 1 到 5 分或 0 到 100 分的复杂分数,没人能说清每个分数的含义,后续验证自动评估时也会变得非常复杂。

无明确画面指引,以二元评分这一核心结论作为代表性锚点

08:00 用人工标注数据校准自动评估

要信任自动评估,需要以人工标注的真值作为依据。标注可以在错误分析中完成,也可以另外进行,AI 还能先提出标签、由人工接受或修改,从而提高效率。评估结果的错误分为两类:漏判(该失败的没有被发现)和误报(被标为失败但实际正常)。数据应划分为三部分。训练集的样例可用于提示词中的示例。开发集约占 40%,用于观察人工与评估器的一致性,并不断优化提示词以提高一致性,这一过程可借助算法辅助。测试集则在最终提示词定稿后用于检验一致性,以判断是否过拟合。若测试集表现良好,说明评估器具有泛化能力;若表现较差,则需要重新迭代整个流程。

人工标注真值数据,作为校准自动评估的基准(无明显视觉画面,按代表性概念兜底)

09:43 自动评估的部署:CI/CD、监控与护栏

经过校准并值得信任的自动评估,可以部署在多个环节。它可以接入 CI/CD 流程,也可以持续监控生产流量,近实时地发现错误出现的位置。部分评估还可以作为护栏,即位于请求与响应路径上的组件,用于阻止不安全内容到达用户,这是护栏最常见的用途。

评估结果判断是否过拟合
评估失败时的过拟合判断
自动评估的部署准备
自动评估接入CI/CD流程
自动评估的应用场景

10:18 常见评估陷阱

第一个陷阱是使用通用指标。1 到 5 分这类分数很难解释,例如 4.2、4.5 与 3.9 之间的差别没有明确含义,也无法指导行动。应转而衡量产品中具体、可执行的失败模式。是否需要为某个问题构建评估,取决于几条经验:问题必须已在追踪中被观察到,或能够被复现;可以基于经验推测潜在风险,但这些风险同样需要能在系统中复现;此外,评估最适合那些需要反复迭代、且暂时不知道如何修复的问题。评估的成本高昂,构建和维护都需要时间与资源,不可能为所有问题都建立评估。

1到5分的评分示例

11:16 以评估改进产品与自动优化的注意事项

评估的核心目的是改进产品。每次修改提示词或代码后,都可以运行评估来判断改动是否有益。评估还需要为产品决策提供依据,即先确定什么样的结果才算足够好、可以上线,并把这一标准编码进评估中,明确通过与不通过的界限。在自动优化方面,智能体可以通过运行评估并依据失败结果迭代系统,但必须谨慎:评估需要足够全面,覆盖可能出错的各个方面,以免智能体只针对指标优化而牺牲其他能力。视频建议不要完全放任智能体,而应由人工审核其提出的提示词,并进行简化和清理,同时检验其在未见测试用例上的表现。此外,评估还能用于比较模型:在保证任务质量下限的前提下,将重要任务迁移到更小的模型上,可以在保持质量的同时降低成本,这通常是建立评估后很容易获得的收益。

强调评估的核心目的是改进产品,作为代表性画面

Conclusions

00:34 产品评估应围绕具体任务结果衡量,不能只依赖基础模型的通用基准。

02:17 追踪记录应完整保存用户会话中的提示词、上下文、工具调用与结果,它是发现问题、测试改动和调试的基础。

03:04 错误分析应先用文字标注失败,再将失败归类并统计数量,以确定优先优化的方向。

04:11 探索性抽样(尤其是随机抽样)最能发现未知问题,项目初期应以探索为主。

05:07 合成数据应只生成系统输入并设计贴近真实的场景,不应优先使用,且需经人工审核。

07:42 自动评估的评分应采用二元的通过或不通过判断,避免难以解释的多级分数。

09:29 自动评估必须依靠人工标注数据校准,并通过独立测试集检验,以防止对开发集过拟合。

10:32 应避免使用通用指标,转而衡量产品中具体、可执行的失败模式。

12:14 评估的根本目的是改进产品,应据此确定上线阈值,并将其编码进评估标准。

13:05 让智能体自动优化时,应由人工审核其提出的提示词,并检验其在未见测试用例上的表现。

13:39 在保持质量下限的前提下,可用评估比较成本与质量,将部分任务迁移到更小的模型上以降低成本。

AI Eval Concepts Explained in 15 Minutes · Video Summary · OctSum