Transformers 文档

VITS

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

该模型于 2021 年 6 月 11 日发表在 HF papers 上,并于 2023 年 9 月 1 日贡献给 Hugging Face Transformers。

VITS

VITS (Variational Inference with adversarial learning for end-to-end Text-to-Speech,基于变分推理和对抗学习的端到端语音合成) 是一种端到端语音合成模型,简化了传统的两阶段文本转语音 (TTS) 系统。它的独特之处在于,它利用变分推理、对抗学习和归一化流直接从文本合成语音,从而产生具有多样化节奏和语调的自然且富有表现力的语音。

你可以在 AI at Meta 组织下找到所有原始的 VITS 检查点 (checkpoints)。

点击右侧侧边栏中的 VITS 模型,可以获取更多关于如何应用 VITS 的示例。

下面的示例演示了如何使用 PipelineAutoModel 类基于图像生成文本。

流水线
自动模型
from scipy.io.wavfile import write

from transformers import pipeline, set_seed


set_seed(555)

pipe = pipeline(
    task="text-to-speech",
    model="facebook/mms-tts-eng",
    device=0
)

speech = pipe("Hello, my dog is cute")

# Extract audio data and sampling rate
audio_data = speech["audio"]
sampling_rate = speech["sampling_rate"]

# Save as WAV file
write("hello.wav", sampling_rate, audio_data.squeeze())

注意事项

  • 请设置一个种子以确保结果可复现,因为 VITS 合成语音的过程具有非确定性。

  • 对于使用非罗马字母的语言(韩语、阿拉伯语等),请安装 uroman 软件包,将文本输入预处理为罗马字母。你可以如下所示检查分词器 (tokenizer) 是否需要 uroman。

    # pip install -U uroman
    from transformers import VitsTokenizer
    
    tokenizer = VitsTokenizer.from_pretrained("facebook/mms-tts-eng")
    print(tokenizer.is_uroman)

    如果你的语言需要使用 uroman,分词器会自动将其应用于文本输入。Python >= 3.10 不需要任何额外的预处理步骤。对于 Python < 3.10,请按照以下步骤操作。

    git clone https://github.com/isi-nlp/uroman.git
    cd uroman
    export UROMAN=$(pwd)

    创建一个用于预处理输入的函数。你可以使用 bash 变量 UROMAN,或者直接将目录路径传递给该函数。

    import torch
    from transformers import VitsTokenizer, VitsModel, set_seed
    import os
    import subprocess
    
    tokenizer = VitsTokenizer.from_pretrained("facebook/mms-tts-kor")
    model = VitsModel.from_pretrained("facebook/mms-tts-kor", device_map="auto")
    
    def uromanize(input_string, uroman_path):
        """Convert non-Roman strings to Roman using the `uroman` perl package."""
        script_path = os.path.join(uroman_path, "bin", "uroman.pl")
    
        command = ["perl", script_path]
    
        process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        # Execute the perl command
        stdout, stderr = process.communicate(input=input_string.encode())
    
        if process.returncode != 0:
            raise ValueError(f"Error {process.returncode}: {stderr.decode()}")
    
        # Return the output as a string and skip the new-line character at the end
        return stdout.decode()[:-1]
    
    text = "이봐 무슨 일이야"
    uromanized_text = uromanize(text, uroman_path=os.environ["UROMAN"])
    
    inputs = tokenizer(text=uromanized_text, return_tensors="pt").to(model.device)
    
    set_seed(555)  # make deterministic
    with torch.no_grad():
       outputs = model(inputs["input_ids"])
    
    waveform = outputs.waveform[0]

VitsConfig

class transformers.VitsConfig

< >

( transformers_version: str | None = None architectures: list[str] | None = None output_hidden_states: bool | None = False return_dict: bool | None = True dtype: typing.Union[str, ForwardRef('torch.dtype'), NoneType] = None chunk_size_feed_forward: int = 0 is_encoder_decoder: bool = False id2label: dict[int, str] | dict[str, str] | None = None label2id: dict[str, int] | dict[str, str] | None = None problem_type: typing.Optional[typing.Literal['regression', 'single_label_classification', 'multi_label_classification']] = None vocab_size: int = 38 hidden_size: int = 192 num_hidden_layers: int = 6 num_attention_heads: int = 2 window_size: int = 4 use_bias: bool = True ffn_dim: int = 768 layerdrop: float | int = 0.1 ffn_kernel_size: int = 3 flow_size: int = 192 spectrogram_bins: int = 513 hidden_act: str = 'relu' hidden_dropout: float | int = 0.1 attention_dropout: float | int = 0.1 activation_dropout: float | int = 0.1 initializer_range: float = 0.02 layer_norm_eps: float = 1e-05 use_stochastic_duration_prediction: bool = True num_speakers: int = 1 speaker_embedding_size: int = 0 upsample_initial_channel: int = 512 upsample_rates: list[int] | tuple[int, ...] = (8, 8, 2, 2) upsample_kernel_sizes: list[int] | tuple[int, ...] = (16, 16, 4, 4) resblock_kernel_sizes: list[int] | tuple[int, ...] = (3, 7, 11) resblock_dilation_sizes: list | tuple = ((1, 3, 5), (1, 3, 5), (1, 3, 5)) leaky_relu_slope: float = 0.1 depth_separable_channels: int = 2 depth_separable_num_layers: int = 3 duration_predictor_flow_bins: int = 10 duration_predictor_tail_bound: float = 5.0 duration_predictor_kernel_size: int = 3 duration_predictor_dropout: float | int = 0.5 duration_predictor_num_flows: int = 4 duration_predictor_filter_channels: int = 256 prior_encoder_num_flows: int = 4 prior_encoder_num_wavenet_layers: int = 4 posterior_encoder_num_wavenet_layers: int = 16 wavenet_kernel_size: int = 5 wavenet_dilation_rate: int = 1 wavenet_dropout: float | int = 0.0 speaking_rate: float | int = 1.0 noise_scale: float = 0.667 noise_scale_duration: float = 0.8 sampling_rate: int = 16000 pad_token_id: int | None = None )

参数

  • vocab_size (int, 可选, 默认为 38) — 模型的词汇表大小。定义了 input_ids 可以表示的不同 token 的数量。
  • hidden_size (int, 可选, 默认为 192) — 隐藏层表示的维度。
  • num_hidden_layers (int, 可选, 默认为 6) — Transformer 解码器中的隐藏层数量。
  • num_attention_heads (int, 可选, 默认为 2) — Transformer 解码器中每个注意力层的注意力头数量。
  • window_size (int, 可选, 默认为 4) — Transformer 编码器注意力层中相对位置编码的窗口大小。
  • use_bias (bool, 可选, 默认为 True) — 是否在 Transformer 编码器的键、查询、值投影层中使用偏置 (bias)。
  • ffn_dim (int, 可选, 默认为 768) — MLP 表示的维度。
  • layerdrop (Union[float, int], 可选, 默认为 0.1) — LayerDrop 概率。详情请参阅 [LayerDrop 论文](https://huggingface.co/papers/1909.11556)。
  • ffn_kernel_size (int, 可选, 默认为 3) — Transformer 编码器中前馈网络所使用的 1D 卷积层的卷积核大小。
  • flow_size (int, 可选, 默认为 192) — 流层 (flow layers) 的维度。
  • spectrogram_bins (int, 可选, 默认为 513) — 目标频谱图中的频率仓 (frequency bins) 数量。
  • hidden_act (str, 可选, 默认为 relu) — 解码器中的非线性激活函数(函数或字符串)。例如:"gelu", "relu", "silu" 等。
  • hidden_dropout (Union[float, int], 可选, 默认为 0.1) — 用于 embeddings、编码器和池化器中所有全连接层的 dropout 概率。
  • attention_dropout (Union[float, int], 可选, 默认为 0.1) — 注意力概率的 dropout 比率。
  • activation_dropout (Union[float, int], 可选, 默认为 0.1) — 全连接层内激活值的 dropout 比率。
  • initializer_range (float, 可选, 默认为 0.02) — 用于初始化所有权重矩阵的 truncated_normal_initializer 的标准差。
  • layer_norm_eps (float, 可选, 默认为 1e-05) — 层归一化层使用的 epsilon 值。
  • use_stochastic_duration_prediction (bool, 可选, 默认为 True) — 是否使用随机持续时间预测模块或常规的持续时间预测器。
  • num_speakers (int, 可选, 默认为 1) — 如果这是一个多说话人模型,则为说话人数量。
  • speaker_embedding_size (int, 可选, 默认为 0) — 说话人嵌入所使用的通道数。对于单说话人模型,该值为零。
  • upsample_initial_channel (int, 可选, 默认为 512) — 进入 HiFi-GAN 上采样网络的输入通道数。
  • upsample_rates (tuple[int]list[int]可选,默认为 [8, 8, 2, 2]) — 定义 HiFi-GAN 上采样网络中每个一维卷积层步幅的整数元组。upsample_rates 的长度定义了卷积层的数量,必须与 upsample_kernel_sizes 的长度相匹配。
  • upsample_kernel_sizes (tuple[int]list[int]可选,默认为 [16, 16, 4, 4]) — 定义 HiFi-GAN 上采样网络中每个一维卷积层核大小的整数元组。upsample_kernel_sizes 的长度定义了卷积层的数量,必须与 upsample_rates 的长度相匹配。
  • resblock_kernel_sizes (tuple[int]list[int]可选,默认为 [3, 7, 11]) — 定义 HiFi-GAN 多感受野融合 (MRF) 模块中一维卷积层核大小的整数元组。
  • resblock_dilation_sizes (tuple[tuple[int]]list[list[int]]可选,默认为 [[1, 3, 5], [1, 3, 5], [1, 3, 5]]) — 定义 HiFi-GAN 多感受野融合 (MRF) 模块中空洞一维卷积层膨胀率的嵌套整数元组。
  • leaky_relu_slope (float可选,默认为 0.1) — Leaky ReLU 激活函数所使用的负斜率角度。
  • depth_separable_channels (int可选,默认为 2) — 每个深度可分离块中使用的通道数。
  • depth_separable_num_layers (int可选,默认为 3) — 每个深度可分离块中使用的卷积层数量。
  • duration_predictor_flow_bins (int可选,默认为 10) — 时长预测器模型中通过无约束有理样条进行映射的通道数。
  • duration_predictor_tail_bound (float可选,默认为 5.0) — 时长预测器模型中计算无约束有理样条时尾部箱的边界值。
  • duration_predictor_kernel_size (int可选,默认为 3) — 时长预测器模型中使用的一维卷积层的核大小。
  • duration_predictor_dropout (float可选,默认为 0.5) — 时长预测器模型的 Dropout 比率。
  • duration_predictor_num_flows (int可选,默认为 4) — 时长预测器模型使用的流阶段数量。
  • duration_predictor_filter_channels (int可选,默认为 256) — 时长预测器模型中卷积层使用的通道数。
  • prior_encoder_num_flows (int可选,默认为 4) — 先验编码器流模型使用的流阶段数量。
  • prior_encoder_num_wavenet_layers (int可选,默认为 4) — 先验编码器流模型使用的 WaveNet 层数量。
  • posterior_encoder_num_wavenet_layers (int可选,默认为 16) — 后验编码器模型使用的 WaveNet 层数量。
  • wavenet_kernel_size (int可选,默认为 5) — WaveNet 模型中使用的一维卷积层的核大小。
  • wavenet_dilation_rate (int可选,默认为 1) — WaveNet 模型中使用的空洞一维卷积层的膨胀率。
  • wavenet_dropout (float可选,默认为 0.0) — WaveNet 层的 Dropout 比率。
  • speaking_rate (float可选,默认为 1.0) — 语速。数值越大,合成的语音速度越快。
  • noise_scale (float可选,默认为 0.667) — 语音预测的随机程度。数值越大,预测的语音变化越丰富。
  • noise_scale_duration (float可选,默认为 0.8) — 时长预测的随机程度。数值越大,预测的时长变化越丰富。
  • sampling_rate (int可选,默认为 16000) — 音频文件数字化的采样率,以赫兹 (Hz) 为单位。
  • pad_token_id (int可选) — 词汇表中用于填充 (padding) 的标记 ID。

这是用于存储 VitsModel 配置的配置类。它根据指定的参数实例化 Vits 模型,定义模型架构。使用默认值实例化配置将产生与 facebook/mms-tts-eng 类似的配置。

配置对象继承自 PreTrainedConfig,可用于控制模型输出。阅读 PreTrainedConfig 的文档以获取更多信息。

示例

>>> from transformers import VitsModel, VitsConfig

>>> # Initializing a "facebook/mms-tts-eng" style configuration
>>> configuration = VitsConfig()

>>> # Initializing a model (with random weights) from the "facebook/mms-tts-eng" style configuration
>>> model = VitsModel(configuration)

>>> # Accessing the model configuration
>>> configuration = model.config

VitsTokenizer

class transformers.VitsTokenizer

< >

( vocab_file pad_token = '<pad>' unk_token = '<unk>' language = None add_blank = True normalize = True phonemize = True is_uroman = False **kwargs )

参数

  • vocab_file (str) — 词汇表文件的路径。
  • language (str可选) — 语言标识符。
  • add_blank (bool, 可选, 默认为 True) — 是否在其他 token 之间插入 token id 0。
  • normalize (bool, 可选, 默认为 True) — 是否通过移除所有大小写和标点符号来对输入文本进行归一化。
  • phonemize (bool, 可选, 默认为 True) — 是否将输入文本转换为音素。
  • is_uroman (bool, 可选, 默认为 False) — 在分词之前是否需要对输入文本应用 uroman 罗马化工具。

构建一个 VITS 分词器。同时也支持 MMS-TTS。

该分词器继承自 PreTrainedTokenizer,其中包含大部分主要方法。用户应参考此超类以获取有关这些方法的更多信息。

__call__

< >

( text: TextInput | PreTokenizedInput | list[TextInput] | list[PreTokenizedInput] | None = None text_pair: TextInput | PreTokenizedInput | list[TextInput] | list[PreTokenizedInput] | None = None text_target: TextInput | PreTokenizedInput | list[TextInput] | list[PreTokenizedInput] | None = None text_pair_target: TextInput | PreTokenizedInput | list[TextInput] | list[PreTokenizedInput] | None = None add_special_tokens: bool = True padding: bool | str | PaddingStrategy = False truncation: bool | str | TruncationStrategy | None = None max_length: int | None = None stride: int = 0 is_split_into_words: bool = False pad_to_multiple_of: int | None = None padding_side: str | None = None return_tensors: str | TensorType | None = None return_token_type_ids: bool | None = None return_attention_mask: bool | None = None return_overflowing_tokens: bool = False return_special_tokens_mask: bool = False return_offsets_mapping: bool = False return_length: bool = False verbose: bool = True tokenizer_kwargs: dict[str, Any] | None = None **kwargs ) BatchEncoding

参数

  • text (str, list[str], list[list[str]], 可选) — 需要编码的序列或序列批次。每个序列可以是字符串或字符串列表(预分词字符串)。如果序列以字符串列表的形式提供(预分词),则必须设置 is_split_into_words=True(以消除与序列批次的歧义)。
  • text_pair (str, list[str], list[list[str]], 可选) — 需要编码的序列或序列批次。每个序列可以是字符串或字符串列表(预分词字符串)。如果序列以字符串列表的形式提供(预分词),则必须设置 is_split_into_words=True(以消除与序列批次的歧义)。
  • text_target (str, list[str], list[list[str]], 可选) — 作为目标文本进行编码的序列或序列批次。每个序列可以是字符串或字符串列表(预分词字符串)。如果序列以字符串列表的形式提供(预分词),则必须设置 is_split_into_words=True(以消除与序列批次的歧义)。
  • text_pair_target (str, list[str], list[list[str]], 可选) — 作为目标文本进行编码的序列或序列批次。每个序列可以是字符串或字符串列表(预分词字符串)。如果序列以字符串列表的形式提供(预分词),则必须设置 is_split_into_words=True(以消除与序列批次的歧义)。
  • tokenizer_kwargs (dict[str, Any], 可选) — 传递给分词器的额外 kwargs。这些参数将与显式参数和其他 kwargs 合并,显式参数具有最高优先级。
  • add_special_tokens (bool, 可选, 默认为 True) — 在对序列进行编码时是否添加特殊 token。这将使用底层的 PretrainedTokenizerBase.build_inputs_with_special_tokens 函数,该函数定义了哪些 token 会自动添加到输入 ID 中。如果您想自动添加 boseos token,这非常有用。
  • padding (bool, strPaddingStrategy, 可选, 默认为 False) — 激活并控制填充。接受以下值:

    • True'longest':填充至批次中最长的序列(如果仅提供单个序列,则不进行填充)。
    • 'max_length':填充至参数 max_length 指定的最大长度,如果未提供该参数,则填充至模型可接受的最大输入长度。
    • False'do_not_pad' (默认):不进行填充(即,可能输出长度不同的序列批次)。
  • truncation (bool, strTruncationStrategy, 可选, 默认为 False) — 激活并控制截断。接受以下值:

    • True'longest_first':截断至参数 max_length 指定的最大长度,或模型可接受的最大输入长度(如果未提供该参数)。这将逐个 token 进行截断,如果提供了序列对(或批次序列对),则从最长的序列中移除一个 token。
    • 'only_first':截断至参数 max_length 指定的最大长度,或模型可接受的最大输入长度(如果未提供该参数)。如果提供了序列对(或批次序列对),则仅截断第一个序列。
    • 'only_second':截断至参数 max_length 指定的最大长度,或模型可接受的最大输入长度(如果未提供该参数)。如果提供了序列对(或批次序列对),则仅截断第二个序列。
    • False'do_not_truncate' (默认):不进行截断(即,可能输出超过模型最大允许输入长度的序列)。
  • max_length (int, 可选) — 控制截断/填充参数所使用的最大长度。

    如果未设置或设置为 None,当截断/填充参数需要最大长度时,将使用预定义的模型最大长度。如果模型没有特定的最大输入长度(如 XLNet),则将禁用截断/填充至最大长度的功能。

  • stride (int, 可选, 默认为 0) — 如果与 max_length 一起设置,当 return_overflowing_tokens=True 时返回的溢出 token 将包含被截断序列末尾的一些 token,以便在截断序列和溢出序列之间提供一定的重叠。此参数的值定义了重叠 token 的数量。
  • is_split_into_words (bool, 可选, 默认为 False) — 输入是否已经是预分词的(例如,已拆分为单词)。如果设置为 True,分词器将假设输入已经拆分为单词(例如,通过空白字符拆分),并在此基础上进行分词。这对于命名实体识别 (NER) 或 token 分类任务非常有用。
  • pad_to_multiple_of (int, 可选) — 如果设置,将填充序列至提供的数值的倍数。需要激活 padding。这对于在计算能力 >= 7.5 (Volta) 的 NVIDIA 硬件上启用 Tensor Cores 的使用特别有用。
  • padding_side (str, 可选) — 模型应该在侧边应用填充。应该在 ['right', 'left'] 中选择。默认值取自同名的类属性。
  • return_tensors (strTensorType, 可选) — 如果设置,将返回张量而不是 Python 整数列表。可接受的值为:

    • 'pt':返回 PyTorch torch.Tensor 对象。
    • 'np':返回 Numpy np.ndarray 对象。
  • return_token_type_ids (bool, 可选) — 是否返回 token 类型 ID。如果保留默认值,将根据特定分词器的默认值(由 return_outputs 属性定义)返回 token 类型 ID。

    什么是 token 类型 ID?

  • return_attention_mask (bool, 可选) — 是否返回注意力掩码。如果保留默认值,将根据特定分词器的默认值(由 return_outputs 属性定义)返回注意力掩码。

    什么是注意力掩码?

  • return_overflowing_tokens (bool, 可选, 默认为 False) — 是否返回溢出的 token 序列。如果提供了输入 ID 的序列对(或批次对)并且设置了 truncation_strategy = longest_firstTrue,则会抛出错误,而不是返回溢出的 token。
  • return_special_tokens_mask (bool, 可选, 默认为 False) — 是否返回特殊 token 掩码信息。
  • return_offsets_mapping (bool, 可选, 默认为 False) — 是否返回每个 token 的 (char_start, char_end)

    这仅在继承自 PreTrainedTokenizerFast 的快速分词器上可用。如果使用 Python 的分词器,此方法将抛出 NotImplementedError

  • return_length (bool, 可选, 默认为 False) — 是否返回已编码输入的长度。
  • verbose (bool, 可选, 默认为 True) — 是否打印更多信息和警告。
  • **kwargs — 传递给 self.tokenize() 方法

返回

BatchEncoding

具有以下字段的 BatchEncoding

  • input_ids — 要输入到模型中的标记 ID 列表。

    什么是输入 ID?

  • token_type_ids — 要输入到模型中的标记类型 ID 列表(当 return_token_type_ids=True 或如果 *“token_type_ids”* 在 self.model_input_names 中时)。

    什么是标记类型 ID?

  • attention_mask — 指定模型应关注哪些标记的索引列表(当 return_attention_mask=True 或如果 *“attention_mask”* 在 self.model_input_names 中时)。

    什么是注意力掩码?

  • overflowing_tokens — 溢出标记序列列表(当指定 max_lengthreturn_overflowing_tokens=True 时)。

  • num_truncated_tokens — 截断标记的数量(当指定 max_lengthreturn_overflowing_tokens=True 时)。

  • special_tokens_mask — 0 和 1 的列表,其中 1 表示添加的特殊标记,0 表示常规序列标记(当 add_special_tokens=Truereturn_special_tokens_mask=True 时)。

  • length — 输入的长度(当 return_length=True 时)

将一个或多个序列或一对或多对序列标记化并准备用于模型的主要方法。

save_vocabulary

< >

( save_directory: str filename_prefix: str | None = None )

VitsModel

class transformers.VitsModel

< >

( config: VitsConfig )

参数

  • config (VitsConfig) — 包含模型所有参数的模型配置类。使用配置文件进行初始化不会加载与模型相关的权重,只会加载配置。请查看 from_pretrained() 方法以加载模型权重。

完整的 VITS 模型,用于文本转语音(TTS)合成。

该模型继承自 PreTrainedModel。请查看超类文档以了解该库为所有模型实现的通用方法(例如下载或保存、调整输入嵌入大小、剪枝头部等)。

此模型也是一个 PyTorch torch.nn.Module 子类。像普通的 PyTorch Module 一样使用它,并参考 PyTorch 文档了解一般用法和行为的所有相关信息。

forward

< >

( input_ids: torch.Tensor | None = None attention_mask: torch.Tensor | None = None speaker_id: int | None = None output_attentions: bool | None = None output_hidden_states: bool | None = None return_dict: bool | None = None labels: torch.FloatTensor | None = None speaking_rate: float | None = None **kwargs ) VitsModelOutputtuple(torch.FloatTensor)

参数

  • input_ids (torch.Tensor,形状为 (batch_size, sequence_length)可选) — 输入序列标记在词汇表中的索引。默认情况下填充将被忽略。

    索引可以使用 AutoTokenizer 获取。详细信息请参阅 PreTrainedTokenizer.encode()PreTrainedTokenizer.call()

    什么是输入 ID?

  • attention_mask (torch.Tensor,形状为 (batch_size, sequence_length)可选) — 用于避免对填充标记索引执行注意力计算的掩码。掩码值选自 [0, 1]

    • 1 表示未遮蔽的标记,
    • 0 表示遮蔽的标记。

    什么是注意力掩码?

  • speaker_id (int, 可选) — 要使用的说话人嵌入(embedding)。仅用于多说话人模型。
  • output_attentions (bool, 可选) — 是否返回所有注意力层的注意力张量。有关更多详细信息,请参见返回张量下的 attentions
  • output_hidden_states (bool, 可选) — 是否返回所有层的隐藏状态。有关更多详细信息,请参见返回张量下的 hidden_states
  • return_dict (bool, 可选) — 是否返回 ModelOutput 而不是普通的元组。
  • labels (torch.FloatTensor,形状为 (batch_size, config.spectrogram_bins, sequence_length)可选) — 目标声谱图的浮点值。设置为 -100.0 的时间步长在损失计算中将被忽略(遮蔽)。
  • speaking_rate (float, 可选) — 语速。

返回

VitsModelOutputtuple(torch.FloatTensor)

一个 VitsModelOutput 或一个 torch.FloatTensor 元组(如果传递了 return_dict=False 或当 config.return_dict=False 时),根据配置(VitsConfig)和输入,包含各种元素。

VitsModel 的前向传播方法,覆盖了 __call__ 特殊方法。

虽然 forward pass 的实现需要在此函数中定义,但你应该在之后调用 Module 实例而不是这个,因为前者负责运行预处理和后处理步骤,而后者会静默地忽略它们。

  • waveform (torch.FloatTensor,形状为 (batch_size, sequence_length)) — 模型预测的最终音频波形。

  • sequence_lengths (torch.FloatTensor,形状为 (batch_size,)) — waveform 批次中每个元素的样本长度。

  • spectrogram (torch.FloatTensor,形状为 (batch_size, sequence_length, num_bins)) — 在流模型(flow model)输出处预测的对数梅尔声谱图。该声谱图被传递给 Hi-Fi GAN 解码器模型以获得最终的音频波形。

  • hidden_states (tuple[torch.FloatTensor]可选,在传入 output_hidden_states=Trueconfig.output_hidden_states=True 时返回) — torch.FloatTensor 元组(一个用于嵌入层的输出(如果模型有嵌入层的话) + 一个用于每层输出),形状为 (batch_size, sequence_length, hidden_size)

    模型在每个层输出的隐藏状态以及可选的初始嵌入输出。

  • attentions (tuple[torch.FloatTensor]可选,在传入 output_attentions=Trueconfig.output_attentions=True 时返回) — torch.FloatTensor 元组(每层一个),形状为 (batch_size, num_heads, sequence_length, sequence_length)

    注意力 softmax 后的注意力权重,用于计算自注意力头中的加权平均值。

示例

>>> from transformers import VitsTokenizer, VitsModel, set_seed
>>> import torch

>>> tokenizer = VitsTokenizer.from_pretrained("facebook/mms-tts-eng")
>>> model = VitsModel.from_pretrained("facebook/mms-tts-eng")

>>> inputs = tokenizer(text="Hello - my dog is cute", return_tensors="pt")

>>> set_seed(555)  # make deterministic

>>> with torch.no_grad():
...     outputs = model(inputs["input_ids"])
>>> outputs.waveform.shape
torch.Size([1, 45824])
在 GitHub 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.