speechbrain.k2_integration.utils 模块

用于k2与SpeechBrain集成的实用工具。

此代码是从 icefall (https://github.com/k2-fsa/icefall) 调整而来。

Authors:
  • 皮埃尔·冠军 2023

  • 赵泽宇 2023

  • 乔治奥斯·卡拉卡西迪斯 2023

摘要

函数:

lattice_path_to_textid

从最佳路径的FSA中提取文本(作为单词ID)。

lattice_paths_to_text

将最佳路径转换为字符串列表。

load_G

加载一个用于解码图创建(或语言模型重评分)的语言模型。

prepare_rescoring_G

准备一个语言模型,目的是用于语言模型重评分。

参考

speechbrain.k2_integration.utils.lattice_path_to_textid(best_paths: k2.Fsa, return_ragged: bool = False) List[List[int]] | k2.RaggedTensor[source]

从最佳路径的FSA中提取文本(作为单词ID)。

Parameters:
  • best_paths (k2.Fsa) – 一个包含最佳路径的k2.Fsa,其中best_paths.arcs.num_axes() == 3,即包含多个FSA,这预期是k2.shortest_path的结果(否则返回的值将没有意义)。

  • return_ragged (bool) – 如果为True,则返回一个具有两个轴的稀疏张量 [utt][word_id]。 如果为False,则返回一个列表的列表形式的单词ID。

Returns:

  • 返回一个包含整数列表的列表,其中包含我们解码的标签序列。

  • 解码。

speechbrain.k2_integration.utils.lattice_paths_to_text(best_paths: k2.Fsa, word_table) List[str][source]

将最佳路径转换为字符串列表。

Parameters:
  • best_paths (k2.Fsa) – 它是给定话语中得分最高的路径。

  • word_table (List[str] 或 Dict[int,str]) – 它是一个将单词ID映射到单词的列表或字典。

Returns:

texts – 字符串列表,每个字符串是对应话语的解码结果。

Return type:

列表[str]

speechbrain.k2_integration.utils.load_G(path: str | Path, cache: bool = True) k2.Fsa[source]

加载一个语言模型用于解码图的创建(或语言模型重评分)。

Parameters:
  • path (str) – FST LM 的路径(以 .fst.txt 结尾)或 k2 转换的 LM 的路径(以 pytorch .pt 格式)。

  • cache (bool) – 是否从/到.pt格式加载/缓存LM(在同一目录中)。

Returns:

G – 一个表示语言模型的FSA。

Return type:

k2.Fsa

speechbrain.k2_integration.utils.prepare_rescoring_G(G: k2.Fsa) k2.Fsa[source]

准备一个LM,目的是将其用于LM重评分。 例如,在librispeech配方中,这是一个4-gram LM(而一个3gram LM用于HLG构建)。

Parameters:

G (k2.Fsa) – 一个表示语言模型的FSA。

Returns:

G – 一个表示语言模型(LM)的FSA,具有以下修改: - G.aux_labels 被移除 - G.lm_scores 被设置为 G.scores - G 是弧排序的

Return type:

k2.Fsa