Backtesting | LangSmith Evaluations - Part 19

LangChain
16 May 202410:05

Summary

TLDRランチェインのLanceが、バックテストに焦点を当てた評価シリーズを紹介しています。プロダクションアプリのログを活用し、新しいアプリのバリアントをテストする方法を説明しています。例えば、ベクターストアを使用する「gbd4 Turbo」アプリを例に、コンテキスト詰め込みを試して比較する方法を紹介しています。ユーザーからの実際の質問をもとに、データセットを作成し、異なるアプリバリアントを評価し、比較評価を行う方法を解説しています。このプロセスは、プロダクションアプリを改善し、新しい機能をテストするのに非常に便利なワークフローです。

Takeaways

  • 🔧 これは「Lang chain」というツールを使用して、アプリのバックテストに関する評価シリーズを紹介するビデオスクリプトです。
  • 🛠️ スクリプトでは、既存のプロダクションログを利用して、新しいアプリのバリアントをテストする方法を説明しています。
  • 📈 「gbd4 Turbo」という特定のRAGアプリについて話しており、これはベクターストアを使用してプロダクションで動作しています。
  • 🔄 「コンテキスト詰め込み」という新しいアプリバリアントをテストする際に、プロダクションログを再利用することができると強調しています。
  • 📝 テストのために、プロダクションからのユーザーデータを直接使用し、データセットとして利用することができると説明されています。
  • 🔧 スクリプトでは、新しいプロジェクト「バックテスト」を作成し、ユーザーからの質問を通してアプリをテストするプロセスを紹介しています。
  • 📑 「バックテスト V2」という新しいデータセットを作成し、ユーザーログをもとにした評価を実行する方法が説明されています。
  • 🔄 新しいアプリバリアント「predict Rag」と「ser gbd4 turbo」を使用して、既存のプロダクションアプリと比較する評価を実行しています。
  • 📊 ペアワイズエバリュエーターを使用して、新しいアプリバリアントとプロダクションアプリの出力を比較評価する方法が紹介されています。
  • 📝 スクリプトでは、コードの質問に対する回答の品質を評価するための基準を設定し、評価プロンプトを作成する方法も説明されています。
  • 🔎 最後に、新しいアプリバリアントとプロダクションアプリの比較評価を行い、どちらが優れているかを詳細に分析しています。

Q & A

  • ランチェインのバックテストとはどのようなプロセスですか?

    -ランチェインのバックテストとは、既存のアプリのバージョンが収集したユーザーデータを使用して、新しいアプリのバリアントを実行し、その出力を比較するプロセスです。これは、異なるバリアントを試してアプリを改善するのに非常に便利な方法です。

  • なぜバックテストはアプリ開発において重要な役割を果たしますか?

    -バックテストは、既存のアプリのパフォーマンスを評価し、新しいバージョンが改善点を提供しているかどうかを判断するのに役立ちます。これにより、開発者はより良いユーザーエクスペリエンスを提供するためにアプリを最適化できます。

  • ランチェインのフレームワークにおけるデータセットとは何を意味しますか?

    -ランチェインのフレームワークにおけるデータセットとは、実際のユーザーデータから収集されたログを指します。これらは、新しいアプリのバリアントをテストする際に使用されるデータセットとして活用されます。

  • 新しいアプリバリアントをテストする際に、どのようにしてユーザーデータをデータセットに変換するのですか?

    -ユーザーデータは、ランチェインのフレームワークで提供される特定のコードを使用して、新しいデータセットに変換されます。これにより、ユーザーの入力がデータセットの入力として使用され、新しいアプリバリアントをテストすることができます。

  • バックテストで使用する新しいアプリバリアントの例として、コンテキストスティッキングとは何ですか?

    -コンテキストスティッキングは、ベクターストアを使用する代わりに、すべてのドキュメントをLLMに渡す方法です。これにより、正しいドキュメントチャンクのリトリーブに関する問題が回避され、すべての情報が一度に提供されます。

  • バックテストの結果を比較するために使用される対比評価とは何ですか?

    -対比評価は、2つの異なるアプリバリアントの出力を比較し、どちらが基準に基づいて優れているかを判断するプロセスです。これは、新しいバリアントが現在のプロダクションバージョンよりも優れているかどうかを判断するのに役立ちます。

  • ランチェインフレームワークで新しいプロジェクトを作成する際に、どのようにしてプロジェクトを識別するのですか?

    -新しいプロジェクトは、名前とバージョン番号を使用して識別されます。例えば、「バックテスト V2」のように、プロジェクト名とバージョン番号を組み合わせて一意のプロジェクトを作成します。

  • バックテスト中にランチェインフレームワークで実行された評価とはどのようなものですか?

    -バックテスト中に実行された評価は、新しいアプリバリアントのパフォーマンスを測定し、特定の基準に基づいてそのパフォーマンスを評価します。これは、新しいバリアントが期待通りに機能しているかを確認するのに役立ちます。

  • バックテストのプロセスで、どのようにして生産性向上に貢献するのですか?

    -バックテストは、既存のユーザーデータを再利用することで、新しいアプリバリアントを迅速にテストし、改善することができます。これにより、開発者は時間を節約し、より迅速にアプリを最適化してユーザーに提供できます。

  • バックテストを使用して、どのようにしてアプリの品質を向上させるのですか?

    -バックテストを使用して、新しいアプリバリアントを実際のユーザーデータでテストし、そのパフォーマンスを比較評価します。これにより、アプリの品質向上に必要な具体的な改善点を見つけ出し、実装することができます。

  • バックテストの結果を分析する際に、どのような基準を使用するのですか?

    -バックテストの結果を分析する際には、コードの答えが問題のクリアオーバービューを含んでいるか、コードのインポートや解決策が含まれているかなどの基準を使用します。これにより、どのバリアントがより優れた結果を提供しているかを判断できます。

Outlines

00:00

🔍 バックテストのプロセスと目的

ランスは、Lang chainの評価シリーズを続け、バックテストに焦点を当てています。彼らのプロダクションアプリ、gbd4 Turboを使用してベクターストアを利用していますが、新しいバリアントを試すために、既存のプロダクションログを利用してテストすることができます。これにより、新しいアプリバリアントを既存のユーザーデータでテストし、出力を比較することができます。このプロセスにより、新しいアプリバリアントを効率的に評価することができます。

05:00

📈 バックテストによるアプリバリアントの比較

ランスは、プロダクションログから新しいデータセットを作成し、それを使用して新しいアプリバリアントをテストしました。彼は、gbd4 Turboという新しいバリアントを使用して、コンテキストの詰め込みを行っており、ベクターストアを使用する基本バージョンとは異なるアプローチをとっています。その後、新しいペアワイズ評価プロンプトを作成し、生産バージョンと新しいバリアントの出力を比較しました。評価結果は、新しいバリアントの方が優れていると示しました。

10:02

🙌 バックテストの利点とプロセスの概要

ランスは、プロダクションで動作しているアプリのログを取得し、それらをデータセットに変換することで、バックテストを行うことができます。これにより、異なるバリアントをテストし、プロダクションに投入する前に比較的簡単に比較評価を行うことができます。このプロセスは、プロダクションで動作しているアプリケーションに対して新しいバリアントをテストする際に非常に便利です。

Mindmap

Keywords

💡Lang chain

「Lang chain」とは、言語モデルや関連技術を活用したツールやアプリケーションを開発するためのフレームワークのことで、ビデオではこれに基づいてアプリケーションのバックテストを行うプロセスが紹介されています。ビデオの中では、Lang chainを使用して開発されたアプリケーションを評価し、改善する手法について説明しています。

💡バックテスト

バックテストとは、既存のアプリケーションやシステムに対して新しいアルゴリズムや変種を適用し、そのパフォーマンスを比較評価するプロセスのことです。ビデオでは、既存のプロダクションログを利用して新しいアプリケーション変種のパフォーマンスをテストし、比較評価する手順が説明されています。

💡プロダクションログ

プロダクションログとは、実際の運用環境で収集されたユーザーの行動データやシステムのログ情報のことを指します。ビデオでは、これらのログをもとに新しいアプリケーション変種をテストし、その結果を評価するプロセスが紹介されています。

💡データセット

データセットとは、分析やテストに使用されるデータの集まりです。ビデオでは、プロダクションログからデータを抽出し、新しいデータセットを作成することで、バックテストを行う際の入力値として使用しています。

💡アプリケーション変種

アプリケーション変種とは、既存のアプリケーションに対して行われた変更や改良を含むバージョンのことです。ビデオでは、ベクターストアを使用するのではなく、コンテキスト詰め込みを使用した新しいアプリケーション変種をテストする例が紹介されています。

💡コンテキスト詰め込み

コンテキスト詰め込みとは、モデルに必要な情報をすべて含む方法であり、ビデオでは、これはベクターストアを使用する代わりの手法として紹介されています。この手法は、ドキュメントの正しいチャンクを検索する問題を回避する利点があります。

💡ペアワイズエバリュエーター

ペアワイズエバリュエーターとは、2つの結果を比較し、評価するツールです。ビデオでは、プロダクションベースラインと新しいアプリケーション変種の出力を比較し、どちらが優れているかを判断するのに使用されています。

💡コード質問応答

コード質問応答とは、ユーザーからのコードに関する質問に答えることを意味します。ビデオでは、Lang expression languageに関する質問に対して、新しいアプリケーション変種とベースラインのどちらがより良い回答を提供するかを比較評価しています。

💡エクスペリメント

エクスペリメントとは、特定の目的で行われるテストや実験のことです。ビデオでは、新しいアプリケーション変種をテストし、その結果を評価するプロセスをエクスペリメントと呼称しており、その結果をもとに比較評価が行われています。

💡比較評価

比較評価とは、2つ以上の結果やパフォーマンスを比べ、どちらが優れているかを判断するプロセスです。ビデオでは、プロダクションベースラインと新しいアプリケーション変種の出力を比較評価し、どちらがより良い結果を出すかを判断しています。

Highlights

Lance from Lang chain discusses back testing different app variants using production logs.

Motivation for back testing involves trying a new variant like context stuffing instead of using a vector store.

Production logs can be utilized to create a dataset for testing without needing a curated dataset.

Back testing allows for the comparison of new app variants against the current production version.

Lance creates a new project called 'back testing' to evaluate the new app variant.

User interactions with the app are simulated and used to generate a dataset for testing.

Traces from the app are taken and turned into a new dataset for evaluating the app variant.

A new experiment is initiated using a different app variant without a vector store.

The new experiment is named 'predict Rag and ser gbd4 turbo' which uses context stuffing.

The initial experiment serves as the production baseline for comparison.

A pairwise evaluator is used to compare the outputs of the baseline and the new variant.

Criteria for evaluation include clarity, code import, and code solution.

The pairwise evaluation provides a detailed comparison and preference between the two app versions.

The workflow allows for easy back testing of production apps with different variants.

Back testing can be highly convenient for testing different chains before putting them into production.

The process concludes with a comparative assessment using the pairwise evaluator.

Transcripts

play00:01

hi this is Lance from Lang chain we're

play00:02

continuing our Langs Smith evaluation

play00:04

series focused on back testing today so

play00:07

to to motivate this let's say we had an

play00:09

app in production uh say for example

play00:11

it's one of our rag apps that we kind of

play00:13

talked about in some prior videos um and

play00:17

the particular rag app uh in our case is

play00:19

gbd4 Turbo using a vector store so

play00:22

that's in production we're collecting

play00:23

production traffic from users based

play00:25

using this app version now what happens

play00:28

if we want to try different variant like

play00:30

let's say I want to try context stuffing

play00:31

rather than using my Vector store um one

play00:35

really convenient and nice thing to be

play00:36

able to do there is take a bunch of

play00:38

production logs we've already collected

play00:40

and just run my new app variant on them

play00:42

and see how the output Compares right

play00:44

that's a really common thing you might

play00:45

want to do so if you look at our

play00:47

framework here we're talking about the

play00:49

data set actually can come from existing

play00:50

production logs that's really convenient

play00:52

we don't have to build some like curated

play00:54

data set from it we can just take user

play00:56

data that actually has been you know

play00:58

contributed to our existing app and turn

play01:00

that into a data set so that's step one

play01:03

and we can test then a different app

play01:06

variant on those same inputs so that's

play01:08

really useful and we can use like a

play01:10

pairwise evaluator compare our new

play01:13

variant of the app to our old or

play01:16

production version that's running

play01:17

currently so that's like a common

play01:18

workflow now let's walk through this so

play01:20

I'm going to create a new project I'll

play01:22

call it back testing I'll create a a new

play01:24

one here back testing let's say

play01:26

V2 um and here's my app so let's say

play01:28

this is running a production here here's

play01:30

a few user questions related to L chain

play01:32

expression language so if you call this

play01:34

particular app um is actually ingesting

play01:38

information about Lang and expression

play01:40

language and um so these are all running

play01:44

cool so we can just kick a few of these

play01:45

off um

play02:08

great so I've run five different uh user

play02:12

questions uh through my app now assume

play02:15

this is you know obviously we're doing

play02:16

the notebook but assume this is a

play02:17

production app it's it's just out there

play02:19

these are users interacting with your

play02:21

app right so that's what we're

play02:22

simulating here now I've created this

play02:24

project back testing V2 we can go over

play02:26

to limith um I can look at my projects

play02:30

page and it's here and so great so

play02:34

here's all my traces they're all logged

play02:36

here so that's

play02:37

fantastic um now what I can do is this

play02:42

code right here will take these traces

play02:44

so I can specify my like my my run

play02:47

filters in terms of like start and end

play02:49

time um and I can choose the project

play02:53

that I want to grab from so in this case

play02:54

it's this project we just logged to and

play02:57

basically what we can do here is I can

play02:58

create a new data set so I'm taking

play03:00

these user logs effectively right here

play03:03

and what I'm do is I'm turning them into

play03:05

a new data set so now we'll see if you

play03:07

go over to our data sets page we have

play03:09

this new data set called backing V2 and

play03:11

it has like the exact time and so forth

play03:14

and what you'll see here is pretty nice

play03:16

um those user inputs are now just simply

play03:19

inputs in my data set so I've kind of

play03:21

sucked them into a data set that's all

play03:22

I've done now what I can do here is I

play03:26

can run an evaluation on the states that

play03:28

we just created using a different Vari

play03:29

into my app so I'll call this this

play03:31

predict Rag and ser gbd4 turbo is a

play03:34

different app variant this particular

play03:36

variant doesn't use a vector store it

play03:38

does context stuffing um which we can

play03:40

talk about a little bit later but let's

play03:41

say kick off that evaluation so I run

play03:44

that right now so if I can I can go back

play03:46

to my data set here we can see a new

play03:48

experiment has been kicked off and

play03:50

what's pretty cool about this when I

play03:51

create this data set my initial

play03:53

experiment is the prod Baseline so

play03:55

that's basically my production app that

play03:57

we've been using that we logged from um

play04:00

and that is actually what we collected

play04:01

our our inputs and our outputs initially

play04:04

from so this is kind of like our

play04:05

Baseline right this is our inputs these

play04:07

are outputs from that Baseline version

play04:09

we looked at initially now I've just run

play04:12

a new experiment using our variant right

play04:14

so this a gp4 turbo so it's what I just

play04:16

kicked off and this is running now you

play04:17

can see it's still

play04:19

running um you can see kind of the name

play04:21

here my experiment prefix gp4 turbo and

play04:25

that is what uh you can see here so gb4

play04:30

turbo that's great so that's all

play04:32

running and we can check and see the

play04:35

state of that experiment looks like it's

play04:36

still

play04:37

going um cool so there's one more to

play04:42

go and it looks like it's done so that's

play04:45

great so now we are finished so here's

play04:49

where things get kind of interesting so

play04:51

I've run so maybe just back up what do

play04:54

we do here so if I go all the way back

play04:57

first I had a project that I was logging

play05:00

to so this is simulating um for example

play05:03

like a a production app and these are

play05:05

user user interactions that are being

play05:07

logged to some particular project what

play05:08

I've done is I've taken these these

play05:11

these input and output Pairs and I've

play05:13

pulled them into a new data set and you

play05:15

can see that right here I suck those in

play05:18

and by default when I do that that

play05:20

Baseline is grabbed as my prod Baseline

play05:23

so this is what my production app inputs

play05:25

and outputs now what's cool is I was

play05:28

able to just run a new experiment with

play05:30

my new app version on those same user

play05:32

inputs but now I have my new output so

play05:34

these are the outputs for my new chain

play05:35

so that's great now this all comes

play05:38

together in kind of a cool way because I

play05:39

can use a pairwise evaluator to compare

play05:41

them so I just created a new pairwise

play05:44

evaluation prompt for this particular

play05:46

task and I I think I already have it

play05:48

open here great so this particular task

play05:51

if you recall is code question answering

play05:53

based on the Lang expression language

play05:55

documentation so I set up my pawise

play05:57

prompt and I just say you know previous

play05:58

act as a judge to evaluate the quality

play06:00

of of code responses from two assistants

play06:03

um related to Lang Str language I give

play06:05

my criteria here begin your evaluation

play06:07

comparing the responses based upon do

play06:09

they contain a clear overview of the

play06:11

problem do they contain code import they

play06:13

contain code solution right um so you

play06:17

don't allow length to affect the results

play06:19

and so forth so anyway that's my

play06:22

evaluation prompt now I've I can Define

play06:25

this pairwise Valor we just already

play06:27

talked about this in the last video so

play06:29

you've already seen a good example of

play06:30

that I'm creating a pawise evaluator

play06:32

right here and what's pretty cool is I

play06:35

can run that pawise evaluator on my two

play06:37

experiment so this is my this is the

play06:39

name of my most recent experiment it's

play06:41

gp4 turbo boom and my initial experiment

play06:45

I can go back and get that name so it's

play06:48

this prod Baseline so I can just plug

play06:50

those

play06:52

in

play06:54

okay so I'm running a comparative

play06:57

evaluation between my prod Baseline and

play07:00

my new app variant that I ran back

play07:01

testing on I kick that off so now this

play07:04

is running and of course it's going to

play07:06

be logged to the same overall uh data

play07:09

set here so if I go back to my data set

play07:12

recall we had two experiments my prod

play07:14

Baseline my back testing which is

play07:16

running those same prod inputs with my

play07:18

new chain gp4 Turbo with context

play07:21

stuffing um and now I've kicked off an

play07:25

experiment that's comparing the two so

play07:27

it's comparing my prod Baseline versus

play07:29

my new variant gbd4 Turbo with context

play07:31

stuffing versus the the Baseline if you

play07:33

recall is actually using retrieval from

play07:35

a vector store um the varant is actually

play07:38

using gbd4 uh Turbo with context

play07:42

stuffing the entire lell docs into the

play07:45

um into the llm which has some benefits

play07:47

over retrieval because uh you don't have

play07:49

issues related to retrieval of the

play07:51

correct document chunks uh you're just

play07:54

passing in everything and so there's

play07:55

some benefits there that we could talk

play07:57

about at length uh different time so

play08:00

this is running and it looks like it

play08:03

might be finished this is done and this

play08:05

is pretty cool so I can go I can go here

play08:07

I can look at here's all the inputs here

play08:09

was my prod Baseline here is my variant

play08:13

this is what I ran back testing on and

play08:15

what's pretty neat about the pair wise

play08:16

value we can really see the preference

play08:18

and so in this particular case it

play08:19

prefers the output from our variant over

play08:22

the Baseline and again just as we saw in

play08:25

the previous video we can actually click

play08:26

into here and investigate why so you can

play08:29

go to the evaluator and it actually

play08:31

gives you an explanation as to why so

play08:33

anyway you can really dig into this but

play08:35

this is a pretty nice workflow so if we

play08:36

Zoom all the way back out what did we

play08:38

really do here uh well we had an

play08:42

example of an app running in production

play08:47

this is kind of simulation of that we

play08:48

collected five user inputs we turned

play08:51

those into a data set that's what we did

play08:53

here we then ran what we call back

play08:55

testing on that data set with a new app

play08:58

variant so like I want to test the new

play08:59

app version in this case my Baseline

play09:01

used retrieval from a vector store my

play09:04

new app variant used context stuffing so

play09:07

I ran that uh

play09:10

evaluation and then I so then that that

play09:12

resulted in a

play09:14

generation um so that's right here for

play09:16

every input I produced a new generation

play09:19

or output from my variant that's great

play09:21

and then I ran this comparative eval

play09:23

saying hey which one's better here's my

play09:25

prompt and I kicked that off I just

play09:28

added the names of the two experiments

play09:30

and as we saw before you get this pretty

play09:32

nice comparative assessment with

play09:34

detailed evaluation so pretty useful

play09:37

thing to do if you have any app running

play09:38

in production you can pretty easily grab

play09:40

those production logs turn them into a

play09:42

data set do back testing on them with

play09:44

like different variants different chains

play09:46

you want to test and you can even do

play09:47

things like pairwise evaluation to say

play09:49

hey which one's better or worse based on

play09:51

some criteria that I can Define so

play09:53

really nice workflow highly convenient

play09:55

um for um kind of testing at testing

play09:59

different variants of of chains that you

play10:01

want to do you want to put in production

play10:03

thanks

Rate This

5.0 / 5 (0 votes)

Related Tags
バックテストプロダクションアプリ比較評価データセットAIコード質問言語ベクターストアコンテキスト
Do you need a summary in English?