torchaudio.models.decoder¶
解码器类¶
CTCDecoder¶
-
class
torchaudio.models.decoder.CTCDecoder(nbest: int, lexicon: Optional[Dict], word_dict: torchaudio._torchaudio_decoder._Dictionary, tokens_dict: torchaudio._torchaudio_decoder._Dictionary, lm: torchaudio._torchaudio_decoder._LM, decoder_options: Union[torchaudio._torchaudio_decoder._LexiconDecoderOptions, torchaudio._torchaudio_decoder._LexiconFreeDecoderOptions], blank_token: str, sil_token: str, unk_word: str)[source]¶ 来自 Flashlight 的 CTC 束搜索解码器 [1]。
注意
要构建解码器,请使用工厂函数
ctc_decoder()。- Parameters
nbest (int) – 要返回的最佳解码数量
lexicon (Dict 或 None) – 单词到拼写的词典映射,或 None 表示无词典解码器
word_dict (_Dictionary) – 单词字典
tokens_dict (_Dictionary) – 标记字典
lm (_LM) – 语言模型
decoder_options (_LexiconDecoderOptions 或 _LexiconFreeDecoderOptions) – 用于束搜索解码的参数
blank_token (str) – 对应空格的标记
sil_token (str) – 对应静音的 token
unk_word (str) – 对应未知词的单词
- Tutorials using
CTCDecoder:
-
__call__(self, emissions: torch.FloatTensor, lengths: Optional[torch.Tensor] = None) → List[List[torchaudio.models.decoder.CTCHypothesis]][source]¶ - Parameters
emissions (torch.FloatTensor) – 形状为 (batch, frame, num_tokens) 的 CPU 张量,存储标签上的概率分布序列;声学模型的输出。
lengths (Tensor 或 None, 可选) – 形状为 (batch, ) 的 CPU 张量,用于存储每个批次中输出张量在时间轴上的有效长度。
- Returns
批次中每个音频序列的排序最佳假设列表。
- Return type
List[List[CTCHypothesis]]
工厂函数¶
ctc_decoder¶
-
class
torchaudio.models.decoder.ctc_decoder(lexicon: Optional[str], tokens: Union[str, List[str]], lm: Optional[str] = None, nbest: int = 1, beam_size: int = 50, beam_size_token: Optional[int] = None, beam_threshold: float = 50, lm_weight: float = 2, word_score: float = 0, unk_score: float = - inf, sil_score: float = 0, log_add: bool = False, blank_token: str = '-', sil_token: str = '|', unk_word: str = '<unk>')[source]¶ 从 Flashlight [1] 构建 CTC 束搜索解码器。
- Parameters
lexicon (str 或 None) – 包含可能单词及其对应拼写的词典文件。 每行由一个单词及其空格分隔的拼写组成。如果为 None,则使用无词典解码。
tokens (str or List[str]) – 包含有效标记的文件或列表。如果使用文件,期望的格式是将映射到同一索引的标记放在同一行
nbest (int, optional) – 要返回的最佳解码数量(默认值:1)
beam_size (int, optional) – 每个解码步骤后保留的最大假设数量(默认值:50)
beam_size_token (int, optional) – 在每一步解码中考虑的最大token数量。 如果为 None,则设置为token的总数(默认值:None)
beam_threshold (float, optional) – 用于剪枝假设的阈值(默认值:50)
lm_weight (float, optional) – 语言模型的权重(默认值:2)
word_score (float, optional) – 词插入分数(默认值:0)
unk_score (float, optional) – 未知词插入分数(默认值:-inf)
sil_score (float, optional) – 静音插入分数(默认值:0)
log_add (bool, optional) – 在合并假设时是否使用 logadd(默认值:False)
blank_token (str, optional) – 对应空白符的标记(默认值:“-“)
sil_token (str, optional) – 对应静音的 token(默认值:“|”)
unk_word (str, optional) – 对应未知词的单词(默认值:“<unk>”)
- Returns
解码器
- Return type
- Example
>>> decoder = ctc_decoder( >>> lexicon="lexicon.txt", >>> tokens="tokens.txt", >>> lm="kenlm.bin", >>> ) >>> results = decoder(emissions) # List of shape (B, nbest) of Hypotheses
- Tutorials using
ctc_decoder:
实用函数¶
download_pretrained_files¶
-
class
torchaudio.models.decoder.download_pretrained_files(model: str)[source]¶ 检索用于 CTC 解码器的预训练数据文件。
- Parameters
model (str) – 要下载的预训练语言模型。 选项:[“librispeech-3-gram”, “librispeech-4-gram”, “librispeech”]
- Returns
- Object with the following attributes
- lm:
对应于已下载语言模型的路径,或者如果该模型未与 lm 关联则为 None
- lexicon:
对应于已下载词典文件的路径
- tokens:
对应于已下载令牌文件的路径
- Tutorials using
download_pretrained_files: