見出し画像

【Chat GPTのファインチューニング: 手順と費用】英語解説を日本語で読む【2023年8月23日|@Prompt Engineering】

この動画は、Chat GPTを自分のデータセットで微調整する方法について詳細に解説しています。微調整により、モデルの安定性、指示に従う能力、出力のカスタマイズが向上し、APIの呼び出し速度を上げ、コストを削減できます。動画では、微調整のコスト、手順、および注意点についても説明しており、特に、微調整したGPT 3.5 Turboモデルは通常のモデルよりも高価で、その価格上昇がパフォーマンス向上に見合うかは不明であると指摘しています。
公開日:2023年8月23日
※動画を再生してから読むのがオススメです。


So, this is huge.

これはとても大きなことです。

Starting today, you can fine-tune ChatGPT on your own data sets.

今日から、自分のデータセットでChatGPTを微調整できる。

It's something that people have been waiting for for a while.

それは人々がしばらく待ち望んでいたものです。

In this video, we'll see what benefits you can get when you fine-tune ChatGPT on your own data set.

このビデオでは、自分のデータセットでChatGPTを微調整することで、どのようなメリットが得られるかを見ていきます。

We will also look at the pricing structure, and I'll walk you through a code example of how you can fine-tune a model on your own data set.

また、料金体系や、ご自身のデータセットでどのようにモデルを微調整できるのか、コード例を通してご紹介します。

And at the end of the video, we will also explore why it may not be a good option for most of the people.

そしてビデオの最後には、ほとんどの人にとって良い選択肢ではない理由も探ります。

So, what exactly do you get with fine-tuning?

では、ファインチューニングによって何が得られるのでしょうか?

When you fine-tune a model, you will get improved stability, which basically means the model will be able to follow instructions better.

モデルを微調整すると、改善された安定性が得られます。これは基本的に、モデルがより良い指示に従うことができることを意味します。

You will also get reliable output formatting, so basically the model will stick to the output format in which you want the output to be.

また、信頼性の高い出力フォーマットも得られます。基本的にモデルは、あなたが望む出力フォーマットに忠実です。

And with fine-tuning, you will be able to customize the tone of the model.

また、微調整により、モデルのトーンをカスタマイズすることができる。

A few things that they have highlighted in their blog post: first, when you fine-tune a model, you will be able to use shorter prompts to get better performance.

まず、モデルを微調整する場合、より良いパフォーマンスを得るために、より短いプロンプトを使用することができる。

Also, compared to GPT-3, the GPT-3.5 can handle 4000 tokens, and from their test, it seems like you can reduce the prompt size by up to 90 percent by fine-tuning instructions into the model itself, thus speeding up the API calls and cutting costs.

また、GPT-3と比較して、GPT-3.5は4000トークンを扱うことができます。彼らのテストによると、モデル自体に命令を微調整することによって、プロンプトのサイズを最大90%削減することができるようです。

Now, the beauty is when you combine fine-tuning with other approaches such as prompt engineering, information retrieval, and function calling.

ファインチューニングを、プロンプト・エンジニアリング、情報検索、関数呼び出しといった他のアプローチと組み合わせたときこそ、素晴らしいものになる。

That's what makes these LLMs a lot more powerful.

それこそが、これらのLLMをより強力なものにしているのだ。

Next, before looking at a fine-tuning example, let's look at the pricing.

次に、ファインチューニングの例を見る前に、価格設定を見てみよう。

Now, they have divided the pricing into two different parts: one is the initial training cost, and the second portion is the usage cost.

今、価格は2つの異なる部分に分けられています。1つは初期のトレーニングコストであり、2つ目は使用コストです。

So, for training, it's going to cost you 0.008 dollars per thousand tokens.

つまり、トレーニングには1000トークンあたり0.008ドルかかります。

Now, for input prompts, it's going to cost you 0.012 dollars per thousand tokens.

入力プロンプトには、1,000トークンあたり0.012ドルかかります。

And for the output usage, it's going to cost you around 0.016 dollars per thousand tokens.

そして、アウトプットの使用には、1,000トークンあたり0.016ドルかかる。

So, at the end, they have provided a very simplified example.

最後に、彼らは非常に単純化した例を提示しています。

For example, if you have a training job that's around 100,000 tokens, that will cost you around 2.4 dollars to train the model.

例えば、100,000トークン程度のトレーニングが必要な場合、モデルのトレーニングにかかるコストは約2.4ドルです。

Now, we're going to come back to this pricing again at the end of the video because there is a lot to unpack here.

今、この価格について再び話を戻します。ここには解説するべきことがたくさんあります。

Now, let's look at how exactly you can do the fine-tuning.

では、具体的にどのように微調整ができるのかを見てみましょう。

So, in the blog post, they have provided this schema.

ブログ記事では、このようなスキーマを提供している。

First, you need to prepare your data set, and the data set is supposed to have a system message, then input from the user, then response from the assistant.

まず、データセットを準備する必要があります。データセットには、システムメッセージ、ユーザーからの入力、アシスタントからの応答があるはずです。

That's how your data set is supposed to look like.

それがデータセットがどのように見えるべきかです。

Then, you can make an API call to OpenAI to upload the files, then create a training job through an API.

そして、OpenAIにAPIコールをしてファイルをアップロードし、APIを通じてトレーニングジョブを作成します。

And then you can reuse the model through an API as well.

そして、APIを通してモデルを再利用することもできます。

But we are going to look at a more concrete python example.

しかし、より具体的なPythonの例を見てみましょう。

So OpenAI has a very nice fine-tuning guide on their website.

OpenAIのウェブサイトには、とても素晴らしい微調整ガイドがあります。

So here they give you the reasons of why you would want to fine-tune.

ここでは、なぜ微調整を行いたいのか、その理由を説明しています。

For example, a fine-tuning will result in higher quality results than prompting ability, to train on more examples than you can fit in a single prompt, and token savings due to shorter problems and lower latency.

例えば、ファインチューニングを行うことで、プロンプトの能力よりも質の高い結果が得られること、1回のプロンプトで収まるよりも多くの例でトレーニングできること、問題が短くなりレイテンシが減ることでトークンを節約できることなどが挙げられます。

Right, it's a very detailed guide and I would recommend everybody to go over this if you are really trying to understand fine-tuning OpenAI models.

OpenAIモデルのファインチューニングを本当に理解しようとするなら、このガイドに目を通すことをお勧めします。

But let's say if you want to fine-tune the model on your own data set, first you need to put your data in a proper format.

しかし、自分のデータセットでモデルを微調整したい場合、まずデータを適切なフォーマットにする必要があります。

So for that, your data is supposed to have three different fields or roles.

そのために、データには3つの異なるフィールドやロールが必要です。

So the first one is system message.

最初のフィールドはシステムメッセージです。

Uh, then and so that's basically the system message that we are providing to the model.

それは基本的に、モデルに提供されるシステムメッセージです。

Then the user input.

次にユーザー入力です。

So here we are defining the role as user and the content is the input prompt from the user.

ここではロールをユーザーと定義し、内容はユーザーからの入力プロンプトです。

And then you're going to have response from the assistant.

そして、アシスタントからの応答が得られます。

Right, so basically you will arrange all your examples in a simple JSON file and that JSON file is going to be used by the model for training.

基本的には、すべての例をシンプルなJSONファイルに配置し、そのJSONファイルをモデルがトレーニングに使用します。

Now once your data is in the proper format, you need to upload the JSON file that you just created to OpenAI API.

データが適切な形式になったら、作成したJSONファイルをOpenAI APIにアップロードする必要があります。

Now once you're able to create your data set, the next step is going to be to upload your data set to OpenAI.

データセットが作成できたら、次はデータセットをOpenAIにアップロードします。

So for that, we're going to be using the Python code.

そのためにPythonのコードを使います。

This is the OpenAI API package.

これはOpenAIのAPIパッケージです。

Then you will provide the file name.

その後、ファイル名を指定します。

So let's assume the data is stored within this mydata.json file.

データはこのmydata.jsonファイルに保存されているとします。

And then you provide the purpose.

そして目的を指定します。

So in this specific case, we want to fine-tune our model.

このケースでは、モデルを微調整したいのです。

Now after doing this, we need to simply start the fine-tuning job.

これを行った後、単純に微調整ジョブを開始する必要があります。

And for that, we need to provide our OpenAI API key.

そのためには、OpenAIのAPIキーを提供する必要がある。

Then you simply make a call to the fine-tune job.

そして、微調整ジョブを呼び出すだけです。

This will create a job and it will start fine-tuning.

これでジョブが作成され、微調整が開始されます。

Now you need to provide two additional inputs.

ここで、さらに2つの入力を提供する必要がある。

First is going to be the training file.

1つ目はトレーニング・ファイルです。

This is basically the model name that's going to be used for the trained model.

これはトレーニングされたモデルに使用されるモデル名です。

And then you need to provide the name of the base model.

そしてベースモデルの名前を入力する必要があります。

So if you want to fine-tune GPT-3.5 turbo, you need to provide that name in here.

GPT-3.5ターボを微調整したい場合は、ここにその名前を入力する必要があります。

What happens when you fine-tune the model and you want to use it?

モデルを微調整して、それを使いたい場合はどうするのですか?

It's as simple as using the chat completion API from OpenAI.

OpenAIのチャット補完APIを使うのと同じくらい簡単だ。

So here you simply need to provide the model name that you assign to your fine-tune model, then the system message.

ここでは、微調整モデルに割り当てるモデル名と、システムメッセージを指定するだけです。

And then, the user input and you will get the assistant response or the model response as output.

そして、ユーザが入力すると、アシスタントの応答やモデルの応答が出力されます。

So, this is very simple to fine-tune GPT-3.5 using the OpenAI API.

このように、OpenAI APIを使ったGPT-3.5の微調整はとても簡単です。

I'm going to create a more detailed video on how to fine-tune this on your own data set.

自分のデータセットでこれを微調整する方法について、より詳細なビデオを作成するつもりです。

We are going to look at how to structure the data set, and then we'll make the API call to get a fine-tuned model.

データセットをどのように構成するかを見て、それからAPIコールを行い、微調整されたモデルを取得します。

So, stay tuned for that video.

そのビデオにご期待ください。

Now, let's look at some not so great things which might deter some people from using this service.

さて、このサービスを使うのをためらう人がいるかもしれない、あまり良くない点を見てみよう。

Okay, so the first one is the safety feature.

では、最初のものは安全機能です。

Your training data is passed through their moderation API and then a GPT4-powered moderation system to detect unsafe training data that conflicts with the safety standards of OpenAI.

あなたのトレーニングデータは、OpenAIの安全基準に抵触する安全でないトレーニングデータを検出するために、GPT4が搭載されたモデレーションシステムとモデレーションAPIを通過します。

So, basically, you are limited by the standards of data.

つまり、基本的にはデータの基準によって制限されます。

Now, the second thing to consider is the price itself because the fine-tuned GPT-3.5 turbo model is a lot more expensive compared to the vanilla GPT-3.5 turbo model.

次に考慮するべきことは価格そのものです。微調整されたGPT-3.5ターボモデルは、バニラのGPT-3.5ターボモデルと比べてはるかに高価です。

Just as an example, for input tokens, it's about eight times more expensive compared to if you're using the 4K context window GPT-3.5 turbo model.

例として、入力トークンの場合、4Kコンテキスト・ウィンドウGPT-3.5ターボ・モデルを使用する場合と比べて約8倍高くなります。

Now, for the output tokens, it's about 5.3 times more expensive compared to the original 3.5.

さて、出力トークンについては、オリジナルの3.5と比較して約5.3倍です。

Now, compared to GPT4, it's still less expensive, but probably the performance is not going to be as great as GPT4.

GPT4と比較すると、まだ安価ですが、おそらく性能はGPT4には及ばないでしょう。

So, if you're fine-tuning a model, you really need to consider this substantial increase in price.

ですから、モデルを微調整する場合は、この大幅な価格上昇を考慮する必要があります。

It's a very interesting development, and it will be interesting to see what people can make on top of it.

非常に興味深い開発であり、その上で人々がどんなものを作れるのか興味深い。

Although, we'll still have to see whether it can actually give a performance boost in your applications or not, and is that performance boost worth the substantially increased price?

とはいえ、あなたのアプリケーションで実際に性能アップが可能かどうか、そしてその性能アップは大幅な価格アップに見合うものなのかどうかは、まだ見極める必要があるだろう。

Let me know what you think in the comment section below.

下のコメント欄で意見を聞かせてほしい。

I will be making a more detailed video on how to fine-tune this model on your own data set.

あなた自身のデータセットでこのモデルを微調整する方法について、より詳細なビデオを作成する予定です。

If you found the content useful, consider liking the video and subscribe to the channel.

もしこのコンテンツが役に立ったら、「いいね!」とチャンネル登録をお願いします。

Thanks for watching and see you in the next one.

ご視聴いただきありがとうございました。次回をお楽しみに。

この記事が気に入ったらサポートをしてみませんか?