ChatGptは、一般的な言語だけでなく、絵文字や単語のスクランブルなどの型破りな文章を処理できる堅牢な翻訳者としての能力も実証しています。ただし、正確な命令に従い、モデルtemperatureパラメーターを0に設定するように指示された場合でも、決定論的な出力を生成し、ラインとラインの相関に準拠するとは限りません。
このユーティリティは、Openai ChatGpt APIを使用してテキストを翻訳し、特にSRT字幕向けにラインベースの翻訳に特に焦点を当てています。翻訳者は、SRTのオーバーヘッドを削除し、テキストをバッチにグループ化することでトークンの使用を最適化し、その結果、トークンの消費が過度に並べずに任意の長さの翻訳が行われ、ライン入力と出力の1対1の一致が確保されます。
--experimental-structured-mode 。--experimental-use-full-context (CLIのみ)で有効になります。参照:https://github.com/openai/openai-quickstart-node#setup
>= 16.13.0が必要です。このREADMEは、 bashシェル環境を想定していますgit clone https://github.com/Cerlancism/chatgpt-subtitle-translator && cd chatgpt-subtitle-translatornpm installchmod +x cli/translator.mjs.example.envを.envにコピーしますcp .env.example .env.envファイルにAPIキーを追加します cli/translator.mjs --help
Usage: translator [options]
Translation tool based on ChatGPT API
オプション:
--from <language>
ソース言語(デフォルト: "")
--to <language>
ターゲット言語(デフォルト:「英語」)
-i, --input <file>
.srt形式またはプレーンテキストで、このファイルのコンテンツを含むソーステキストを入力します
-o, --output <file>
出力ファイル名、デフォルトは入力ファイル名に基づいています
-p, --plain-text <text>
このプレーンテキスト引数を使用してソーステキストを入力します
-s, --system-instruction <instruction>
プロンプトシステム命令テンプレートをオーバーライド--from --to Translate ${from} to ${to}
--initial-prompts <prompts>
JSONでの翻訳の最初のプロンプト(デフォルト: "[]" )
--no-use-moderator
OpenAI APIモデレートエンドポイントを使用しないでください
--moderation-model
(デフォルト: "omni-moderation-latest" )https://platform.openai.com/docs/models/moderation
--no-prefix-number
数値インデックスを使用した行をプレフィックスしないでください
--no-line-matching
1〜1行の数量入出力マッチングを実施しないでください
-l, --history-prompt-length <length>
次のリクエストバッチのために保持する迅速な履歴の長さ(デフォルト:10)
-b, --batch-sizes <sizes> jsonアレイの翻訳プロンプトスライスの順序の増加のバッチサイズ(デフォルト: "[10,100]" )
トークン制限内に推定されている場合、各翻訳プロンプトに含める行の数。出力ライン量の不一致の場合、この数は配列の値に応じて段階的に減少し、最終的には段階的に到達します。
通常、バッチサイズが大きいと、より効率的なトークン利用と潜在的により良いコンテキスト翻訳につながります。ただし、出力ライン量の不一致またはトークン制限を超えると、トークンの無駄が発生し、バッチサイズが小さくなるバッチの再提出が必要です。
--experimental-structured-mode [mode]
構造化された応答を有効にします。 (デフォルト: array 、選択array 、 object )
--experimental-structured-mode array入力と出力をプレーンアレイ形式に構造化します。このオプションは、ベースモードに比べてより簡潔ですが、バッチごとにわずかに多くのトークンを使用しています。--experimental-structured-mode objectは、入力値に基づいて動的に生成されたオブジェクトスキーマに入力と出力の両方を構成します。このオプションはさらに簡潔で、トークンが少なく使用されますが、バッチサイズが小さく、遅くて信頼できない場合があります。その信頼性の低いため、再送信の回収が増える可能性があり、その過程でより多くのトークンを無駄にする可能性があります。 --experimental-use-full-context
翻訳されたデータの完全なコンテキストを含めて、迅速なキャッシュでうまく機能します。
ユーザーとアシスタントメッセージのペアごとの翻訳された行は--history-prompt-length (デフォルトでは--history-prompt-length 10 )で定義されているようにスライスされます。これを最大のバッチサイズ(デフォルトでは--batch-sizes "[10,100]" )に--history-prompt-length 100勧めします。
これを有効にすると、モデルのコンテキストウィンドウの制限(通常は128Kにぶつかるリスクがありますが、ほとんどの場合に十分である必要があります。
--log-level <level>
ログレベル(デフォルト: debug 、選択: trace 、 debug 、 info 、 warn 、 error 、 silent )
--silent
--log-level silentと同じ
--quiet
--log-level silentと同じ
GPTの追加オプション:
-m, --model <model>"gpt-4o-mini" )https://platform.openai.com/docs/api-reference/chat/create--stream-t, --temperature <temperature>0.3未満の低い値を翻訳のより決定論的に設定する必要があります(デフォルト: 1 )https://platform.openai.com/docs/api-reference/chat/create#chat-create-temperation--top_p <top_p>--presence_penalty <presence_penalty>--frequency_penalty <frequency_penalty--logit_bias <logit_bias>cli/translator.mjs --plain-text "你好"標準出力
Hello.
cli/translator.mjs --stream --to " Emojis " --temperature 0 --plain-text " $( curl ' https://api.chucknorris.io/jokes/0ECUwLDTTYSaeFCq6YMa5A ' | jq .value ) "入力引数
Chuck Norris can walk with the animals, talk with the animals; grunt and squeak and squawk with the animals... and the animals, without fail, always say 'yessir Mr. Norris'.
標準出力
????♂️??????????????️??️❗️??????=???????????????????=??.
cli/translator.mjs --stream --system-instruction " Scramble characters of words while only keeping the start and end letter " --no-prefix-number --no-line-matching --temperature 0 --plain-text " Chuck Norris can walk with the animals, talk with the animals; "標準出力
Cuhck Nroris can wakl wtih the aiamnls, talk wtih the aiamnls;
cli/translator.mjs --stream --system-instruction " Unscramble characters back to English " --no-prefix-number --no-line-matching --temperature 0 --plain-text " Cuhck Nroris can wakl wtih the aiamnls, talk wtih the aiamnls; "標準出力
Chuck Norris can walk with the animals, talk with the animals;
cli/translator.mjs --stream --temperature 0 --input test/data/test_cn.txt入力ファイル:test/data/test_cn.txt
你好。
拜拜!
標準出力
Hello.
Goodbye!
cli/translator.mjs --stream --temperature 0 --input test/data/test_ja_small.srt入力ファイル:test/data/test_ja_small.srt
1
00 : 00 : 00 , 000 --> 00 : 00 : 02 , 000
おはようございます。
2
00 : 00 : 02 , 000 --> 00 : 00 : 05 , 000
お元気ですか?
3
00 : 00 : 05 , 000 --> 00 : 00 : 07 , 000
はい、元気です。
4
00 : 00 : 08 , 000 --> 00 : 00 : 12 , 000
今日は天気がいいですね。
5
00 : 00 : 12 , 000 --> 00 : 00 : 16 , 000
はい、とてもいい天気です。出力ファイル:test/data/test_ja_small.srt.out_english.srt
1
00 : 00 : 00 , 000 --> 00 : 00 : 02 , 000
Good morning.
2
00 : 00 : 02 , 000 --> 00 : 00 : 05 , 000
How are you?
3
00 : 00 : 05 , 000 --> 00 : 00 : 07 , 000
Yes, I'm doing well.
4
00 : 00 : 08 , 000 --> 00 : 00 : 12 , 000
The weather is nice today, isn' t it?
5
00 : 00 : 12 , 000 --> 00 : 00 : 16 , 000
Yes, it's very nice weather.システム命令
トークン: 5
Translate Japanese to English
| 入力 | プロンプト | 変身 | 出力 |
|---|---|---|---|
トークン: | トークン: | トークン: | トークン: |
1
00 : 00 : 00 , 000 --> 00 : 00 : 02 , 000
おはようございます。
2
00 : 00 : 02 , 000 --> 00 : 00 : 05 , 000
お元気ですか?
3
00 : 00 : 05 , 000 --> 00 : 00 : 07 , 000
はい、元気です。
4
00 : 00 : 08 , 000 --> 00 : 00 : 12 , 000
今日は天気がいいですね。
5
00 : 00 : 12 , 000 --> 00 : 00 : 16 , 000
はい、とてもいい天気です。 | | | 1
00 : 00 : 00 , 000 --> 00 : 00 : 02 , 000
Good morning.
2
00 : 00 : 02 , 000 --> 00 : 00 : 05 , 000
How are you?
3
00 : 00 : 05 , 000 --> 00 : 00 : 07 , 000
Yes, I'm doing well.
4
00 : 00 : 08 , 000 --> 00 : 00 : 12 , 000
The weather is nice today, isn' t it?
5
00 : 00 : 12 , 000 --> 00 : 00 : 16 , 000
Yes, it's very nice weather. |
TODO :その他の分析
5 SRTライン:
test/data/test_ja_small.srt
299362276 30 SRTライン:
test/data/test_ja.srt
16256719[5, 10]のSRTストリッピングとラインバッチ、最大10の歴史的迅速なコンテキストを含む:1036