How to evaluate using LLM-as-a-Judge (Tutorial)

Elvis Saravia · Beginner ·🧠 Large Language Models ·1y ago

Key Takeaways

The video demonstrates how to evaluate the performance of a language model (LM) application using LLM-as-a-Judge metrics, specifically hallucination and answer relevance, with the OPIC framework and GPT for Mini model.

Full Transcript

in this demo we are going to show you how to evaluate using llm as a judge metrics using opic so we're going to explain also the metrics such as hallucination and answer relevance that we're using to assess how good the performance of the LM application is at the desired task all right so we're going to run the first set of lines of code here which is just the usual Imports and again we're performing tracing for our application and then we are using the GPT for Mini model and here is the chb application the typical way on how to call the food chb for a response given a user input and this is just our evaluation task very similar again the code stays the same as before and the only difference would be this hallucination and answer relevance keep in mind that we are still using that data set right that food chatbot eval data set that we were using previously so the metrics here are hallucination and answer relevance and what are these measuring so the chop out generates responses based on those user queries and based on the information that's provided the information that's also provided here is the menu items and those menu items contain information that the llm should be able to use to respond factually to the user queries in a chat setting so Hallucination is is the metric that allows you to check if the llm response contains any hallucinated information and so in order to check for this you will need to provide the llm input which is this input the user query and you also need to provide the llm output as well which is this part here and in addition to that you will need to provide the context so this particular metric uses those Tri bits of information this is very different from the previous metrix in the previous metrix theistic metric such as lonstein distance for instance was using and comparing the output of the model and the reference in this case we're using these three and for answer relevance the idea is that this metric allows you to evaluate how relevant and appropriate the llm response is to the given input question or prompt so in order to assess the relevance of the answer you will need to provide the llm input which is again the this input right here and the llm output which is going to be this part here and so what the answer relevance does is it's going to mainly focus on the appropriateness and pertinence of the response rather than the factual accuracy of it which is what the hallucination one is doing so that's the of answer relevance and both of these metrics are based guess what on llms this is why these approaches are referred to as l LM based evaluation because they're using an llm or prompting an llm to do the scoring for both of these metrics and the experiment name is again the one that we have been using here and then we run the evaluation and the evaluation expects the experiment name the data set the same data set the evaluation task again this one here and the scoring metrics which are those metrics and then the config which you can pass any information that you like here we're passing just the model name here all right so now we can run this again takes a little bit of time a minute to two is what it takes for these experiments so sometimes it fails to compute the answer relevance metric and sometimes that has to do with the prompt itself The Prompt that's used to do this evaluation and sometimes what you'll need to do is you need to find a work around that sometimes you need to specify custom metrics so these metrics are not perfect by any means again because they are based on an llm but anyways so it finished here and you can see that it definitely failed on one so we're going to look into that the UI and why exactly it failed but you can see the hallucination metric here is 0.42 and answer relevance metric is 0.72 and that's the average score so definitely we're getting really nice score for answer relevance that's really nice to see and for hallucination we want to see that as low as possible so if it's one that means that's the highest and if it's zero that means we have no hallucination so this is really good to see already and again number of samples in 56 on the little report here all right let's switch over to the opic UI and see what went on here so here is the new evaluation or the experiment that was conducted just now so we can click on that and you will see here is the aage score that you saw in the terminal so these are the average scores and now we can take a look at some of these outputs here so let's try to take a look at this one so this one notice that it doesn't contain the answer relevance metric right so if we look at that more closely we can see that the Ed op was this so the menu does not list any gluten-free deserts specifically are there any offerings for gluten-free desserts and so we can take a look at the output of the model here and the output was we don't have gluten-free desserts but we do have delicious options like fresh Berry parfait so for some reason it wasn't able to provide a score for this and it raised an exception but as I was mentioning these metrics are not perfect by any means and our job now is to think about oh we might might need to actually develop some custom metric for this so that we can get more reliable results but this is still good we only got one fail so that means most of the other ones were working but we can quickly assess here that yeah it might have been the way the model was scoring because this looks okay there's nothing wrong with the actual output as far as I can tell let's look at an example here I want to really look at some of these examples they're really fun to see like for instance this one answer relevance metric so this one offers an explanation as well so let's look at this one is the vegan Beyond Burger a popular choice and then the expected output here is the vegan Beyond Burger is a popular choice on our menu with a popularity rating of four out of five looks like it's a popular one and the output of the model was the v b Burger is a delicious favorite rated for out of five featuring a tasty plant-based Patty and all the fixings plus your choice of fries so very interesting tone very enthusiastic and we can look at the answer relevance metric and the reason why this was scored so high this is very close to the highest score that you can get for answer relevance so it says the answer directly addresses the query about the popularity of the vegan Beyond Burger by seting it as a delicious favorite rated four out of five that explanation is actually coming from the llm and that's why it's referred to as llm based evaluation and then it says it provides relevant information about the plant-based Patty and fixings and so on so this is really cool because you can get an idea on why this was considered to be super relevant in terms of the response that we're getting from the llm and given the input and the menu information and for hallucination there's no hallucination but you can see the explanation here it says the output accurately states that the vegan Beyond Burger is rated four out of five in popularity so that's really awesome to see and we can go on and continue to look at the different results here specifically we might want to take a look at the answer relevance how we can get this higher and and then how we can reduce this as well so you will look at different examples where the hallucination metric is high and where the answer relevance is low and so that will give you some intuition into what else you can fix how you can iterate on your prompts so the idea is to gain insights as you do this evaluation and you continue to run more and more and more experiments that's the idea behind this type of experimentation that we're doing here we are using the concept of llm as a judge is very easy to do using opic

Original Description

For code and full tutorial enroll in our FREE course on LLM Evaluation: https://www.comet.com/site/llm-course/ #ai #chatgpt #artificialintelligence
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Elvis Saravia · Elvis Saravia · 0 of 60

← Previous Next →
1 101 ways to solve search (by Pratik Bhavsar)
101 ways to solve search (by Pratik Bhavsar)
Elvis Saravia
2 TLDR Generation of Scientific Documents | ML Interview #1 with Isabel Cachola
TLDR Generation of Scientific Documents | ML Interview #1 with Isabel Cachola
Elvis Saravia
3 Sentiment Analysis: Key Milestones, Challenges and New Directions
Sentiment Analysis: Key Milestones, Challenges and New Directions
Elvis Saravia
4 Discriminative Adversarial Search for Abstractive Summarization (by Thomas Scialom)
Discriminative Adversarial Search for Abstractive Summarization (by Thomas Scialom)
Elvis Saravia
5 Question Understanding: COVID-Q: 1,600+ Questions about COVID-19
Question Understanding: COVID-Q: 1,600+ Questions about COVID-19
Elvis Saravia
6 Getting Started with NLP
Getting Started with NLP
Elvis Saravia
7 Building tools and frameworks for large-scale social media mining (by Dr. Juan M. Banda)
Building tools and frameworks for large-scale social media mining (by Dr. Juan M. Banda)
Elvis Saravia
8 TextAttack: A Framework for Data Augmentation and Adversarial Training in NLP
TextAttack: A Framework for Data Augmentation and Adversarial Training in NLP
Elvis Saravia
9 Dive into Deep Learning (Study Group): Introduction to Deep Learning | Session 1
Dive into Deep Learning (Study Group): Introduction to Deep Learning | Session 1
Elvis Saravia
10 Dive into Deep Learning (Study Group): Multilayer Perceptrons | Session 4
Dive into Deep Learning (Study Group): Multilayer Perceptrons | Session 4
Elvis Saravia
11 How I read and annotate ML papers
How I read and annotate ML papers
Elvis Saravia
12 Keep Learning ML  (Session 1) | DSV, CompLex, Modern tools for emotions
Keep Learning ML (Session 1) | DSV, CompLex, Modern tools for emotions
Elvis Saravia
13 Dive into Deep Learning (Study Group): Preliminaries | Session 2
Dive into Deep Learning (Study Group): Preliminaries | Session 2
Elvis Saravia
14 Keep Learning ML #2 | Language-conditioned policy learning, Effective ML Testing, EagerPy
Keep Learning ML #2 | Language-conditioned policy learning, Effective ML Testing, EagerPy
Elvis Saravia
15 Dive into Deep Learning (Study Group): Linear Neural Networks | Session 3
Dive into Deep Learning (Study Group): Linear Neural Networks | Session 3
Elvis Saravia
16 Dive into Deep Learning (Study Group): Multilayer Perceptrons | Session 4
Dive into Deep Learning (Study Group): Multilayer Perceptrons | Session 4
Elvis Saravia
17 Keep Learning ML #3 | Contrastively Trained Structured World Models
Keep Learning ML #3 | Contrastively Trained Structured World Models
Elvis Saravia
18 Dive into Deep Learning (Study Group): Deep Learning Computation with PyTorch |  Session 5
Dive into Deep Learning (Study Group): Deep Learning Computation with PyTorch | Session 5
Elvis Saravia
19 Dive into Deep Learning (Study Group): Convolutional Neural Networks | Session 6
Dive into Deep Learning (Study Group): Convolutional Neural Networks | Session 6
Elvis Saravia
20 Dive into Deep Learning (Study Group): Modern CNNs | Session 7
Dive into Deep Learning (Study Group): Modern CNNs | Session 7
Elvis Saravia
21 101 ways to solve neural search with Jina
101 ways to solve neural search with Jina
Elvis Saravia
22 (Hopefully-Reusable) Life Lessons for PhD Students in NLP
(Hopefully-Reusable) Life Lessons for PhD Students in NLP
Elvis Saravia
23 How to save the world and forward your career in 5 easy steps | Women in NLP Talks
How to save the world and forward your career in 5 easy steps | Women in NLP Talks
Elvis Saravia
24 Prompt Engineering Overview
Prompt Engineering Overview
Elvis Saravia
25 Getting Started with the OpenAI Playground
Getting Started with the OpenAI Playground
Elvis Saravia
26 LM-Guided Chain of Thought
LM-Guided Chain of Thought
Elvis Saravia
27 Elements of a Prompt
Elements of a Prompt
Elvis Saravia
28 Reasoning with Intermediate Revision and Search with LLMs #chatgpt #ai #llms #science #programming
Reasoning with Intermediate Revision and Search with LLMs #chatgpt #ai #llms #science #programming
Elvis Saravia
29 General Tips for Designing Prompts
General Tips for Designing Prompts
Elvis Saravia
30 Efficient Infinite Context Transformers #ai #machinelearning #research #llms #science
Efficient Infinite Context Transformers #ai #machinelearning #research #llms #science
Elvis Saravia
31 Best Practices and Lessons Learned on Synthetic Data for Language Models #ai #machinelearning #genai
Best Practices and Lessons Learned on Synthetic Data for Language Models #ai #machinelearning #genai
Elvis Saravia
32 Reducing Hallucinations in Structured Outputs via RAG #chatgpt #ai #llms #programming
Reducing Hallucinations in Structured Outputs via RAG #chatgpt #ai #llms #programming
Elvis Saravia
33 Basic Prompt Examples for LLMs
Basic Prompt Examples for LLMs
Elvis Saravia
34 LLM In Context Recall is Prompt Dependent  #llms #ai #chatgpt #machinelearning
LLM In Context Recall is Prompt Dependent #llms #ai #chatgpt #machinelearning
Elvis Saravia
35 Zero-shot Prompting Explained
Zero-shot Prompting Explained
Elvis Saravia
36 RAG Faithfulness #llms #ai #gpt4
RAG Faithfulness #llms #ai #gpt4
Elvis Saravia
37 Understanding LLM Settings
Understanding LLM Settings
Elvis Saravia
38 Llama 3 is here! | First impressions and thoughts
Llama 3 is here! | First impressions and thoughts
Elvis Saravia
39 Llama 3 is Here! #ai #llms #llama3
Llama 3 is Here! #ai #llms #llama3
Elvis Saravia
40 Microsoft introduces Phi-3 | The most capable small language model?
Microsoft introduces Phi-3 | The most capable small language model?
Elvis Saravia
41 Microsoft introduces Phi-3! #ai #llms #microsoft
Microsoft introduces Phi-3! #ai #llms #microsoft
Elvis Saravia
42 Make Your LLM Fully Utilize the Context #ai #llms #machinelearning
Make Your LLM Fully Utilize the Context #ai #llms #machinelearning
Elvis Saravia
43 When to Retrieve? #ai #llms #machinelearning
When to Retrieve? #ai #llms #machinelearning
Elvis Saravia
44 Training an LLM to effectively use information retrieval
Training an LLM to effectively use information retrieval
Elvis Saravia
45 State-of-the-art open-source LLM judges #ai #machinelearning #gpt4
State-of-the-art open-source LLM judges #ai #machinelearning #gpt4
Elvis Saravia
46 Better and Faster LLMs via Multi-token Prediction
Better and Faster LLMs via Multi-token Prediction
Elvis Saravia
47 AlphaMath Almost Zero #ai #science #machinelearning
AlphaMath Almost Zero #ai #science #machinelearning
Elvis Saravia
48 SWE-Agent | An LLM-based Software Engineering Agent
SWE-Agent | An LLM-based Software Engineering Agent
Elvis Saravia
49 [LLM NEWS] AlphaFold 3, xLSTM, OpenAI's Model Spec, DeepSeek-V2, OpenDevin CodeAct 1.0
[LLM NEWS] AlphaFold 3, xLSTM, OpenAI's Model Spec, DeepSeek-V2, OpenDevin CodeAct 1.0
Elvis Saravia
50 LLM-powered tool for web scraping #ai #chatgpt #engineering
LLM-powered tool for web scraping #ai #chatgpt #engineering
Elvis Saravia
51 Learn about LLMs in this NEW course #ai #chatgpt #engineering
Learn about LLMs in this NEW course #ai #chatgpt #engineering
Elvis Saravia
52 [LLM NEWS] KANs, Gemma 10M Context, OpenAI Updates?, Automatic Prompt Engineering, Tokenizer Arena
[LLM NEWS] KANs, Gemma 10M Context, OpenAI Updates?, Automatic Prompt Engineering, Tokenizer Arena
Elvis Saravia
53 [LLM News] GPT4-o, Project Astra, Veo, Copilot+ PCs, Gemini 1.5 Flash, Chameleon
[LLM News] GPT4-o, Project Astra, Veo, Copilot+ PCs, Gemini 1.5 Flash, Chameleon
Elvis Saravia
54 Enhancing Answer Selection in LLMs #ai #machinelearning #engineering
Enhancing Answer Selection in LLMs #ai #machinelearning #engineering
Elvis Saravia
55 On exploring LLMs #ai #promptengineering #chatgpt
On exploring LLMs #ai #promptengineering #chatgpt
Elvis Saravia
56 Transformers Can Do Arithmetic with the Right Embeddings #ai #machinelearning #engineering
Transformers Can Do Arithmetic with the Right Embeddings #ai #machinelearning #engineering
Elvis Saravia
57 [LLM News] xAI Series B, Codestral, LLM Guide, AutoGen Course, Symbolic Chain-of-Thought
[LLM News] xAI Series B, Codestral, LLM Guide, AutoGen Course, Symbolic Chain-of-Thought
Elvis Saravia
58 PR-Agent #ai #gpt4 #software
PR-Agent #ai #gpt4 #software
Elvis Saravia
59 Extracting features from Claude 3 Sonnet
Extracting features from Claude 3 Sonnet
Elvis Saravia
60 Has prompt engineering been solved?
Has prompt engineering been solved?
Elvis Saravia

This video tutorial demonstrates how to evaluate the performance of a language model application using LLM-as-a-Judge metrics with the OPIC framework and GPT for Mini model. It covers the concepts of hallucination and answer relevance metrics and how to use them to assess the performance of an LM application.

Key Takeaways
  1. Import necessary libraries and load the dataset
  2. Define the evaluation task and metrics
  3. Run the evaluation using the OPIC framework and GPT for Mini model
  4. Analyze the results and identify areas for improvement
  5. Iterate on the prompts and experiment with different metrics
💡 Using LLM-as-a-Judge metrics with the OPIC framework and GPT for Mini model provides a reliable way to evaluate the performance of language model applications, specifically in terms of hallucination and answer relevance.

Related Reads

Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →