RankGAN Discriminator¶
- class textbox.module.Discriminator.RankGANDiscriminator.RankGANDiscriminator(config, dataset)[source]¶
Bases:
UnconditionalGenerator
RankGANDiscriminator is a ranker which can endow a relative rank among the sequences when given a reference. The ranker is designed with the convolutional neural network.
- calculate_loss(real_data, fake_data, ref_data)[source]¶
Calculate the loss for real data and fake data. To rank the human_written sentences higher than the machine-written sentences.
- Parameters
real_data (torch.Tensor) – The realistic sentence data, shape: [batch_size, max_seq_len].
fake_data (torch.Tensor) – The generated sentence data, shape: [batch_size, max_seq_len].
ref_data (torch.Tensor) – The reference sentence data, shape: [ref_size, max_seq_len].
- Returns
The calculated loss of real data and fake data, shape: [].
- Return type
torch.Tensor
- forward(data)[source]¶
Maps concatenated sequence matrices into the embedded feature vectors.
- Parameters
data (torch.Tensor) – The sentence data, shape: [batch_size, max_seq_len].
- Returns
The embedded feature vectors, shape: [batch_size, total_filter_num].
- Return type
torch.Tensor
- get_rank_scores(sample_data, ref_data)[source]¶
Get the ranking score (before softmax) for sample s given reference u.
\[\alpha(s|u) = cosine(y_s,y_u) = \frac{y_s \cdot y_u}{\parallel y_s \parallel \parallel y_u \parallel}\]- Parameters
sample_data (torch.Tensor) – The realistic or generated sentence data, shape: [sample_size, max_seq_len].
ref_data (torch.Tensor) – The reference sentence data, shape: [ref_size, max_seq_len].
- Returns
The ranking score of sample data, shape: [batch_size].
- Return type
torch.Tensor
- highway(data)[source]¶
Apply the highway net to data.
- Parameters
data (torch.Tensor) – The original data, shape: [batch_size, total_filter_num].
- Returns
The data processed after highway net, shape: [batch_size, total_filter_num].
- Return type
torch.Tensor
- training: bool¶