Sampling instead of argmax

This commit is contained in:
Lysandre
2020-06-17 10:25:16 -04:00
parent 218ae1ed18
commit e50654c03c
2 changed files with 9 additions and 3 deletions
@@ -437,10 +437,14 @@ class CombinedModel(nn.Module):
# get the generator's predicted value on each masked position
fake_logits = self.gather_positions(generator_output, masked_lm_positions)
fake_argmaxes = fake_logits.argmax(-1)
fake_softmaxed = torch.softmax(fake_logits, dim=-1)
fake_sampled = fake_softmaxed\
.view(fake_logits.shape[0] * fake_logits.shape[1], fake_logits.shape[2])\
.multinomial(1)\
.view(fake_logits.shape[:-1])
# create a tensor containing the predicted tokens
fake_tokens = input_ids.scatter(-1, masked_lm_positions, fake_argmaxes)
fake_tokens = input_ids.scatter(-1, masked_lm_positions, fake_sampled)
fake_tokens[:, 0] = input_ids[:, 0]
discriminator_labels = (labels != fake_tokens).int()
@@ -461,7 +465,7 @@ class CombinedModel(nn.Module):
return (
total_loss,
(generator_output, discriminator_output),
(masked_input_ids, fake_argmaxes),
(masked_input_ids, fake_sampled),
(discriminator_labels, discriminator_predictions),
)
+2
View File
@@ -71,6 +71,8 @@ try:
_has_wandb = False if os.getenv("WANDB_DISABLED") else True
except ImportError:
_has_wandb = False
except AttributeError:
_has_wandb = False
def is_wandb_available():