]> git.djapps.eu Git - pkg/ggml/sources/ggml/commitdiff
examples : add --print-confidence option to cli (whisper/3150)
authorDaniel Bevenius <redacted>
Wed, 14 May 2025 17:21:48 +0000 (19:21 +0200)
committerGeorgi Gerganov <redacted>
Tue, 27 May 2025 15:04:10 +0000 (18:04 +0300)
* examples : add --print-confidence option to cli

This commit adds a new command-line option `--print-confidence` to the
whisper-cli. When enabled, this option prints the confidence level of each
token in the transcribed text using ANSI formatting codes.

The confidence levels are represented using different styles:
```console
main: confidence: highlighted (low confidence), underlined (medium), dim (high confidence)
```

Refs: https://github.com/ggml-org/whisper.cpp/issues/3135

examples/common.h

index 1aa763817ee93261f9d7b48381e2693e4410bd7e..8f99df7dd326a0f6587a9b64628475098b75a656 100644 (file)
@@ -294,6 +294,26 @@ const std::vector<std::string> k_colors = {
     set_xterm256_foreground( 78, 178, 101),
 };
 
+// ANSI formatting codes
+static std::string set_inverse() {
+    return "\033[7m";
+}
+
+static std::string set_underline() {
+    return "\033[4m";
+}
+
+static std::string set_dim() {
+    return "\033[2m";
+}
+
+// Style scheme for different confidence levels
+const std::vector<std::string> k_styles = {
+    set_inverse(),   // Low confidence - inverse (highlighted)
+    set_underline(), // Medium confidence - underlined
+    set_dim(),       // High confidence - dim
+};
+
 //
 // Other utils
 //