CLVP (Contrastive Language-Voice Pretrained Transformer) モデルは、James Betker によって Better speech synthesis through scaling で提案されました。
論文の要約は次のとおりです。
*近年、画像生成の分野は自己回帰変換器と DDPM の応用によって革命を起こしています。これらのアプローチは、画像生成のプロセスを段階的な確率的プロセスとしてモデル化し、大量のコンピューティングとデータを活用して画像の分布を学習します。パフォーマンスを向上させるこの方法論は、画像に限定される必要はありません。この論文では、画像生成ドメインの進歩を音声合成に適用する方法について説明します。その結果、表現力豊かなマルチ音声テキスト読み上げシステムである TorToise が誕生しました。
このモデルは Susnato Dhar によって提供されました。 元のコードは ここ にあります。
ClvpModelForConditionalGeneration.generate()
メソッドの使用を強くお勧めします。ClvpConditioningEncoder
は、これらのテキスト トークンとオーディオ表現を取得し、テキストとオーディオに基づいて条件付けされた埋め込みに変換します。ClvpModelForConditionalGeneration.generate()
は、上記のすべてのロジックを 1 つのメソッドに圧縮します。例 :
>>> import datasets
>>> from transformers import ClvpProcessor, ClvpModelForConditionalGeneration
>>> # Define the Text and Load the Audio (We are taking an audio example from HuggingFace Hub using `datasets` library).
>>> text = "This is an example text."
>>> ds = datasets.load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
>>> ds = ds.cast_column("audio", datasets.Audio(sampling_rate=22050))
>>> sample = ds[0]["audio"]
>>> # Define processor and model.
>>> processor = ClvpProcessor.from_pretrained("susnato/clvp_dev")
>>> model = ClvpModelForConditionalGeneration.from_pretrained("susnato/clvp_dev")
>>> # Generate processor output and model output.
>>> processor_output = processor(raw_speech=sample["array"], sampling_rate=sample["sampling_rate"], text=text, return_tensors="pt")
>>> generated_output = model.generate(**processor_output)
( text_config = None speech_config = None decoder_config = None projection_dim = 768 logit_scale_init_value = 2.6592 initializer_factor = 1.0 **kwargs )
Parameters
dict
, optional) —
Dictionary of configuration options used to initialize the CLVP text encoder. dict
, optional) —
Dictionary of configuration options used to initialize CLVP speech encoder. dict
, optional) —
Dictionary of configuration options used to initialize ClvpDecoderConfig. int
, optional, defaults to 768) —
Dimentionality of text and speech projection layers. float
, optional, defaults to 2.6592) —
The inital value of the logit_scale paramter. Default is used as per the original CLVP implementation. float
, optional, defaults to 1.0) —
A factor for initializing all weight matrices (should be kept to 1.0, used internally for initialization
testing). ClvpConfig is the configuration class to store the configuration of a ClvpModelForConditionalGeneration. It is used to instantiate a CLVP model according to the specified arguments, defining the text model, speech model and decoder model configs. Instantiating a configuration with the defaults will yield a similar configuration to that of the CLVP susnato/clvp_dev architecture.
Configuration objects inherit from PretrainedConfig and can be used to control the model outputs. Read the documentation from PretrainedConfig for more information.
Example:
>>> from transformers import ClvpConfig, ClvpModelForConditionalGeneration
>>> # Initializing a ClvpConfig with susnato/clvp_dev style configuration
>>> configuration = ClvpConfig()
>>> # Initializing a ClvpModelForConditionalGeneration (with random weights) from the susnato/clvp_dev style configuration
>>> model = ClvpModelForConditionalGeneration(configuration)
>>> # Accessing the model configuration
>>> configuration = model.config
>>> # We can also initialize a CLVPConfig from a CLVPTextConfig, CLVPSpeechConfig and a CLVPAutoRegressiveConfig
>>> from transformers import ClvpEncoderConfig, ClvpDecoderConfig
>>> # Initializing a CLVP text, CLVP speech and CLVP decoder configuration
>>> config_text = ClvpEncoderConfig()
>>> config_speech = ClvpEncoderConfig()
>>> decoder_config = ClvpDecoderConfig()
>>> config = ClvpConfig.from_sub_model_configs(config_text, config_speech, decoder_config)
( text_config: ClvpEncoderConfig speech_config: ClvpEncoderConfig decoder_config: ClvpDecoderConfig **kwargs ) → ClvpConfig
Parameters
ClvpEncoderConfig
) —
Text model configuration of type ClvpEncoderConfig. ClvpEncoderConfig
) —
Speech model configuration of type ClvpEncoderConfig. ClvpDecoderConfig
) —
Decoder model configuration of type ClvpDecoderConfig. Returns
An instance of a configuration object
Instantiate a ClvpConfig (or a derived class) from CLVP text model configuration, CLVP speech model configuration and CLVP decoder model configuration.
( vocab_size = 256 hidden_size = 768 intermediate_size = 1536 projection_dim = 768 num_hidden_layers = 20 num_attention_heads = 12 hidden_act = 'gelu' layer_norm_eps = 1e-05 attention_dropout = 0.1 dropout = 0.1 use_rotary_embedding = True use_attention_bias = False summary_type = 'mean' initializer_factor = 1.0 bos_token_id = 255 eos_token_id = 0 **kwargs )
Parameters
int
, optional, defaults to 256) —
Vocabulary size of the CLVP Encoder model. int
, optional, defaults to 768) —
Dimensionality of the encoder layers and the pooler layer. int
, optional, defaults to 1536) —
Dimensionality of the “intermediate” (i.e., feed-forward) layer in the Transformer encoder. int
, optional, defaults to 768) —
Dimensionality of the projection vector. int
, optional, defaults to 20) —
Number of hidden layers in the Transformer encoder. int
, optional, defaults to 12) —
Number of attention heads for each attention layer in the Transformer encoder. str
or function
, optional, defaults to "gelu"
) —
The non-linear activation function (function or string) in the encoder and pooler. If string, "gelu"
,
"relu"
, "selu"
and "gelu_new"
"quick_gelu"
are supported. float
, optional, defaults to 1e-05) —
The epsilon used by the layer normalization layers. float
, optional, defaults to 0.1) —
The dropout ratio for the attention probabilities. float
, optional, defaults to 0.1) —
The dropout ratio for the feed-forward layers in ClvpEncoderMLP
. bool
, optional, defaults to True
) —
Whether to use rotary_embedding or not. bool
, optional, defaults to False
) —
Whether to use bias in Query, Key and Value layers during self attention. str
, optional, defaults to "mean"
) —
What strategy to use to get pooler_output from the last_hidden_state. "last"
, "first"
, "mean"
and
"cls_index"
are supported. float
, optional, defaults to 1.0) —
A factor for initializing all weight matrices (should be kept to 1.0, used internally for initialization
testing). int
, optional, defaults to 255) —
Beginning of sequence token id. int
, optional, defaults to 0) —
End of sequence token id. This is the configuration class to store the configuration of a ClvpEncoder. It is used to instantiate a CLVP text or CLVP speech encoder according to the specified arguments. Instantiating a configuration with the defaults will yield a similar configuration to that of the encoder of the CLVP susnato/clvp_dev architecture.
Configuration objects inherit from PretrainedConfig and can be used to control the model outputs. Read the documentation from PretrainedConfig for more information.
Example:
>>> from transformers import ClvpEncoderConfig, ClvpEncoder
>>> # Initializing a ClvpEncoderConfig with susnato/clvp_dev style configuration
>>> encoder_configuration = ClvpEncoderConfig()
>>> # Initializing a ClvpEncoder (with random weights) from the susnato/clvp_dev style configuration
>>> model = ClvpEncoder(encoder_configuration)
>>> # Accessing the model configuration
>>> configuration = model.config
( vocab_size = 8194 max_position_embeddings = 608 max_text_tokens = 404 hidden_size = 1024 num_hidden_layers = 30 num_attention_heads = 16 n_inner = None num_mel_attn_blocks = 6 activation_function = 'gelu_new' resid_pdrop = 0.1 embd_pdrop = 0.1 attention_dropout = 0.1 layer_norm_epsilon = 1e-05 initializer_range = 0.02 summary_type = 'cls_index' summary_use_proj = True summary_activation = None summary_proj_to_labels = True summary_first_dropout = 0.1 use_cache = True bos_token_id = 8192 eos_token_id = 8193 feature_size = 80 use_attention_bias = True initializer_factor = 1.0 decoder_fixing_codes = [83, 45, 45, 248] **kwargs )
Parameters
int
, optional, defaults to 8194) —
Vocabulary size of the model. int
, optional, defaults to 608) —
The maximum sequence length of mel tokens that this model might ever be used with. Similar to n_positions
in GPT2Config
. int
, optional, defaults to 404) —
The maximum sequence length of text tokens that this model might ever be used with. Similar to
n_positions
in GPT2Config
. int
, optional, defaults to 1024) —
Dimensionality of the embeddings and hidden states. int
, optional, defaults to 30) —
Number of hidden layers in the Transformer encoder. int
, optional, defaults to 16) —
Number of attention heads for each attention layer in the Transformer encoder. int
, optional) —
Dimensionality of the inner feed-forward layers. None
will set it to 4 times hidden_size
. int
, optional, defaults to 6) —
Denotes the number of self attention layers in ClvpConditioningEncoder
. str
, optional, defaults to "gelu_new"
) —
Activation function, to be selected in the list ["relu", "silu", "gelu", "tanh", "gelu_new"]
. float
, optional, defaults to 0.1) —
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler. float
, optional, defaults to 0.1) —
The dropout ratio for the embeddings. float
, optional, defaults to 0.1) —
The dropout ratio for the attention. float
, optional, defaults to 1e-05) —
The epsilon to use in the layer normalization layers. float
, optional, defaults to 0.02) —
The standard deviation of the truncated_normal_initializer for initializing all weight matrices. string
, optional, defaults to "cls_index"
) —
Argument used when doing sequence summary.
Has to be one of the following options:
"last"
: Take the last token hidden state (like XLNet)."first"
: Take the first token hidden state (like BERT)."mean"
: Take the mean of all tokens hidden states."cls_index"
: Supply a Tensor of classification token position (like GPT/GPT-2)."attn"
: Not implemented now, use multi-head attention.bool
, optional, defaults to True
) —
Whether or not to add a projection after the vector extraction. str
, optional) —
Pass "tanh"
for a tanh activation to the output, any other value will result in no activation. bool
, optional, defaults to True
) —
Whether the projection outputs should have config.num_labels
or config.hidden_size
classes. float
, optional, defaults to 0.1) —
The dropout ratio to be used after the projection and activation. bool
, optional, defaults to True
) —
Whether or not the model should return the last key/values attentions (not used by all models). int
, optional, defaults to 8192) —
Beginning of sequence token id, used at the start of the generation. int
, optional, defaults to 8193) —
End of sequence token id, used in the method
ClvpModelForConditionalGeneration.fix_speech_decoder_output()
to correct decoder outputs. int
, optional, defaults to 80) —
The feature dimension of the extracted mel features. This value is used in ClvpConditioningEncoder
. bool
, optional, defaults to True
) —
Whether to use bias in Query, Key and Value layers during self attention. float
, optional, defaults to 1.0) —
A factor for initializing all weight matrices (should be kept to 1.0, used internally for initialization
testing). list
, optional, defaults to [83, 45, 45, 248]
) —
These values are used in the method fix_speech_decoder_output
to fix decoder generated outputs. This is the configuration class to store the configuration of a ClvpDecoder. It is used to instantiate a CLVP Decoder Model according to the specified arguments, defining the model architecture. Instantiating a configuration with the defaults will yield a similar configuration to that of the Decoder part of the CLVP susnato/clvp_dev architecture.
Configuration objects inherit from PretrainedConfig and can be used to control the model outputs. Read the documentation from PretrainedConfig for more information.
The architecture is similar to GPT2.
Example:
>>> from transformers import ClvpDecoderConfig, ClvpDecoder
>>> # Initializing a ClvpDecoderConfig with susnato/clvp_dev style configuration
>>> decoder_configuration = ClvpDecoderConfig()
>>> # Initializing a ClvpDecoder (with random weights) from the susnato/clvp_dev style configuration
>>> model = ClvpDecoder(decoder_configuration)
>>> # Accessing the model configuration
>>> configuration = model.config
( vocab_file merges_file errors = 'replace' unk_token = '[UNK]' bos_token = '<|endoftext|>' eos_token = '[STOP]' pad_token = '[STOP]' add_prefix_space = False add_bos_token = False add_eos_token = False **kwargs )
Parameters
str
) —
Path to the vocabulary file. str
) —
Path to the merges file. str
, optional, defaults to "replace"
) —
Paradigm to follow when decoding bytes to UTF-8. See
bytes.decode for more information. str
, optional, defaults to "[UNK]"
) —
The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this
token instead. str
, optional, defaults to "<|endoftext|>"
) —
The beginning of sequence token. str
, optional, defaults to "[STOP]"
) —
The end of sequence token. str
, optional, defaults to "[STOP]"
) —
The pad token of the sequence. bool
, optional, defaults to False
) —
Whether or not to add an initial space to the input. This allows to treat the leading word just as any
other word. (CLVP tokenizer detect beginning of words by the preceding space). bool
, optional, defaults to False
) —
Whether to add bos_token
in front of the sequence when add_special_tokens=True. bool
, optional, defaults to False
) —
Whether to add eos_token
in end of the sequence when add_special_tokens=True. Construct a CLVP tokenizer. Based on byte-level Byte-Pair-Encoding.
This tokenizer has been trained to treat spaces like parts of the tokens (a bit like sentencepiece) so a word will
be encoded differently whether it is at the beginning of the sentence (without space) or not:
>>> from transformers import ClvpTokenizer
>>> tokenizer = ClvpTokenizer.from_pretrained("susnato/clvp_dev")
>>> tokenizer("Hello world")["input_ids"]
[62, 84, 28, 2, 179, 79]
>>> tokenizer(" Hello world")["input_ids"]
[2, 62, 84, 28, 2, 179, 79]
You can get around that behavior by passing add_prefix_space=True
when instantiating this tokenizer or when you
call it on some text, but since the model was not pretrained this way, it might yield a decrease in performance.
When used with is_split_into_words=True
, this tokenizer will add a space before each word (even the first one).
This tokenizer inherits from PreTrainedTokenizer which contains most of the main methods. Users should refer to this superclass for more information regarding those methods.
( feature_size = 80 sampling_rate = 22050 default_audio_length = 6 hop_length = 256 chunk_length = 30 n_fft = 1024 padding_value = 0.0 mel_norms = None return_attention_mask = False **kwargs )
Parameters
int
, optional, defaults to 80) —
The feature dimension of the extracted features. int
, optional, defaults to 22050) —
The sampling rate at which the audio files should be digitalized expressed in hertz (Hz). int
, optional, defaults to 6) —
The default length of raw audio in seconds. If max_length
is not set during __call__
then it will
automatically be set to default_audio_length * self.sampling_rate
. int
, optional, defaults to 256) —
Length of the overlaping windows for the STFT used to obtain the Mel Frequency coefficients. int
, optional, defaults to 30) —
The maximum number of chuncks of sampling_rate
samples used to trim and pad longer or shorter audio
sequences. int
, optional, defaults to 1024) —
Size of the Fourier transform. float
, optional, defaults to 0.0) —
Padding value used to pad the audio. Should correspond to silences. list
of length feature_size
, optional) —
If mel_norms
is provided then it will be used to normalize the log-mel spectrograms along each
mel-filter. bool
, optional, defaults to False
) —
Whether to return the attention mask. If left to the default, it will return the attention mask.
Constructs a CLVP feature extractor.
This feature extractor inherits from SequenceFeatureExtractor which contains most of the main methods. Users should refer to this superclass for more information regarding those methods.
This class extracts log-mel-spectrogram features from raw speech using a custom numpy implementation of the Short Time Fourier Transform
which should match pytorch’s torch.stft
equivalent.
( raw_speech: Union sampling_rate: Optional = None truncation: bool = True pad_to_multiple_of: Optional = None return_tensors: Union = None return_attention_mask: Optional = True padding: Optional = 'max_length' max_length: Optional = None **kwargs )
Parameters
np.ndarray
, List[float]
, List[np.ndarray]
, List[List[float]]
) —
The sequence or batch of sequences to be padded. Each sequence can be a numpy array, a list of float
values, a list of numpy arrays or a list of list of float values. Must be mono channel audio, not
stereo, i.e. single float per timestep. int
, optional) —
The sampling rate at which the raw_speech
input was sampled. It is strongly recommended to pass
sampling_rate
at the forward call to prevent silent errors and allow automatic speech recognition
pipeline. bool
, optional, default to True
) —
Activates truncation to cut input sequences longer than max_length to max_length. int
, optional) —
If set will pad the sequence to a multiple of the provided value.
This is especially useful to enable the use of Tensor Cores on NVIDIA hardware with compute capability
>= 7.5
(Volta), or on TPUs which benefit from having sequence lengths be a multiple of 128.
bool
, optional, defaults to True
) —
Whether to return the attention mask. If left to the default, it will return the attention mask.
str
or TensorType, optional) —
If set, will return tensors instead of list of python integers. Acceptable values are:
'tf'
: Return TensorFlow tf.constant
objects.'pt'
: Return PyTorch torch.Tensor
objects.'np'
: Return Numpy np.ndarray
objects.float
, defaults to 0.0) —
The value that is used to fill the padding values / vectors. int
, optional) —
The maximum input length of the inputs. ClvpFeatureExtractor
is used to extract various voice specific properties such as the pitch and tone of the
voice, speaking speed, and even speaking defects like a lisp or stuttering from a sample voice or raw_speech
.
First the voice is padded or truncated in a way such that it becomes a waveform of self.default_audio_length
seconds long and then the log-mel spectrogram is extracted from it.
( feature_extractor tokenizer )
Parameters
ClvpFeatureExtractor
) —
An instance of ClvpFeatureExtractor. The feature extractor is a required input. ClvpTokenizer
) —
An instance of ClvpTokenizer. The tokenizer is a required input. Constructs a CLVP processor which wraps a CLVP Feature Extractor and a CLVP Tokenizer into a single processor.
ClvpProcessor offers all the functionalities of ClvpFeatureExtractor and ClvpTokenizer. See the call(), decode() and batch_decode() for more information.
Forwards the audio
and sampling_rate
arguments to call() and the text
argument to call(). Please refer to the doctsring of the above two methods for more
information.
This method forwards all its arguments to ClvpTokenizer’s decode(). Please refer to the docstring of this method for more information.
This method forwards all its arguments to ClvpTokenizer’s batch_decode(). Please refer to the docstring of this method for more information.
( config: ClvpConfig )
Parameters
The composite CLVP model with a text encoder, speech encoder and speech decoder model.The speech decoder model generates the speech_ids from the text and the text encoder and speech encoder workstogether to filter out the best speech_ids. This model inherits from PreTrainedModel. Check the superclass documentation for the generic methods the library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads etc.)
This model is also a PyTorch torch.nn.Module subclass. Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and behavior.
( input_ids: LongTensor = None input_features: FloatTensor = None conditioning_encoder_inputs_embeds: Optional = None text_encoder_inputs_embeds: Optional = None attention_mask: Optional = None return_loss: Optional = None output_hidden_states: Optional = None output_attentions: Optional = False return_dict: Optional = None ) → transformers.models.clvp.modeling_clvp.ClvpOutput
or tuple(torch.FloatTensor)
Parameters
torch.LongTensor
of shape (batch_size, sequence_length)
, optional) —
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
it.
Indices can be obtained using AutoTokenizer. See PreTrainedTokenizer.encode() and PreTrainedTokenizer.call() for details.
torch.FloatTensor
of shape (batch_size, feature_size, time_dim)
) —
Indicates log mel-spectrogram representations for audio returned by ClvpFeatureExtractor. torch.FloatTensor
, optional) —
inputs_embeds for ClvpConditioningEncoder
. Can be used in place of input_ids
. torch.FloatTensor
, optional) —
inputs_embeds for the text encoder model passed in place of input_ids
. torch.Tensor
of shape (batch_size, sequence_length)
, optional) —
Mask to avoid performing attention on padding text token indices. Mask values selected in [0, 1]
:
bool
, optional) —
Whether or not to return the contrastive loss. bool
, optional) —
Whether or not to return the attentions tensors of all attention layers. See attentions
under returned
tensors for more detail. bool
, optional) —
Whether or not to return the hidden states of all layers. See hidden_states
under returned tensors for
more detail. bool
, optional) —
Whether or not to return a ModelOutput instead of a plain tuple. Returns
transformers.models.clvp.modeling_clvp.ClvpOutput
or tuple(torch.FloatTensor)
A transformers.models.clvp.modeling_clvp.ClvpOutput
or a tuple of
torch.FloatTensor
(if return_dict=False
is passed or when config.return_dict=False
) comprising various
elements depending on the configuration (<class 'transformers.models.clvp.configuration_clvp.ClvpConfig'>
) and inputs.
torch.FloatTensor
of shape (1,)
, optional, returned when return_loss
is True
) — Contrastive loss for speech-text similarity.torch.LongTensor
, optional) — speech_ids (or speech candidates) generated by the ClvpForCausalLM
model.torch.FloatTensor
of shape (speech_batch_size, text_batch_size)
) — The scaled dot product scores between speech_embeds
and text_embeds
. This represents the speech-text
similarity scores.torch.FloatTensor
of shape (text_batch_size, speech_batch_size)
) — The scaled dot product scores between text_embeds
and speech_embeds
. This represents the text-speech
similarity scores.torch.FloatTensor
of shape (batch_size, output_dim
) — The text embeddings obtained by applying the projection layer to the pooled output of the text encoder
model.torch.FloatTensor
of shape (batch_size, output_dim
) — The speech embeddings obtained by applying the projection layer to the pooled output of the speech encoder
model.BaseModelOutputWithPooling
) — The pooled output of the last_hidden_state
of the text encoder Model.BaseModelOutputWithPooling
) — The pooled output of the last_hidden_state
of the speech encoder Model.torch.FloatTensor
, optional) — The hidden states of the decoder model.torch.FloatTensor
, optional) — The hidden states of the text encoder model.torch.FloatTensor
, optional) — The hidden states of the speech encoder model.The ClvpModelForConditionalGeneration forward method, overrides the __call__
special method.
Although the recipe for forward pass needs to be defined within this function, one should call the Module
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.
Examples:
>>> import datasets
>>> from transformers import ClvpProcessor, ClvpModelForConditionalGeneration
>>> # Define the Text and Load the Audio (We are taking an audio example from HuggingFace Hub using `datasets` library)
>>> text = "This is an example text."
>>> ds = datasets.load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
>>> ds = ds.cast_column("audio", datasets.Audio(sampling_rate=22050))
>>> _, audio, sr = ds.sort("id").select(range(1))[:1]["audio"][0].values()
>>> # Define processor and model
>>> processor = ClvpProcessor.from_pretrained("susnato/clvp_dev")
>>> model = ClvpModelForConditionalGeneration.from_pretrained("susnato/clvp_dev")
>>> # processor outputs and model outputs
>>> processor_output = processor(raw_speech=audio, sampling_rate=sr, text=text, return_tensors="pt")
>>> outputs = model(
... input_ids=processor_output["input_ids"],
... input_features=processor_output["input_features"],
... return_dict=True,
... )
( input_ids: LongTensor = None input_features: FloatTensor = None attention_mask: Optional = None generation_config: Optional = None pad_to_max_mel_tokens: Optional = None output_hidden_states: Optional = None **kwargs ) → ClvpOutput
or tuple
Parameters
torch.FloatTensor
of shape (batch_size, sequence_length)
, optional) —
Input text Tokens. Processed from the ClvpTokenizer. torch.FloatTensor
of shape (batch_size, feature_size, time_dim)
, optional) —
Indicates log-melspectrogram representations for audio returned by ClvpFeatureExtractor. torch.Tensor
of shape (batch_size, sequence_length)
, optional) —
Mask to avoid performing attention on padding text token indices. Mask values selected in [0, 1]
:
~generation.GenerationConfig
, optional) —
The generation configuration to be used as base parametrization for the generation call. **kwargs
passed to generate matching the attributes of generation_config
will override them. If
generation_config
is not provided, the default will be used, which had the following loading
priority: 1) from the generation_config.json
model file, if it exists; 2) from the model
configuration. Please note that unspecified parameters will inherit GenerationConfig’s
default values, whose documentation should be checked to parameterize generation. int
, optional) —
Pads generated speech_ids to the specified value. This is to implement the same logic from the official
repo, link: https://github.com/neonbjb/tortoise-tts/blob/80f89987a5abda5e2b082618cd74f9c7411141dc/tortoise/api.py#L430
and to make sure the logits are same.
This does not affect generation quality so please don’t consider using it since it is less efficient. bool
, optional) —
Whether or not to return the hidden states of decoder model, text encoder and speech encoder models. Returns
ClvpOutput
or tuple
A ClvpOutput
(if return_dict_in_generate=True
or when
config.return_dict_in_generate=True
) or a tuple.
Generate method for ClvpModelForConditionalGeneration
, this method calls the generate
method of
ClvpForCausalLM
and then uses those generated speech_ids
to process text_embeds
and speech_embeds
using
ClvpEncoder
.
( input_ids: Optional = None text_encoder_inputs_embeds: Optional = None attention_mask: Optional = None ) → torch.FloatTensor
of shape (batch_size, output_dim)
Parameters
torch.LongTensor
of shape (batch_size, sequence_length)
) —
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
provide it.
torch.FloatTensor
, optional) —
inputs_embeds for the text encoder model passed in place of input_ids
. torch.Tensor
of shape (batch_size, sequence_length)
, optional) —
Mask to avoid performing attention on padding token indices. Mask values selected in [0, 1]
:
Returns
torch.FloatTensor
of shape (batch_size, output_dim)
The text embeddings obtained by applying the projection layer to the pooled output of the CLVP Text Model.
This method can be used to extract text_embeds from a text. The text embeddings obtained by applying the projection layer to the pooled output of the CLVP text encoder model.
Examples:
>>> from transformers import ClvpProcessor, ClvpModelForConditionalGeneration
>>> # Define the Text
>>> text = "This is an example text."
>>> # Define processor and model
>>> processor = ClvpProcessor.from_pretrained("susnato/clvp_dev")
>>> model = ClvpModelForConditionalGeneration.from_pretrained("susnato/clvp_dev")
>>> # Generate processor output and text embeds
>>> processor_output = processor(text=text, return_tensors="pt")
>>> text_embeds = model.get_text_features(input_ids=processor_output["input_ids"])
( speech_ids: Optional = None input_ids: Optional = None input_features: Optional = None conditioning_encoder_inputs_embeds: Optional = None attention_mask: Optional = None generation_config: Optional = None **kwargs ) → torch.FloatTensor
of shape (batch_size, output_dim)
Parameters
torch.LongTensor
of shape (batch_size, num_speech_ids)
, optional) —
Speech Tokens. Padding will be ignored by default should you provide it. If speech_ids are provided
then input_ids and input_features will be automatically ignored. torch.LongTensor
of shape (batch_size, sequence_length)
, optional) —
Input text Tokens. Processed from the ClvpTokenizer. If speech_ids is not provided, then input_ids
and input_features will be used. torch.FloatTensor
of shape (batch_size, feature_size, time_dim)
, optional) —
Indicates log-melspectrogram representations for audio returned by ClvpFeatureExtractor. If
speech_ids is not provided, then input_ids and input_features will be used. torch.FloatTensor
, optional) —
inputs_embeds for ClvpConditioningEncoder
. Can be used in place of input_ids
. torch.LongTensor
of shape (batch_size, sequence_length)
, optional) —
Mask to avoid performing attention on padding speech token indices. Mask values selected in [0, 1]
:
GenerationConfig
, optional) —
generation config to control the generation of speech_ids if they are not provided. Returns
torch.FloatTensor
of shape (batch_size, output_dim)
The speech embeddings obtained by applying the projection layer to the pooled output of the CLVP Speech Model.
This method can be used to extract speech_embeds. The speech embeddings are obtained by applying the speech model on speech_ids. If speech_ids is not present but both input_ids and input_features are given then the decoder model will be used to first generate the speech_ids and then applying the speech model.
Examples:
>>> import datasets
>>> from transformers import ClvpProcessor, ClvpModelForConditionalGeneration
>>> # Define the Text and Load the Audio (We are taking an audio example from HuggingFace Hub using `datasets` library)
>>> text = "This is an example text."
>>> ds = datasets.load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
>>> ds = ds.cast_column("audio", datasets.Audio(sampling_rate=22050))
>>> _, audio, sr = ds.sort("id").select(range(1))[:1]["audio"][0].values()
>>> # Define processor and model
>>> processor = ClvpProcessor.from_pretrained("susnato/clvp_dev")
>>> model = ClvpModelForConditionalGeneration.from_pretrained("susnato/clvp_dev")
>>> # Generate processor output and model output
>>> processor_output = processor(raw_speech=audio, sampling_rate=sr, text=text, return_tensors="pt")
>>> speech_embeds = model.get_speech_features(
... input_ids=processor_output["input_ids"], input_features=processor_output["input_features"]
... )
( config )
Parameters
The CLVP decoder model with a language modelling head on top. This model inherits from PreTrainedModel. Check the superclass documentation for the generic methods the library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads etc.)
This model is also a PyTorch torch.nn.Module subclass. Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and behavior.
( input_ids: Optional = None past_key_values: Optional = None attention_mask: Optional = None token_type_ids: Optional = None position_ids: Optional = None head_mask: Optional = None inputs_embeds: Optional = None labels: Optional = None use_cache: Optional = None output_attentions: Optional = None output_hidden_states: Optional = None return_dict: Optional = None )
Parameters
torch.LongTensor
of shape (batch_size, input_ids_length)
) —
Indices of input sequence tokens in the vocabulary.
Indices can be obtained using AutoTokenizer. See PreTrainedTokenizer.encode() and PreTrainedTokenizer.call() for details.
Tuple[Tuple[torch.Tensor]]
of length config.n_layers
) —
Contains precomputed hidden-states (key and values in the attention blocks) as computed by the model (see
past_key_values
output below). Can be used to speed up sequential decoding. The input_ids
which have
their past given to this model should not be passed as input_ids
as they have already been computed. torch.FloatTensor
of shape (batch_size, sequence_length)
, optional) —
Mask to avoid performing attention on padding token indices. Mask values selected in [0, 1]
:
If past_key_values
is used, attention_mask
needs to contain the masking strategy that was used for
past_key_values
. In other words, the attention_mask
always has to have the length:
len(past_key_values) + len(input_ids)
torch.LongTensor
of shape (batch_size, input_ids_length)
, optional) —
Segment token indices to indicate first and second portions of the inputs. Indices are selected in [0, 1]
:
torch.LongTensor
of shape (batch_size, sequence_length)
, optional) —
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range [0, config.max_position_embeddings - 1]
.
torch.FloatTensor
of shape (num_heads,)
or (num_layers, num_heads)
, optional) —
Mask to nullify selected heads of the self-attention modules. Mask values selected in [0, 1]
:
torch.FloatTensor
of shape (batch_size, sequence_length, hidden_size)
, optional) —
Optionally, instead of passing input_ids
you can choose to directly pass an embedded representation. This
is useful if you want more control over how to convert input_ids
indices into associated vectors than the
model’s internal embedding lookup matrix.
If past_key_values
is used, optionally only the last inputs_embeds
have to be input (see
past_key_values
).
bool
, optional) —
If set to True
, past_key_values
key value states are returned and can be used to speed up decoding (see
past_key_values
). bool
, optional) —
Whether or not to return the attentions tensors of all attention layers. See attentions
under returned
tensors for more detail. bool
, optional) —
Whether or not to return the hidden states of all layers. See hidden_states
under returned tensors for
more detail. bool
, optional) —
Whether or not to return a ModelOutput instead of a plain tuple. torch.LongTensor
of shape (batch_size, sequence_length)
, optional) —
Labels for language modeling. Note that the labels are shifted inside the model, i.e. you can set
labels = input_ids
Indices are selected in [-100, 0, ..., config.vocab_size]
All labels set to -100
are ignored (masked), the loss is only computed for labels in [0, ..., config.vocab_size]
The ClvpForCausalLM forward method, overrides the __call__
special method.
Although the recipe for forward pass needs to be defined within this function, one should call the Module
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.
( config: ClvpDecoderConfig )
Parameters
The bare Clvp decoder model outputting raw hidden-states without any specific head on top. This model inherits from PreTrainedModel. Check the superclass documentation for the generic methods the library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads etc.)
This model is also a PyTorch torch.nn.Module subclass. Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and behavior.
( input_ids: Optional = None attention_mask: Optional = None token_type_ids: Optional = None position_ids: Optional = None head_mask: Optional = None past_key_values: Optional = None inputs_embeds: Optional = None use_cache: Optional = None output_attentions: Optional = None output_hidden_states: Optional = None return_dict: Optional = None )
Parameters
torch.LongTensor
of shape (batch_size, input_ids_length)
) —
Indices of input sequence tokens in the vocabulary.
Indices can be obtained using AutoTokenizer. See PreTrainedTokenizer.encode() and PreTrainedTokenizer.call() for details.
Tuple[Tuple[torch.Tensor]]
of length config.n_layers
) —
Contains precomputed hidden-states (key and values in the attention blocks) as computed by the model (see
past_key_values
output below). Can be used to speed up sequential decoding. The input_ids
which have
their past given to this model should not be passed as input_ids
as they have already been computed. torch.FloatTensor
of shape (batch_size, sequence_length)
, optional) —
Mask to avoid performing attention on padding token indices. Mask values selected in [0, 1]
:
If past_key_values
is used, attention_mask
needs to contain the masking strategy that was used for
past_key_values
. In other words, the attention_mask
always has to have the length:
len(past_key_values) + len(input_ids)
torch.LongTensor
of shape (batch_size, input_ids_length)
, optional) —
Segment token indices to indicate first and second portions of the inputs. Indices are selected in [0, 1]
:
torch.LongTensor
of shape (batch_size, sequence_length)
, optional) —
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range [0, config.max_position_embeddings - 1]
.
torch.FloatTensor
of shape (num_heads,)
or (num_layers, num_heads)
, optional) —
Mask to nullify selected heads of the self-attention modules. Mask values selected in [0, 1]
:
torch.FloatTensor
of shape (batch_size, sequence_length, hidden_size)
, optional) —
Optionally, instead of passing input_ids
you can choose to directly pass an embedded representation. This
is useful if you want more control over how to convert input_ids
indices into associated vectors than the
model’s internal embedding lookup matrix.
If past_key_values
is used, optionally only the last inputs_embeds
have to be input (see
past_key_values
).
bool
, optional) —
If set to True
, past_key_values
key value states are returned and can be used to speed up decoding (see
past_key_values
). bool
, optional) —
Whether or not to return the attentions tensors of all attention layers. See attentions
under returned
tensors for more detail. bool
, optional) —
Whether or not to return the hidden states of all layers. See hidden_states
under returned tensors for
more detail. bool
, optional) —
Whether or not to return a ModelOutput instead of a plain tuple. The ClvpModel forward method, overrides the __call__
special method.
Although the recipe for forward pass needs to be defined within this function, one should call the Module
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.
Transformer encoder consisting of config.num_hidden_layers
self attention layers. Each layer is a
ClvpEncoderLayer
.
( input_ids: Optional = None inputs_embeds: Optional = None attention_mask: Optional = None position_ids: Optional = None output_attentions: Optional = None output_hidden_states: Optional = None return_dict: Optional = None )
Parameters
torch.LongTensor
of shape (batch_size, input_ids_length)
, optional) —
Indices of input sequence tokens in the vocabulary.
Indices can be obtained using AutoTokenizer. See PreTrainedTokenizer.encode() and PreTrainedTokenizer.call() for details.
torch.FloatTensor
of shape (batch_size, sequence_length, hidden_size)
, optional) —
input embeddings for the model. This bypasses the model’s internal embedding lookup matrix. torch.LongTensor
of shape (batch_size, sequence_length)
, optional) —
Mask to avoid performing attention on padding token indices. Mask values selected in [0, 1]
:
torch.LongTensor
, optional) —
Denotes the position ids of input_ids
. bool
, optional) —
Whether or not to return the attentions tensors of all attention layers. See attentions
under
returned tensors for more detail. bool
, optional) —
Whether or not to return the hidden states of all layers. See hidden_states
under returned tensors
for more detail. bool
, optional) —
Whether or not to return a ModelOutput instead of a plain tuple. Transformer decoder consisting of config.num_hidden_layers layers. Each layer is a ClvpDecoderLayer
( input_ids: Optional = None attention_mask: Optional = None token_type_ids: Optional = None position_ids: Optional = None head_mask: Optional = None past_key_values: Optional = None inputs_embeds: Optional = None use_cache: Optional = None output_attentions: Optional = None output_hidden_states: Optional = None return_dict: Optional = None )
Parameters
torch.LongTensor
of shape (batch_size, input_ids_length)
) —
Indices of input sequence tokens in the vocabulary.
Indices can be obtained using AutoTokenizer. See PreTrainedTokenizer.encode() and PreTrainedTokenizer.call() for details.
Tuple[Tuple[torch.Tensor]]
of length config.n_layers
) —
Contains precomputed hidden-states (key and values in the attention blocks) as computed by the model (see
past_key_values
output below). Can be used to speed up sequential decoding. The input_ids
which have
their past given to this model should not be passed as input_ids
as they have already been computed. torch.FloatTensor
of shape (batch_size, sequence_length)
, optional) —
Mask to avoid performing attention on padding token indices. Mask values selected in [0, 1]
:
If past_key_values
is used, attention_mask
needs to contain the masking strategy that was used for
past_key_values
. In other words, the attention_mask
always has to have the length:
len(past_key_values) + len(input_ids)
torch.LongTensor
of shape (batch_size, input_ids_length)
, optional) —
Segment token indices to indicate first and second portions of the inputs. Indices are selected in [0, 1]
:
torch.LongTensor
of shape (batch_size, sequence_length)
, optional) —
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range [0, config.max_position_embeddings - 1]
.
torch.FloatTensor
of shape (num_heads,)
or (num_layers, num_heads)
, optional) —
Mask to nullify selected heads of the self-attention modules. Mask values selected in [0, 1]
:
torch.FloatTensor
of shape (batch_size, sequence_length, hidden_size)
, optional) —
Optionally, instead of passing input_ids
you can choose to directly pass an embedded representation. This
is useful if you want more control over how to convert input_ids
indices into associated vectors than the
model’s internal embedding lookup matrix.
If past_key_values
is used, optionally only the last inputs_embeds
have to be input (see
past_key_values
).
bool
, optional) —
If set to True
, past_key_values
key value states are returned and can be used to speed up decoding (see
past_key_values
). bool
, optional) —
Whether or not to return the attentions tensors of all attention layers. See attentions
under returned
tensors for more detail. bool
, optional) —
Whether or not to return the hidden states of all layers. See hidden_states
under returned tensors for
more detail. bool
, optional) —
Whether or not to return a ModelOutput instead of a plain tuple. The ClvpDecoder forward method, overrides the __call__
special method.
Although the recipe for forward pass needs to be defined within this function, one should call the Module
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.