背景や目的
・以前の記事では、Gpt-3.5-Turboでの追加学習のLLM精度を確認しました。
・今回は、7月のGpt-4o-miniの発表を受けて、いよいよ追加学習が使えるレベルになったかも!と期待しつつ、追加学習を試してみました。
Gpt-4o-mini を追加学習する事はできません?
・前回と同様にGoogle Colaboノートブックを使用しました。
・Colaboで以下のコードを書いて実行しました。
!pip install --upgrade openai
### ドライブをマウントしておく
from google.colab import drive
drive.mount('/content/drive')
・使用するトレーニング ファイルは、以前Gpt-3.5-Turbo でファインチューニングした時と同じファイルを使いました。架空人物のプロフィールです。

・トレーニングファイルをOpenAIへアップします。
###学習データのアップ
from openai import OpenAI
client = OpenAI(api_key = "sk-**************")
client.files.create(
file=open("/content/drive/Shareddrives/先進技術開発研究チーム/生成AI研究/自動応答システムプロトタイプ1/独自データ作成実験用データ/train_data.json", "rb"),
purpose='fine-tune'
)
・ファインチューニングJOBを開始します。
###アップしたデータでファインチューニング
from openai import OpenAI
client = OpenAI(api_key = "sk-****************")
client.fine_tuning.jobs.create(
training_file="file-**************",
#model="gpt-3.5-turbo-0125" #前回記事の実験モデル
model="gpt-4o-mini-2024-07-18" #今回試すモデル
)・上記コードを実行後、ファインチューニングJOB開始後、「validating_files」まで進みましたが「Status: Failed」が表示されました(OpenAIコンソールで確認)。

・ファインチューニングJOBログのエラーメッセージは以下の通りです。

・エラーの原因は、ファイルが無効で、何かに違反しているようです。
違反箇所等の詳細な情報が無く、手がかりはviolate OpenAI’s usage policies しかありません。
・学習ファイルの書式(JSON)が変わったのかと思い、OpenAIのファインチューニング手順をみたら、以前 GPT-3.5-Turbo ファインチューニングで使用した形式と同じです。変更無しです!
補足)OpenAIファインチューニングのJSON形式例では、RoleのSystem、User、Assistantで、それぞれ情報を持っています。詳細は過去の記事ご参照ください(→過去記事)。
{"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "What's the capital of France?"}, {"role": "assistant", "content": "Paris, as if everyone doesn't know that already."}]}
{"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "Who wrote 'Romeo and Juliet'?"}, {"role": "assistant", "content": "Oh, just some guy named William Shakespeare. Ever heard of him?"}]}
{"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "How far is the Moon from Earth?"}, {"role": "assistant", "content": "Around 384,400 kilometers. Give or take a few, like that really matters."}]}・念のため、OpenAI 追加学習GUI を使用して再度ファインチューニングを試みました。
追加学習GUIはOpenAI APIダッシュボードで「Fine-Tuning」で「+Create」から利用できます。


・ベースモデルを「gpt-4o-mini-2024-07-18」を選択し、同じトレーニング ファイルを選択して、残りの設定をデフォルトのままにしてファインチューニングジョブを実行しました。結果は同じNGでした。
・OpenAIのDeveloper Forumで、他の方も同じ経験されていましたが、解決されていませんでした。(→OpenAI Developer Forum)

・他では、7月24日付けのOpenAI公式アカウント:「@OpenAIDevs」からの以下の投稿を「X(旧:Twitter)」を見つけました。

・気になるのは「Tier 4 and 5 users」です。
・Tierとは、Openaiが以下の基準に基づいてユーザーを分類する使用tiersを意味します。

・現在、Tier 4 または 5 ではないため、Gpt-4o-miniのファインチューニングがブロックされている?
・しかし、OpenAIのファインチューニング画面とAPIドキュメントではこれについて書いてない。うーん。
・確認のため、OpenAIの「Help」を参照して、以下の質問を出した。
質問:
Hello!
A few days ago i tried fine-tuning with gpt-4o-mini-2024-07-18 and faced an error during the training file validation and faced a job failure for the first time.
The job failed due to an invalid training file.
The error message is as below:
This training file was blocked by our moderation system because it contains too many examples that violate OpenAI’s usage policies, or because it attempts to create model outputs that violate OpenAI’s usage policies.
15:33:44
Validating training file: file-**********
15:33:44
Created fine-tuning job: ftjob-***********
Please note that the training file that i am using is the same one i have previously used successfully for fine tuning gpt-3.5-turbo-0613&0125.
Would really appreciate what could have gone wrong as the format checker also passed with no errors.

・ボットが返信し、OpenAI からの応答は以下の通りです。
答え:
Hello,
Thank you for reaching out to OpenAI support.
It sounds like you’re encountering an issue with the moderation system while trying to fine-tune the `gpt-4o-mini-2024-07-18` model and we are here to help. Even though your training file worked previously with `gpt-3.5-turbo-0613` and `gpt-3.5-turbo-0125`, the `gpt-4o-mini` model might have stricter or different moderation criteria.
Here are a few steps you can take to troubleshoot and resolve this issue:
1. Review the Content: Ensure that the content of your training file adheres to OpenAI’s usage policies. The policies might have been updated or the new model might have stricter enforcement.
2. Check for Sensitive Content: Look for any content that might be flagged as sensitive or inappropriate. This includes but is not limited to:
– Hate speech
– Harassment
– Misinformation
– Explicit content
3. Modify the Training Data: If you identify any content that might be problematic, consider modifying or removing it. Even if the content was previously accepted, it might need adjustments to meet the new model’s criteria.
4. Use the Moderation API: You can use OpenAI’s Moderation API to pre-check your training data for any potential issues. This can help you identify and resolve problems before submitting the file for fine-tuning.
If you have reviewed your data and still face issues, please provide us the steps you’ve taken so far.
For more information on fine-tuning, you can refer to the fine-tuning guide.
We hope this helps you resolve the issue. If you have any further questions, feel free to ask!
Best,
Marcus
OpenAI Support
・「Tier 4以上が必要」の件は、誤りだったようです。
・「Moderation API(?!)で事前チェックできる」は新情報です。
・Moderation APIは、学習データファイルが有害かどうかをテストするAPIのようです。

・OpenAI Supportの助言4.に従い、Moderation APIを使ったチェックをしてみました。
・Colabo上コードセルを開き、まず「OpenAI」をインストールします。
(Google colaboの利用方法はここでは割愛します。)
!pip install openai
from openai import OpenAI
import json
client = OpenAI(api_key="sk-**************")
def process(data):
if isinstance(data, dict):
sorted_data = {k: process(v) for k, v in sorted(data.items())}
return {k: format_floats(v) for k, v in sorted_data.items()}
elif isinstance(data, list):
return [process(item) for item in data]
else:
return data
def format_floats(data):
if isinstance(data, float):
# Format floats to 10 decimal places as strings
return f"{data:.10f}"
else:
return data
text = """愛上 尾根さんの生年月日を教えてください。 1998年9月14日です。
愛上 尾根さんの職業を教えてください。 パティシエです。
愛上 尾根さんの性別を教えてください。 男性です。
愛上 尾根さんの出身地を教えてください。 青森県五所川原市です。
愛上 尾根さんの現在住所を教えてください。 東京都品川区西五反田8丁目1−5です。
愛上 尾根さんの出身高校を教えてください。 五所川原工科高校です。
愛上 尾根さんの出身大学を教えてください。 日本大学です。
愛上 尾根さんの好きな食べ物を教えてください。 麻婆豆腐です。辛いものが好きです。
愛上 尾根さんの特技を教えてください。 パズルです。
愛上 尾根さんの身長を教えてください。 172cmです。
愛上 尾根さんの体重を教えてください。 82kgです。"""
api_response = client.moderations.create(input=text)
response_dict = api_response.model_dump()
formatted_dict = process(response_dict)
print(json.dumps(formatted_dict, indent=2))・上のコードセルをGoogleColabo上Shift+Enterすれば検索実行されます。
結果(Response)は以下の通りです。
{
"id": "modr-****************",
"model": "text-moderation-007",
"results": [
{
"categories": {
"harassment": false,
"harassment/threatening": false,
"harassment_threatening": false,
"hate": false,
"hate/threatening": false,
"hate_threatening": false,
"self-harm": false,
"self-harm/instructions": false,
"self-harm/intent": false,
"self_harm": false,
"self_harm_instructions": false,
"self_harm_intent": false,
"sexual": false,
"sexual/minors": false,
"sexual_minors": false,
"violence": false,
"violence/graphic": false,
"violence_graphic": false
},
"category_scores": {
"harassment": "0.0013560511",
"harassment/threatening": "0.0000020551",
"harassment_threatening": "0.0000020551",
"hate": "0.0001251776",
"hate/threatening": "0.0000007184",
"hate_threatening": "0.0000007184",
"self-harm": "0.0001720232",
"self-harm/instructions": "0.0000003024",
"self-harm/intent": "0.0000068691",
"self_harm": "0.0001720232",
"self_harm_instructions": "0.0000003024",
"self_harm_intent": "0.0000068691",
"sexual": "0.0686868802",
"sexual/minors": "0.0161863714",
"sexual_minors": "0.0161863714",
"violence": "0.0007420173",
"violence/graphic": "0.0000068199",
"violence_graphic": "0.0000068199"
},
"flagged": false
}
]
}・ModerationAPIのResponse結果では「”flagged”: false」なので、OpenAI の使用ポリシー違反は無しです!個別判定(harassment等18個)も全て「false」です。
・おかしいですね。手がかりが無くなってしまいました。少し時間をおいてまた確認してみたいと思います。(もし、何かご存じの方がいらっしゃれば、フォロー頂けると助かります。)
まとめ
・「gpt-4o-mini-2024-07-18」のファインチューニングはコード(Google Colab上)とOpenAIのGUIの両方でエラーが発生してNGでした。
・学習データファイルは、形式チェックに加えて、使用ポリシーのチェックが追加されたようです。
・その使用ポリシーは、ModerationAPIで事前に試す事が出来たのですが、ファインチューニング時と挙動が違っていました。これは、また時間をおいて調査したいと思います。
