File size: 2,308 Bytes
d382895
 
 
2e9c1b5
 
 
 
3316a96
 
0f5a8e7
3316a96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18ed5c7
3316a96
 
0f5a8e7
e1de7f2
 
 
 
 
 
 
 
 
 
 
 
 
 
85dbcae
 
 
 
 
 
 
 
 
e1de7f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
license: mit
pipeline_tag: automatic-speech-recognition
---

# Whisper tflite models for use in Whisper app on F-Droid

"transcribe-translate" models provide signatures for "serving_transcribe" and "serving_translate" to force the model to perform a certain action


    @tf.function(
        input_signature=[
            tf.TensorSpec((1, 80, 3000), tf.float32, name="input_features"),
        ],
    )
    def transcribe(self, input_features):
        outputs = self.model.generate(
            input_features,
            max_new_tokens=450,  # change as needed
            return_dict_in_generate=True,
            forced_decoder_ids=[[2, 50359], [3, 50363]],  # forced to transcribe any language with no timestamps
        )
        return {"sequences": outputs["sequences"]}

    @tf.function(
        input_signature=[
            tf.TensorSpec((1, 80, 3000), tf.float32, name="input_features"),
        ],
    )
    def translate(self, input_features):
        outputs = self.model.generate(
            input_features,
            max_new_tokens=450,  # change as needed
            return_dict_in_generate=True,
            forced_decoder_ids=[[2, 50358], [3, 50363]],  # forced to translate any language with no timestamps
        )
        return {"sequences": outputs["sequences"]}




In order to force transcription for a certain language set the 1. decoder id as shown below:

    def transcribe(self, input_features):
        outputs = self.model.generate(
            input_features,
            max_new_tokens=450,  # change as needed
            return_dict_in_generate=True,
            forced_decoder_ids=[[1, 50261], [2, 50359], [3, 50363]],  # forced to transcribe (50359) German (50261) with no timestamps (50363)
        )
        return {"sequences": outputs["sequences"]}

    def translate(self, input_features):
        outputs = self.model.generate(
            input_features,
            max_new_tokens=450,  # change as needed
            return_dict_in_generate=True,
            forced_decoder_ids=[[1, 50261], [2, 50358], [3, 50363]],  # different forced_decoder_ids
        )
        return {"sequences": outputs["sequences"]}

(language codes from here: https://github.com/woheller69/whisperIME/blob/master/app/src/main/java/com/whispertflite/utils/InputLang.java)