transcribe

Pairwise Evaluation | LangSmith Evaluations - Part 17

LangChain · 13m · transcribed 15d ago
More from LangChain Business
𝕏 Share ▶ YouTube 📥 PDF 🤖 .md

Section Insights

# 0:00

Introduction to Pairwise Valuation

What is pairwise valuation and how does it work?

Pairwise valuation involves comparing outputs from two different language models (LLMs) based on user preference. Users evaluate which output they prefer, effectively acting as judges in the process. This method can also utilize LLMs as judges, allowing for a structured evaluation of generated content.

  • Pairwise valuation allows users to compare outputs from different LLMs.
  • Users or LLMs can act as judges in the evaluation process.
  • This method is akin to A/B testing, focusing on user preference.
# 2:45

Setting Up Pairwise Valuation Tests

How do you set up experiments for pairwise valuation?

To conduct pairwise valuation, various LLMs are selected for testing, and a custom evaluation prompt is defined. Each model's output is evaluated independently before conducting pairwise comparisons to assess which model performs better based on specific criteria.

  • Select multiple LLMs for comparison in pairwise valuation.
  • Define clear evaluation criteria for assessing model outputs.
  • Run independent evaluations before pairwise comparisons.
# 5:30

Importance of Comparative Evaluation

Why is comparative evaluation important in pairwise valuation?

Comparative evaluation helps to highlight differences between LLM outputs that may not be apparent when evaluated in isolation. It allows for a more nuanced understanding of which outputs are more engaging or effective, particularly when all models score similarly in independent evaluations.

  • Comparative evaluation reveals subtle differences between model outputs.
  • Isolated evaluations may mask performance disparities.
  • Effective criteria are crucial for distinguishing between outputs.
# 8:15

Executing Pairwise Comparisons

How are pairwise comparisons executed and analyzed?

Pairwise comparisons are executed by systematically evaluating different model outputs against each other, ensuring to account for positional effects. The results are logged, showing preferences for one model over another, which can reveal consistent trends in performance despite similar independent scores.

  • Systematic execution of pairwise comparisons is essential.
  • Logging results helps identify consistent preferences among models.
  • Positional effects should be controlled to ensure fair comparisons.
# 11:01

Insights from Pairwise Evaluation Results

What insights can be gained from the results of pairwise evaluations?

Pairwise evaluations can uncover significant preferences between models that are not evident in isolated assessments. For instance, one model may consistently outperform another despite both receiving high independent scores. This highlights the value of comparative analysis in understanding model effectiveness.

  • Pairwise evaluations can reveal significant performance differences.
  • Independent scores may not reflect true comparative performance.
  • Detailed analysis of results can provide insights into model strengths.

Transcript

0:01 hi this is Lance from Lang chain we're attending our Langs meth valuation series talking about pairwise valuations so chapot arena is one of the most popular pairwise valuation benchmarks that's out there and we can kind of use our framework here to to kind of think through what it actually is doing so in that particular case a user prompts two different Anonymous llms with the same prompt and the twms produce generation and in terms of valuat the

0:27 user itself is the evaluator so the user decides which generation he she prefers and picks that one and so it's very simply par wise valuation with human is Judge right you basically on you know log Generations from two different llms which are Anonymous now the LM syst team also showed that you can use llm as judge for pawise valuations as well and they have actually pretty nice repo and they have some prompts here so you can actually

0:56 see them here if you go to data you go to judge prompts you actually they actually have a really nice pairwise evaluation prompt here so you can certainly use llm as judge or human to do pairwise evaluation and we can think of as kind of a variant of AB testing we already talked about regression testing so that's like you're comparing you have a fixed eval set you're comparing different changes to your app over time on this fix eval set we talked about

1:19 back testing and Parise evaluation is comparing you know two generations on the same input and you're encoding something like human preference or other types of criteria in a parse evaluator so let's give an example of this let's say we want to do paper summarization for for example Twitter so I loaded 10 different papers from archive you know very you know typically mostly they they they relate to kind of llms a number of

1:51 papers relate to kind of Contex extension some new models it's kind of a mix of LM related papers I save them as a data set called paper generator so if we go over this data set lives in lsmith here's the example so it's basically just a bunch of papers right if you click on one of these you can see it's a whole bunch of input text that's all it's going on and these are going to be the inputs to our pairwise

2:14 evaluation right so next I'm just going to find a few different chains to do that paper summarization and the main point here is I want to try a few different llms so let's CH let's try anthropic for one so here's my summarization prompt you know distill this this text I.E the paper that we just talked about one of these papers from the eval set it gets plumbed in here summarize it into a tweet you know per these five criteria make an

2:43 engaging title bullet points emojis right you get the idea we're going to use CLA 3 Opus we're going to use Hau then I also use open AI so I'm going to use gbd4 turbo which is you know the latest model 12 28k context and I'm also going to use command R which has I believe like 120,000 token context window as well so these are the four different LMS I'm going to use for my par wise valuation testing so I've

3:12 defined all these and again I'm just using simple functions that are just going to invoke a really simple chain that's just going to be basically my prompt here piped to my model output or parti the output to string and I'm going to be passing in my examples from my eval set which all have this text key you can see when we defi when we built the eval Set we just defined our inputs as text d d being the the the full kind of input

3:42 text from the paper so that's all it's going on pretty simple stuff now here I Define this is where things get a little bit interesting before I think about parse evaluation I just want to run an individual experiment evaluating the quality of my my summaries in isol so I want to evaluate each one independently and here's the evaluator I use so I just Define like a custom evaluation prompt you're grading TW summary tweets for papers you know

4:11 ensure the answer meets this criteria I kind of give the criteria back I say give it a score of five to you know 0o to five five meaning it meets all the criteria and real is an engaging tweet zero meaning it meets another the Criterion is bad right so that's all I do there and then I run those evals so I'm going to run the evals on each of my four models so gbd4 turbo Opus command R

4:33 haou all in my eval set and we can see over here so I've run these and this summary engagement score is what I've logged so that's this thing right so when I run my custom eval I'm saving the key as summary engagement score it's an INT so I can look at the score here now here's where things are kind of interesting I want to draw your attention so you can see the evaluation score for three of these is basically

4:57 five out of five right no differentiation so Opus gbd4 Hau all are scored five out of five in this independent evaluation now you see command R is actually graded a little bit lower so you can kind of you can then dig into the particular runs here if you want and so you can look at each of these runs you can look at the feedback if you'd like so you can actually add you can kind of show the

5:22 eal scores here if you want and so you can kind of see the grades and you know that's kind of a little bit beside the point because we're going to really be focusing on pair wise but I do want to show that when you have a criteria evaluator and isolation looking at text it can be hard to normalize it and to highlight interesting differences between different llms right because basically three out of four all saturated like they look fine in

5:48 isolation so that's just an interesting point to highlight and that's kind of sets the motivation for why par wise can be really helpful now we've kicked out these VLS We've ran all these now here's where I'm going to show you how to do pairwise valuation so we actually don't need this and first I want to show something that's pretty interesting so I created a prompt for pairwise valuation and I drew largely from The lmis Prompt that I showed above

6:21 so that was shown up here right here so they have this nice set of prompts that they have used for llm as judge and parse evaluation I took it I modified it slightly for this particular particular task so I say you're an impartial judge looking at the Quality between two AI assistant outputs begin your evaluation by comparing their responses and here what I do is I find

6:52 that this criteria for judging is very important you have to be very pointed with kind of what you're trying to differentiate and because this is Twitter I want my tweets to be engaging or will that be like viral so I basically say which one is a more engaging title more engaging list of bullets more engaging use of emojis right so I'm trying to kind of differentiate between these Generations which in isolation like we showed all rank high right so you know based on the

7:17 independent independent evaluation Opus turbo ha cou all are kind of five out of five right but this parse valuation I really want to distinguish by comparative evaluation which one really like pops like how do I compare these to one another so that's really what I'm doing here you can see I'm Plumbing in assistant a answer system B answer and I'm asking it to score like I'll put one if it's a two if it's B zero if it's a tie right

7:44 that's all it's going on so go back down that's all I'm doing here I'm sitting at my custom evaluator I I pull in this grade prompt and you can see really all I'm doing is I'm Plumbing in the answer answer a answer B the instructions for the particular task which were actually defined up here in my chains and this is where I map from the grade output to an assignment for each run so basically if you recall

8:13 if the score is one that means assistant a or answer a is preferred so I Mark basically the a is the first so one zero if it's two it's assistant B so 01 otherwise 0 0 so that's all I do here then I basically just simp I can simply input the name of my experiments so if you if you go back over here I have four experiments you can see they're all named right here all I have to do is

8:39 just Plum those names in to my comparative evaluation I plum in the evaluator defined here I plum in the name of my existing experiments which have already been run which you can see here and I kick all these off right so I'm going to compare command R to Opus I'm going to compare Opus to hi cou I'll compare gbd4 to Opus and I'll compare Opus to command R flip the order we just want to make sure that there's no

9:05 positional effect like it's not always picking the first one right so I'm going to kick those off so then what I'm going to do is once you kick those off you're going to see in your data set that there's now these pairwise experiments and you can see now we have this new column called ranked preference which is pretty cool so you actually can see here's the experiments I've run and they're all kind of this is the creation time so

9:29 initially I ran command R versus Opus and what it found is it preferred Opus over command R 7:3 and now recall I also ran Opus command R the reverse order just to make sure there's no positional effect in that case it went a to2 so that's a good thing so that shows you that it prefers Opus relative to command R consistently and of course there is a little bit of noise in the ranking it's eight versus seven so it is important

9:53 thing to note that there's some non-determinism in the way that the grader works but it's fine you certainly see directionally you know which which is preferred now we can also click on these and zoom in so this is pretty nice you actually see a good view of like of you know here's your Opus response here's command R you can really see clearly which one is preferred and why right so that's actually pretty nice now you can even

10:17 zoom in further and you can click here on the evaluator so that spins this up so this is actually looking at the evaluator Trace so you can actually convince yourself like why and in my evaluator prompt I output both the grade the preference and the explanation so this tells you exactly why it graded one over the other so that's another like really convenient thing I like to do so anyway this is pretty cool you can like really zoom in you can see kind of

10:45 why one is ranked over the other now I also want to show you something interesting here when we compare Opus to Haiku it's kind of a tie 50/50 right and you know that's that's fine but what's really and and that's well I would say that's interesting actually because Haiku is a faster and cheaper model so for this particular task I might then say you know what there's really no differentiation I would just go ahead and use haou so that's that's

11:09 actually a good thing now what's also interesting is I see that gbd4 actually does quite a bit better than Opus so in that case it's that you know 10 out of 10 instances prefers gbd4 over Opus and that's actually pretty interesting because both have a score of like five independently so what this telling you is if you just look at one of these in in and try to score it individually the greater kind of gives it a five out of

11:35 five but if you compare them to one another it consistently prefers dpd4 and we can actually again zoom in and look at kind of why that is we can look at the evaluation traces and which is kind of nice here is we this this lets you see this is like the gbd4 output as as assistant a and then assistant B is is Opus and you can kind of see and you can really this will give you a very

11:59 detail explanation as to why I preferred a versus B you know it's more engaging in several aspects it gives you a very detailed breakdown so anyway the key intuition is simply this par wise evaluations can be a really nice way for example if doing like kind of ambiguous tasks like text generation to compare between different generation options different llm options to perform the generation in this particular case what we saw is that if I just simply try to

12:27 Define like a criteria grer to look at them in isolation so you can kind of see here it's hard to discriminate right three out of my five models I'll get a five out of five but if I use the pairwise grader I can see that there's significant preferences between the two when I'm looking at for example turbo head-to-head versus Opus it seems to really blow it away for this particular task now of course you should tune

12:55 and really think about your evaluation prompt and that's probably the hardest part so you can see for this particular task I showed it previously this is what my prompt is and I did have to do some prompt engineering to to really highlight for example engaging is what I want to differentiate on now if I picked a different differentiation criteria maybe the scores would be different so this this prompt matters a lot and you should absolutely play with it you can

13:19 Fork this prompt it's it's just it lives in our promp club and it's public but I do want to mention that you know if you can encode human preference in your greater prompt in a crisp way like we're showing we really want to enforce engagement it can be a really powerful way to do evaluation between different llm options as we see in a task like this thanks

Summary

Lance from LangChain discusses the process of pairwise valuation in evaluating language models (LLMs) using a framework that allows for comparative analysis of AI-generated outputs. He explains how to implement pairwise evaluations, particularly in the context of summarizing academic papers, and emphasizes the importance of crafting effective evaluation prompts to distinguish between model performances.

- Pairwise valuation involves comparing outputs from two anonymous LLMs based on user preferences.
- The evaluation can be conducted by humans or through LLMs acting as judges, utilizing specific prompts for comparison.
- A dataset of academic papers is used to test various LLMs, including Anthropic, OpenAI, and others, for summarization tasks.
- Initial evaluations showed high scores across models, making it challenging to differentiate their performances.
- Pairwise evaluations help reveal subtle differences in model outputs that may not be apparent in isolated assessments.
- The importance of crafting precise evaluation prompts is highlighted, as they can significantly influence the outcomes of the comparisons.
- The results from pairwise evaluations can guide decisions on which model to use based on specific criteria, such as engagement in tweet summaries.
- The process allows for deeper insights into model performance, enabling better choices in LLM applications.

Questions Answered

What is pairwise valuation and how does it work?

Pairwise valuation involves comparing outputs from two different language models (LLMs) based on user preference. Users evaluate which output they prefer, effectively acting as judges in the process. This method can also utilize LLMs as judges, allowing for a structured evaluation of generated content.

How do you set up experiments for pairwise valuation?

To conduct pairwise valuation, various LLMs are selected for testing, and a custom evaluation prompt is defined. Each model's output is evaluated independently before conducting pairwise comparisons to assess which model performs better based on specific criteria.

Why is comparative evaluation important in pairwise valuation?

Comparative evaluation helps to highlight differences between LLM outputs that may not be apparent when evaluated in isolation. It allows for a more nuanced understanding of which outputs are more engaging or effective, particularly when all models score similarly in independent evaluations.

How are pairwise comparisons executed and analyzed?

Pairwise comparisons are executed by systematically evaluating different model outputs against each other, ensuring to account for positional effects. The results are logged, showing preferences for one model over another, which can reveal consistent trends in performance despite similar independent scores.

What insights can be gained from the results of pairwise evaluations?

Pairwise evaluations can uncover significant preferences between models that are not evident in isolated assessments. For instance, one model may consistently outperform another despite both receiving high independent scores. This highlights the value of comparative analysis in understanding model effectiveness.

© transcribe · For agents Built with care and craft by Gokul Rajaram