TextGAN Generator¶
- class textbox.module.Generator.TextGANGenerator.TextGANGenerator(config, dataset)[source]¶
Bases:
UnconditionalGenerator
The generator of TextGAN.
- adversarial_loss(real_data, discriminator_func)[source]¶
Calculate the adversarial generator loss of real_data guided by discriminator_func.
- Parameters
real_data (torch.Tensor) – The realistic sentence data, shape: [batch_size, max_seq_len].
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()[source]¶
Sample a batch of generated sentence indice.
- Returns
The generated sentence indice, shape: [batch_size, max_length]. torch.Tensor: The latent code of the generated sentence, shape: [batch_size, hidden_size].
- Return type
torch.Tensor
- training: bool¶