MaliGAN Generator¶
- class textbox.module.Generator.MaliGANGenerator.MaliGANGenerator(config, dataset)[source]¶
Bases:
UnconditionalGenerator
MaliGANGenerator is a generative model with the LSTMs.
- adversarial_loss(discriminator_func)[source]¶
Calculate the adversarial generator loss guided by discriminator_func. A noval objective for the generator to optimize, using importance sampling. The training procedure is closer to maximum likelihood (MLE) training.
\[r_D(x) = \frac{D(x)}{1-D(x)}\]- Parameters
discriminator_func (function) – The function provided from discriminator to calculated the loss of generated sentence.
- Returns
The calculated adversarial loss, shape: [].
- Return type
torch.Tensor
- calculate_loss(corpus, nll_test=False)[source]¶
Calculate the generated loss of corpus.
- Parameters
corpus (Corpus) – The corpus to be calculated.
nll_test (Bool) – Optional; if nll_test is True the loss is calculated in sentence level rather than in word level.
- Returns
The calculated loss of corpus, shape: [].
- Return type
torch.Tensor
- generate(batch_data, eval_data)[source]¶
Generate tokens of sentences using eval_data.
- Parameters
batch_data (Corpus) – Single batch corpus information of evaluation data.
eval_data – Common information of all evaluation data.
- Returns
The generated tokens of each sentence.
- Return type
List[List[str]]
- sample(sample_num)[source]¶
Sample sample_num generated sentence indice.
- Parameters
sample_num (int) – The number to generate.
- Returns
The generated sentence indice, shape: [sample_num, max_length].
- Return type
torch.Tensor
- sample_batch()[source]¶
Sample a batch of generated sentence indice.
- Returns
The generated sentence indice, shape: [batch_size, max_length].
- Return type
torch.Tensor
- training: bool¶