Views
No views yet
PreTrainedTokenizerFast)with torch.no_grad():
logits = model(input_ids).logits[:, -1, :]
probs = torch.nn.functional.softmax(logits, dim=-1)
# Get top probability candidates
top_probs, top_indices = torch.topk(probs, 50)
predictions = []
for idx, prob in zip(top_indices[0], top_probs[0]):
word = tokenizer.decode([idx]).strip()
# Filter out empty strings or byte-fallback artifacts like <0x..>
if len(word) > 0 and not re.search(r'<0x[0-9A-Fa-f]+>', word):
predictions.append((word, prob.item()))
if len(predictions) == 5:
break
return predictions