INNER CODE UNIT · Python
sample_unconditional
HendrikStrobelt/detecting-fake-text · backend/api.py:126
def sample_unconditional(self, length=100, topk=5, temperature=1.0):
'''
Sample `length` words from the model.
Code strongly inspired by
https://github.com/huggingface/pytorch-pretrained-BERT/blob/master/examples/run_gpt2.py
'''
context = torch.full((1, 1),
self.enc.encoder[self.start_token],
device=self.device,
dtype=torch.long)
prev = context
output = context
past = None
# Forward through the model
with torch.no_grad():
for i in range(length):
logits, past = self.model(prev, past=past)