postprocess_hotwords: non-Chinese hotword maps to an empty pinyin key and force-replaces every latin/digit span (ratio("","")=100)

Ouverte Adaptée aux débutants
#3,796 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
76/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
python

Piste de recherche

Commencez par funasr/utils/postprocess_hotwords.py, en particulier _to_pinyin_key, _apply_fuzzy et PostprocessHotwordMatcher.__init__. Reproduisez le problème avec l’exemple Python pur fourni, puis vérifiez les tests existants du matcher pour les clés pinyin vides et celles mêlant plusieurs écritures. Le travail est terminé lorsque les hotwords non chinoises ne remplacent plus des segments latins ou numériques sans rapport, et que la correspondance valide des homophones chinois fonctionne toujours.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

环境
  • funasr 1.4.16(PyPI),paraformer-zh + fsmn-vad + ct-punc
  • 已安装 pypinyin / rapidfuzz(postprocess 模糊匹配依赖)
现象

postprocess_hotwords 传入含拉丁/数字的热词时,转写文本里的英文与数字片段会被整段替换成热词。一个 "AI" 热词会把识别结果刷成满屏 AIAI,数字也被吞掉。

最小复现(纯 Python,不需要模型与音频):

from funasr.utils.postprocess_hotwords import build_postprocess_hotword_matcher

m = build_postprocess_hotword_matcher(["AI"])
out, matches = m.apply_text("用AI做产品,2024年做AI的公司有很多。")
print(out)
# 实际输出: 用AIAI做产品AIAI年做AIAI的公司有很多。
# 期望输出: 原文不变(或仅做同音纠正)

生产环境实测(paraformer-zh 转写 1 小时中文播客,热词 "AI"):转写稿里出现大量 AIAIAIAIAI 连发、2024 等数字被替换成热词。

根因分析

funasr/utils/postprocess_hotwords.py 中:

  1. _to_pinyin_key 用 lazy_pinyin(..., errors="ignore") 构造拼音键,该配置会丢弃所有非中文字符。纯拉丁热词(如 "AI")的拼音键是空串 ""。
  2. _apply_fuzzy 对滑窗 segment 计算 fuzz.ratio(segment_py, target_py),而 rapidfuzz.fuzz.ratio("", "") == 100.0。于是任何拼音键同样为空的滑窗(纯英文/数字窗口)都得满分,超过默认阈值 0.85,被无条件替换成热词。
  3. 连带影响:"A"、"I" 等相邻单字符窗口也各自满分且互不重叠,双双命中后 "AI" 变成 "AIAI";数字窗口 "20"、"24" 同样被替换。
  4. 混合热词(如 "C端")拼音键只剩 "duan",每个同音中文段都会被粘上拉丁:这个端口 → 这个C端口。
  5. 反直觉的是,这类热词本来的目标收益永远无法命中:ratio("ai", "") == 0,期望中的「爱 → AI」同音纠正一次也不会发生。即该路径对非中文热词只有破坏、没有收益。
建议修复

PostprocessHotwordMatcher.__init__ 构造 _length_buckets 时跳过拼音键为空(或与原词长度严重不符)的目标,例如:

for target in self.fuzzy_targets:
    target_py = _to_pinyin_key(target)
    if not target_py:      # 纯拉丁/数字热词:模糊匹配无意义且误伤满分
        continue
    ...

(更严格的话可要求 target_py 覆盖原词的全部非中文字符长度,避免混合词残键误配。)

用户侧临时规避

只把全中文词条传给 postprocess_hotwords;含英文/数字的术语交给其他纠正路径。

Langage dominant
Python
Étoiles
20.9k
Forks
2.1k
Merge moyen
1 j 3 h
PR mergées (30 j)
46

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de modelscope/FunASR

Toutes les issues de modelscope/FunASR

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.