INNER CODE UNIT · Python
logits
HendrikStrobelt/detecting-fake-text · backend/api.py:144
logits = logits[:, -1, :] / temperature
# Filter predictions to topk and softmax
probs = torch.softmax(top_k_logits(logits, k=topk),
dim=-1)
# Sample
prev = torch.multinomial(probs, num_samples=1)
# Construct output
output = torch.cat((output, prev), dim=1)
output_text = self.enc.decode(output[0].tolist())
return output_text
def postprocess(self, token):
with_space = False
with_break = False
if token.startswith('Ġ'):
with_space = True
token = token[1:]