speechbrain.lobes.models.g2p.dataio 模块
G2P 流水线的数据流水线元素
- 作者
Loren Lugosch 2020
Mirco Ravanelli 2020
Artem Ploujnikov 2021(仅进行了少量重构)
概要
类
一个延迟初始化包装器 |
函数
向提供的序列添加 BOS 和 EOS 令牌 |
|
对音素执行 Beam Search。 |
|
构建一个将任意令牌映射到任意选择的字符的映射。 |
|
返回一个函数,该函数从使用字符映射分词后的序列中恢复原始序列 |
|
生成连续字符列表 |
|
清理输入文本,移除不在接受的字素列表中的任何字符并转换为大写 |
|
使用 EOS/BOS 序列初始化音素编码器 |
|
交换字典中的键和值 |
|
根据命名约定确定用于序列(例如,字素/音素)的键。 |
|
对字素序列进行编码 |
|
一个包装器,确保指定对象只初始化一次(主要用于在调用构造函数时进行训练的分词器) |
|
解码音素序列 |
|
使用提供的编码器对音素序列进行编码 |
|
将一批音素序列(单个 tensor)转换为由空格分隔的音素标签字符串列表(例如 ["T AY B L", "B UH K"]),并移除任何特殊令牌。 |
|
从序列中移除任何特殊令牌。 |
|
使用分词器解码序列。 |
|
使用预训练分词器的流水线元素 |
|
应用词嵌入(如果适用)。 |
参考
- speechbrain.lobes.models.g2p.dataio.clean_pipeline(txt, graphemes)[source]
清理输入文本,移除不在接受的字素列表中的任何字符并转换为大写
- 参数:
- 返回值:
item – 一个包装好的转换函数
- 返回类型:
- speechbrain.lobes.models.g2p.dataio.grapheme_pipeline(char, grapheme_encoder=None, uppercase=True)[source]
对字素序列进行编码
- 参数:
char (str) – 要编码的字符列表。
grapheme_encoder (speechbrain.dataio.encoder.TextEncoder) – 字素的文本编码器。如果未提供,
uppercase (bool) – 是否将项目转换为大写
- Yields:
grapheme_list (list) – 原始字素列表,不包括任何不匹配的标签
grapheme_encoded_list (list) – 编码为整数的字素列表
grapheme_encoded (torch.Tensor)
- speechbrain.lobes.models.g2p.dataio.tokenizer_encode_pipeline(seq, tokenizer, tokens, wordwise=True, word_separator=' ', token_space_index=512, char_map=None)[source]
使用预训练分词器的流水线元素
- 参数:
seq (list) – 要编码的令牌列表。
tokenizer (speechbrain.tokenizer.SentencePiece) – 分词器实例
tokens (str) – 可用的令牌
wordwise (str) – 分词是针对整个序列还是逐个单词执行。分词可以产生令牌序列,其中一个令牌可以跨越多个单词
word_separator (str) – 用于单词之间分隔的子字符串。
token_space_index (int) – 空格令牌的索引
char_map (dict) – 字符到令牌的映射。这用于对音素序列而非字符序列进行分词。音素序列通常是一个由一个或两个字符组成的令牌列表(例如 [“DH”, “UH”, “ “, “S”, “AW”, “N”, “D”])。字符映射使得将这些映射到任意选择的字符成为可能
- Yields:
token_list (list) – 原始令牌列表
encoded_list (list) – 编码为整数列表的令牌列表
encoded (torch.Tensor) – 编码为 tensor 的令牌列表
- speechbrain.lobes.models.g2p.dataio.enable_eos_bos(tokens, encoder, bos_index, eos_index)[source]
使用 EOS/BOS 序列初始化音素编码器
- 参数:
- 返回值:
encoder – 编码器
- 返回类型:
- speechbrain.lobes.models.g2p.dataio.phoneme_pipeline(phn, phoneme_encoder=None)[source]
使用提供的编码器对音素序列进行编码
- 参数:
phn (list) – 音素列表
phoneme_encoder (speechbrain.datio.encoder.TextEncoder) – 文本编码器实例(可选,如果未提供,将创建一个新的)
- Yields:
phn (list) – 原始音素列表
phn_encoded_list (list) – 编码后的音素,以列表形式
phn_encoded (torch.Tensor) – 编码后的音素,以 tensor 形式
- speechbrain.lobes.models.g2p.dataio.add_bos_eos(seq=None, encoder=None)[source]
向提供的序列添加 BOS 和 EOS 令牌
- 参数:
seq (torch.Tensor) – 源序列
encoder (speechbrain.dataio.encoder.TextEncoder) – 编码器实例
- Yields:
seq_eos (torch.Tensor) – 已添加 EOS 令牌的序列
seq_bos (torch.Tensor) – 已添加 BOS 令牌的序列
- speechbrain.lobes.models.g2p.dataio.beam_search_pipeline(char_lens, encoder_out, beam_searcher)[source]
对音素执行 Beam Search。此函数旨在用作解码流水线中的组件
- 参数:
char_lens (torch.Tensor) – 字符输入的长度
encoder_out (torch.Tensor) – 原始编码器输出
beam_searcher (speechbrain.decoders.seq2seq.S2SBeamSearcher) – 一个 SpeechBrain beam searcher 实例
- 返回值:
hyps (list) – 假设
scores (list) – 与每个假设相关的置信度分数
- speechbrain.lobes.models.g2p.dataio.build_token_char_map(tokens)[source]
构建一个将任意令牌映射到任意选择的字符的映射。这是为了克服 SentencePiece 的限制。
- speechbrain.lobes.models.g2p.dataio.text_decode(seq, encoder)[source]
使用分词器解码序列。此函数旨在用于 hparam 文件
- 参数:
seq (torch.Tensor) – 令牌索引
encoder (sb.dataio.encoder.TextEncoder) – 文本编码器实例
- 返回值:
output_seq – 令牌列表的列表
- 返回类型:
- speechbrain.lobes.models.g2p.dataio.char_map_detokenize(char_map, tokenizer, token_space_index=None, wordwise=True)[source]
返回一个函数,该函数从使用字符映射分词后的序列中恢复原始序列
- 参数:
char_map (dict) – 字符到输出令牌的映射
tokenizer (speechbrain.tokenizers.SentencePiece.SentencePiece) – 分词器实例
token_space_index (int) – “空格”令牌的索引
wordwise (bool) – 是否按单词应用去分词。
- 返回值:
f – 分词函数
- 返回类型:
callable
- class speechbrain.lobes.models.g2p.dataio.LazyInit(init)[source]
继承自:
Module
一个延迟初始化包装器
- 参数:
init (callable) – 用于初始化底层对象的函数
- speechbrain.lobes.models.g2p.dataio.lazy_init(init)[source]
一个包装器,确保指定对象只初始化一次(主要用于在调用构造函数时进行训练的分词器)
- 参数:
init (callable) – 创建对象的构造函数或函数
- 返回值:
instance – 对象实例
- 返回类型:
- speechbrain.lobes.models.g2p.dataio.phonemes_to_label(phns, decoder)[source]
将一批音素序列(单个 tensor)转换为由空格分隔的音素标签字符串列表(例如 [“T AY B L”, “B UH K”]),并移除任何特殊令牌
- 参数:
phns (torch.Tensor) – 一批音素序列
decoder (Callable) – 将 tensor 转换为音素标签字符串。
- 返回值:
result – 对应于提供的音素的字符串列表
- 返回类型:
- speechbrain.lobes.models.g2p.dataio.word_emb_pipeline(txt, grapheme_encoded, grapheme_encoded_len, grapheme_encoder=None, word_emb=None, use_word_emb=None)[source]
应用词嵌入(如果适用)。此函数旨在用作编码流水线的一部分
- 参数:
txt (str) – 原始文本
grapheme_encoded (torch.Tensor) – 编码后的字素
grapheme_encoded_len (torch.Tensor) – 编码后的字素长度
grapheme_encoder (speechbrain.dataio.encoder.TextEncoder) – 用于字素的文本编码器
word_emb (callable) – 生成词嵌入的模型
use_word_emb (bool) – 指示是否应用词嵌入的标志
- 返回值:
char_word_emb – 词嵌入,扩展到字符维度
- 返回类型:
torch.Tensor