gt4sd.frameworks.granular.ml.models.vae_rnn.core module¶
VaeRnn implementation.
Summary¶
Classes:
VaeRnn - variational encoder using RNN with Gaussian prior and approximate posterior. |
Reference¶
- class VaeRnn(name, position, data, vocab_size, embedding_size, tokenizer, hidden_size_enc=265, n_layers_enc=2, hidden_size_dec=265, n_layers_dec=2, bidirectional=False, latent_size=196, teacher_forcing=True, loss_function='ce', kl_low=0.0, kl_high=0.1, kl_n_epochs=100, kl_start_epoch=0, inference_check_frequency=50, **kwargs)[source]¶
Bases:
GranularEncoderDecoderModel
VaeRnn - variational encoder using RNN with Gaussian prior and approximate posterior.
- __init__(name, position, data, vocab_size, embedding_size, tokenizer, hidden_size_enc=265, n_layers_enc=2, hidden_size_dec=265, n_layers_dec=2, bidirectional=False, latent_size=196, teacher_forcing=True, loss_function='ce', kl_low=0.0, kl_high=0.1, kl_n_epochs=100, kl_start_epoch=0, inference_check_frequency=50, **kwargs)[source]¶
Construct VaeRnn.
- Parameters
name (
str
) – model name.position (
int
) – position of the model.data (
Dict
[str
,str
]) – data name mappings.vocab_size (
int
) – size of the vocabulary.embedding_size (
int
) – size of the embedding vectors.tokenizer (
Tokenizer
) – tokenizer.hidden_size_enc (
int
) – encoder hidden size. Defaults to 256.n_layers_enc (
int
) – number of layers for the encoder. Defaults to 2.hidden_size_dec (
int
) – decoder hidden size. Defaults to 256.n_layers_dec (
int
) – number of layers for the decoder. Defaults to 2.bidirectional (
bool
) – whether the RNN cell is bidirectional. Defaults to False.latent_size (
int
) – latent size. Defaults to 196.teacher_forcing (
bool
) – whether to teacher forcing. Defaults to True.loss_function (
str
) – loss function. Defaults to “ce”.kl_low (
float
) – low KL weight. Defaults to 0.0.kl_high (
float
) – high KL weight. Defaults to 0.1.kl_n_epochs (
int
) – KL number of epochs. Defaults to 100.kl_start_epoch (
int
) – KL starting epoch. Defaults to 0.inference_check_frequency (
int
) – frequency for checking inference quality. Defaults to 50.
- Raises
ValueError – in case the provided loss function is not supported.
- decode(z, max_len=127, *args, **kwargs)[source]¶
Decode a latent space point.
- Parameters
z (
Any
) – latent point.max_len (
int
) – maximum sequence length. Defaults to 127.
- Return type
Any
- Returns
tuple with decoded texts and token indices.
- _sampling_step(x, *args, **kwargs)[source]¶
Run a sampling step in the model.
- Parameters
x (
Any
) – model input.- Return type
Any
- Returns
model sampling step output.
- encode(x, *args, **kwargs)[source]¶
Encode a sample.
- Parameters
x (
Any
) – input sample.- Return type
Any
- Returns
latent encoding.
- encode_decode(x, max_len=127, *args, **kwargs)[source]¶
Encode and decode a sample.
- Parameters
x (
Any
) – input sample.max_len (
int
) – maximum sequence length. Defaults to 127.
- Return type
Any
- Returns
decoded sample.
- inference(x, *args, **kwargs)[source]¶
Run the model in inference mode.
- Parameters
x (
Any
) – sample.- Return type
Any
- Returns
generated output.
- _run_step(x, *args, **kwargs)[source]¶
Run a step in the model.
- Parameters
x (
Any
) – model input.- Return type
Any
- Returns
model step output.
- step(input_data, target_data, device='cpu', current_epoch=0, *args, **kwargs)[source]¶
Training step for the model.
- Parameters
input_data (
Any
) – input for the step.target_data (
Any
) – target for the step.device (
str
) – string representing the device to use. Defaults to “cpu”.current_epoch (
int
) – current epoch. Defaults to 0.
- Return type
Tuple
[Any
,Any
,Any
]- Returns
a tuple containing the step output, the loss and the logs for the module.
- val_step(input_data, target_data, device='cpu', current_epoch=0, *args, **kwargs)[source]¶
Validation step for the model.
- Parameters
input_data (
Any
) – input for the step.target_data (
Any
) – target for the step.device (
str
) – string representing the device to use. Defaults to “cpu”.current_epoch (
int
) – current epoch. Defaults to 0.
- Return type
Any
- Returns
a tuple containing the step output, the loss and the logs for the module.
- static add_model_specific_args(parent_parser, name, *args, **kwargs)[source]¶
Adding to a parser model specific arguments.
- Parameters
parent_parser (
ArgumentParser
) – patent parser.name (
str
) – model name.
- Return type
ArgumentParser
- Returns
updated parser.
- __annotations__ = {}¶
- __doc__ = 'VaeRnn - variational encoder using RNN with Gaussian prior and approximate posterior.'¶
- __module__ = 'gt4sd.frameworks.granular.ml.models.vae_rnn.core'¶