whisper.tflite: forced_decoder_ids does not apply to tflite model (multilingual, language issue)
Hello, I’m interested in converting Whisper models to tflite. And I’m generating a tflite model by referring to your works. Thank you for your contribution before discussing the issue!
My goal is a tflite model that can be transcribed into “Korean”.
For this work, I looked up related multilingual output issues.
And I understood that I had to apply options to perform transcription into a particular language.
model.config.forced_decoder_ids = [[1, 50264], [2, 50359], [3, 50363]] # <|ko|><|transcribe|><|notimestamp|>
they work well, before tflite converting!
My process is like this.
-
Load transformer-TFWhipser model
-
Define the ‘GenerateModel’, ‘serving(input_features)’ Apply configurations to set the language and task at this stage
-
Convert to TFLite (using tf.lite.TFLiteConverter)
-
Inference and output comparison (tensorflow, tflite)
Before converting to TFLite, generation configurations (language, task) were well applied. After that, Korean token values are generated.
output tensor:
[50258 50264 50359 50363 4704 7675 2785 16623 6301 1453 16316 2230
1453 2393 21166 1129 5514 5642 10520 14050 13 50257 ...]
text:
<|startoftranscript|><|ko|><|transcribe|><|notimestamps|> 지구의 일부가 날아가서 달이 되었다는 거예요.<|endoftext|> ...
After converting to TFLite, the model output is set to ‘0’ for task and timestamp tokens, although the language setting token remains in Korean(50264). After that, the tokens are generated with an English value.
output tensor:
[50258 50264 0 0 440 4120 311 644 390 16479 1314 293
3062 257 7135 13 50257 ...]
text:
<|startoftranscript|><|ko|>!! The earth's part was blown away and became a moon.<|endoftext|> ...
I don’t think configs is fully applied during conversion to tflite. Any advice regarding this? I think it would be helpful for a lot of people if we could solve this problem.
In addition, I also experimented with the tflite model, which is separated into an encoder and a decoder through onnx conversion. I got the desired result when I injected ‘decoder_start_token’ into the input_tensor of the decoder. However, if possible, I would like to use an combined model.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (3 by maintainers)
I tested it with the test wav file you provided, and it was decoded normally. It seems to work only if it matches the wav file characteristics that tensorflow can understand.
Thank you so much. 😄
I am sharing my testing environment to help others.
o Python environment python 3.8.19
print(tf.version) print(keras.version) print(transformers.version) 2.12.0 2.12.0 4.42.1
o android studio IDE Android Studio Koala | 2024.1.1 Build #AI-241.15989.150.2411.11948838, built on June 11, 2024 Runtime version: 17.0.10+0–11609105 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Windows 11.0 GC: G1 Young Generation, G1 Old Generation Memory: 2048M Cores: 16 Non-Bundled Plugins: idea.plugin.protoeditor (241.15989.49)
@robre22 My Python package version is as follows, but I don’t think it will help you with your problems.
Python 3.8.10 tensorflow==2.13.1 transformers==4.42.1I’ve experienced the ‘failed to invoke’ issue with some audio files, which may be related to audio files and audio decoding. If you have other audio samples, try them.Yes, it’s still working. However, it may not work well on ‘tiny’ and ‘base’ models. (My project is ‘small’ model.)
In the case of ‘tiny’, some text is broken and strange characters are visible.
Hello. After looking through the github forum, I found issues and solutions related to this.
Issue:
Solution: Those involved in the multilingual support issue of the tflite model will be able to solve most of their problems by proceeding with the ‘monkey patch’ below. https://github.com/nyadla-sys/whisper.tflite/discussions/15#discussioncomment-7362798
Thank you to the engineers involved!