paddlespeech.s2t.models.lm_interface模块

语言模型接口。

class paddlespeech.s2t.models.lm_interface.LMInterface[来源]

基础: ScorerInterface

LM接口模型实现。

方法

add_arguments(parser)

向命令行参数解析器添加参数。

build(n_vocab, **kwargs)

使用 Python 级别的参数初始化此类。

final_score(state)

得分 eos(可选)。

forward(x, t)

从缓存序列计算LM损失值。

init_state(x)

获取用于解码的初始状态(可选)。

score(y, state, x)

评分新令牌(必需)。

select_state(state, i[, new_id])

在主光束搜索中选择具有相对ID的状态。

static add_arguments(parser)[来源]

向命令行参数解析器添加参数。

classmethod build(n_vocab: int, **kwargs)[来源]

用python级别的参数初始化此类。

Args:

idim (int):词汇的数量。

Returns:

LMinterface: LMInterface的新实例。

forward(x, t)[来源]

从缓冲序列计算LM损失值。

Args:

x (torch.Tensor): 输入ids. (batch, len) t (torch.Tensor): 目标ids. (batch, len)

Returns:
tuple[torch.Tensor, torch.Tensor, torch.Tensor]: Tuple of

损失反向传播(标量),t的负对数似然:-log p(t)(标量)和x中的元素数量(标量)

Notes:

最后两个返回值用于困惑度: p(t)^{-n} = exp(-log p(t) / n)

paddlespeech.s2t.models.lm_interface.dynamic_import_lm(module)[来源]

动态导入LM类。

Args:

模块 (str): module_name:class_name 或 predefined_lms 中的别名

Returns:

类型:LM 类