`SentencepiecesTokenizer.ids2tokens` ignores `token_list` - root cause of the paraformer-en gibberish in #3040
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
調査の方向性
funasr/tokenizer/sentencepiece_tokenizer.py の SentencepiecesTokenizer.ids2tokens から始め、Paraformer がどのようにトークン ID を渡すかを追ってください。token_list の読み込み方法を確認し、このケースで SentencePiece モデルとの並び順を比較してください。意図されたトークン対応付けを使うようにデコード動作を更新し、報告された英語のサンプルが正しくデコードされることと、既存モデルとの互換性が保たれることを確認してください。
索引モデルが issue の本文から書いたものです。
説明
Summary
iic/speech_paraformer-large-vad-punc_asr_nat-en-16k-common-vocab10020 is not mispackaged. The model predicts the right token ids; the text goes wrong at decoding. SentencepiecesTokenizer.ids2tokens ignores the loaded token_list (tokens.json) and decodes the ids with the BPE model's own id order. For this model the two orders differ, so every word is replaced by an unrelated one. Decoding the same ids through tokens.json gives correct English.
Environment
FunASR 1.4.16 (same code on current main), torch 2.14.1, Python 3.11, macOS arm64, CPU.
Root cause
funasr/tokenizer/sentencepiece_tokenizer.py:
def ids2tokens(self, *args, **kwargs):
return self.decode(*args, **kwargs) # -> self.sp.DecodeIds(ids)
Paraformer inference calls tokenizer.ids2tokens(token_int). The ids index tokens.json (10020 entries: <blank>, <s>, </s>, ~, <, ...), but sp.DecodeIds reads them as bpe.model ids (10000 pieces: <unk>, <s>, </s>, ▁the, s, ...). Weights load with "All keys matched successfully" and the decoder output size (10020) equals len(tokens.json).
Repro
from funasr import AutoModel
m = AutoModel(model="iic/speech_paraformer-large-vad-punc_asr_nat-en-16k-common-vocab10020", device="cpu")
tk = m.kwargs["tokenizer"]
cap = {}
orig = type(tk).ids2tokens
def spy(self, ids, **kw):
cap["ids"] = list(ids)
return orig(self, ids, **kw)
type(tk).ids2tokens = spy
print(m.generate(input="https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_en.wav")[0]["text"])
print(tk.sp.DecodePieces([tk.token_list[i] for i in cap["ids"]]))
Output on the official sample:
procedure telegram impatience phuket sleeping danielot pro
he tried to think how it could be
Line 1 is the gibberish reported in #3040; line 2 is the correct transcript from the same ids.
Suggested fix
def ids2tokens(self, integers, **kwargs):
if self.token_list is not None:
return [self.token_list[i] for i in integers]
return self.decode(integers, **kwargs)
Models whose tokens.json already follows bpe.model order decode the same either way.
- 主要言語
- Python
- スター
- 20.8k
- フォーク
- 2.1k
- 平均マージ
- 1日 46分
- マージ済み PR(30日)
- 36
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelscope/FunASR のほかの issue
-
compute_wer_by_line raises OverflowError at 32,768 tokens with NumPy 2.3.5対応中かも @carey-bk が今日担当しました。 オープンbug needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
modelscope/FunASR#3781 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
modelscope/FunASR#3762 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Bug: blank lines in wav.scp / jsonl file lists crash prepare_data_iterator (IndexError / JSONDecodeError)対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンneeds feedback
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
modelscope/FunASR#3757 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
modelscope/FunASR#3730 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
modelscope/FunASR#3704 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
modelscope/FunASR の issue をすべて見る
似ている issue
-
idxmax/idxmin raise ValueError when a single partition is all-NA対応中かも @Jason10191019999 が今日担当しました。 オープンneeds triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 3 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
-
[BUG]: Windows GUI package of v1.17.0-rc3 has no GTK DLLs対応中かも @andrut-ds が今日担当しました。 オープンbug CI/CD Pactus-GUI Windows
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
pactus-project/pactus#2428 ·
メンテナーはふだん 1 日以内に返信
-
DiskDataset.reshard() can hang with a zero or negative shard size対応中かも @Programmer-Develops が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 19 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
GNS3/gns3-server#3017 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信