axinc-ai / ailia-models

The collection of pre-trained, state-of-the-art AI models for ailia SDK
2k stars 318 forks source link

whysperのlarge/large-v3モデルで長いファイルを変換すると途中からおかしくなる #1393

Closed itsmeterada closed 6 months ago

itsmeterada commented 7 months ago

長めのファイルを変換しようとしたところ、途中から結果がおかしくなる現象がある。(同じ文章が繰り返し出力される)

テストに使用したファイル。 https://drive.google.com/file/d/1xXThyWwK_o0_gkKbtdULYwAzZqlE2c9M/view?usp=drive_link

結果 large-v3はCPU/GPUでも同様の結果。small/medium/largeでは発生しない。

out_large-v3.txt out_large-v3_cpu.txt out_large.txt

itsmeterada commented 7 months ago

largeとlarge-v3は同じコードで動いているが、雰囲気的には確保しているワーク用の領域が足りていないか、どこかの領域を壊していそう。

kyakuno commented 7 months ago

@ooe1123 きりのいいところでこちらのissueを確認いただけると嬉しいです。

kyakuno commented 7 months ago

whisper large v3はハレーションが発生しやすいという話はある。まずは公式のwhisper v3でbeam size=1にして挙動を確認すると良さそう。 https://deepgram.com/learn/whisper-v3-results

kyakuno commented 7 months ago

こちらのデータでもlarge-v3の評価が低いですね。 https://research.reazon.jp/blog/2024-02-14-ReazonSpeech.html

ooe1123 commented 7 months ago

同じ文章が繰り返される症状と、入力ファイルの長さは関係がないようです。

サンプルコードのaudio_utils.pyにて、 flg_ffmpeg = True と設定を変えると、(オリジナルwhisperと同じ音声ファイル読み込み方法) 02:27.660~の同じ文章が繰り返される症状は解消しました。 (ただし、04:55.180~から同様に同じ文章が繰り返される症状が発生します)

whisperの処理は、 ① wavファイルの読み込み (ffmpegからlibrosaに変更) ② log_mel_spectrogramの処理 (torchからlibrosaに変更) ③ melからaudio_featuresに変換 (torchからonnxに変更) ④ audio_featuresからlogitsを取得 (torchからonnxに変更) ⑤ logitsからtokenにデコード処理

このような流れになっていますが、 ailiaのサンプルコードを実装するときには ③、④のDNNのところでオリジナルと比較すると多少の誤差が出ていて、 また、①と②ではかなりの違いが出ていました。 しかし、最終的に適切にみえる結果が出ているようだったので、これらの誤差を許容していました。

処理の過程でこれらの誤差が積み重なった結果、致命的に間違った出力となってしまうことがあるのではないかと思います。

ooe1123 commented 7 months ago

ailiaのサンプルコードで、large-v3モデルで flg_ffmpeg = True とした場合、 04:55.180~から同じ文章が繰り返される症状が発生していて、

[04:54.280 --> 04:54.680]  And if you look at the Foundation's governance, you'll see there are some of the same things.
[04:54.680 --> 04:55.180]  But the mission is entirely different.
[04:55.180 --> 04:55.680]  But the mission is entirely different.
[04:55.680 --> 04:56.180]  But the mission is entirely different.
[04:56.180 --> 04:56.680]  But the mission is entirely different.
...

一方、オリジナルwhisperでも

[04:54.280 --> 04:54.780]  And if you look at the Foundation's governance, you'll see there are some of the same things.
[04:54.780 --> 04:55.280]  But the mission is entirely different.
[04:55.280 --> 04:55.780]  But the mission is entirely different.
[04:55.780 --> 04:56.280]  But the mission is entirely different.
[04:56.280 --> 04:56.780]  But they're all the same people, too.
[04:56.780 --> 04:57.280]  But the mission is entirely different.
[04:57.280 --> 04:57.780]  But they're all the same people, too.
[04:57.780 --> 04:59.280]  Does that make the Pi Foundation shady or something?
[04:59.280 --> 04:59.780]  No.
[04:59.780 --> 05:00.280]  They do a lot of great things.
[05:00.280 --> 05:00.780]  They do a lot of great things.
[05:00.780 --> 05:01.280]  They do a lot of great things.
[05:01.280 --> 05:05.280]  One of my favorites is the Astro Pi Challenge, where kids can get their code to run on a
[05:05.280 --> 05:06.680]  pie in space.
[05:06.680 --> 05:10.880]  But they are different entities and have been since pretty much the beginning.
[05:10.880 --> 05:14.480]  Does the Foundation stand to profit from Raspberry Pi Trading's IPO?

と出力されており、ここはうまくデコードしにくい箇所のようです。

オリジナルwhisperでは、一旦バグるものの、途中から復帰できていて、 これは複数のサンプルをとったり、(--beam_sizeオプションによる) temperatureの値を大きくして探索範囲を広げたりすることで、 ロバストに作ってあるようです。

いま、ailiaのサンプルコードではその機能が組み込めていていないため、実装を検討してみようと思います。

kyakuno commented 7 months ago

詳細な調査ありがとうございます!原因と対応方針、了解しました!

kyakuno commented 6 months ago

1405 でwhisper公式に導入された、テキストのデコード結果をzlibで圧縮し、圧縮率が高すぎたら繰り返しと判定してfallbackする機能を導入しました。