Skip to content

Commit f141b2b

Browse files
authored
main : add options for temperature control (ggml-org#2088)
Add two options: ``` -tp, --temperature N [0.00 ] The sampling temperature, between 0 and 1 -tpi, --temperature-inc N [0.20 ] The increment of temperature, between 0 and 1 ``` The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit. Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
1 parent 2b434c4 commit f141b2b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

examples/main/main.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ struct whisper_params {
4444
float entropy_thold = 2.40f;
4545
float logprob_thold = -1.00f;
4646
float grammar_penalty = 100.0f;
47+
float temperature = 0.0f;
48+
float temperature_inc = 0.2f;
4749

4850
bool speed_up = false;
4951
bool debug_mode = false;
@@ -133,6 +135,8 @@ bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
133135
else if (arg == "-wt" || arg == "--word-thold") { params.word_thold = std::stof(argv[++i]); }
134136
else if (arg == "-et" || arg == "--entropy-thold") { params.entropy_thold = std::stof(argv[++i]); }
135137
else if (arg == "-lpt" || arg == "--logprob-thold") { params.logprob_thold = std::stof(argv[++i]); }
138+
else if (arg == "-tp" || arg == "--temperature") { params.temperature = std::stof(argv[++i]); }
139+
else if (arg == "-tpi" || arg == "--temperature-inc") { params.temperature_inc = std::stof(argv[++i]); }
136140
// else if (arg == "-su" || arg == "--speed-up") { params.speed_up = true; }
137141
else if (arg == "-debug"|| arg == "--debug-mode") { params.debug_mode = true; }
138142
else if (arg == "-tr" || arg == "--translate") { params.translate = true; }
@@ -198,6 +202,8 @@ void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params & para
198202
fprintf(stderr, " -wt N, --word-thold N [%-7.2f] word timestamp probability threshold\n", params.word_thold);
199203
fprintf(stderr, " -et N, --entropy-thold N [%-7.2f] entropy threshold for decoder fail\n", params.entropy_thold);
200204
fprintf(stderr, " -lpt N, --logprob-thold N [%-7.2f] log probability threshold for decoder fail\n", params.logprob_thold);
205+
fprintf(stderr, " -tp, --temperature N [%-7.2f] The sampling temperature, between 0 and 1\n", params.temperature);
206+
fprintf(stderr, " -tpi, --temperature-inc N [%-7.2f] The increment of temperature, between 0 and 1\n",params.temperature_inc);
201207
// fprintf(stderr, " -su, --speed-up [%-7s] speed up audio by x2 (reduced accuracy)\n", params.speed_up ? "true" : "false");
202208
fprintf(stderr, " -debug, --debug-mode [%-7s] enable debug mode (eg. dump log_mel)\n", params.debug_mode ? "true" : "false");
203209
fprintf(stderr, " -tr, --translate [%-7s] translate from source language to english\n", params.translate ? "true" : "false");
@@ -1107,7 +1113,9 @@ int main(int argc, char ** argv) {
11071113
wparams.greedy.best_of = params.best_of;
11081114
wparams.beam_search.beam_size = params.beam_size;
11091115

1110-
wparams.temperature_inc = params.no_fallback ? 0.0f : wparams.temperature_inc;
1116+
wparams.temperature_inc = params.no_fallback ? 0.0f : params.temperature_inc;
1117+
wparams.temperature = params.temperature;
1118+
11111119
wparams.entropy_thold = params.entropy_thold;
11121120
wparams.logprob_thold = params.logprob_thold;
11131121

0 commit comments

Comments
 (0)