Commit ·
c9ad1bf
1
Parent(s): 848842c
Update app.py
Browse files12 unmodified lines131415161718192021222324252612 unmodified linesdef predict(text=None) -> dict:model.eval()inputs = tokenizer(text, return_tensors="pt")input_ids = inputs["input_ids"].to(device)attention_mask = inputs["attention_mask"].to(device)model.to(device)token_logits = model(input_ids, attention_mask=attention_mask).logitsmask_token_index = torch.where(inputs["input_ids"] == tokenizer.mask_token_id)[1]mask_token_logits = token_logits[0, mask_token_index, :]print(mask_token_logits.shape)top_5_tokens = torch.topk(mask_token_logits, NUM_CLASSES, dim=1).indices[0].tolist()score = torch.nn.functional.softmax(mask_token_logits)[0]top_5_score = torch.topk(score, NUM_CLASSES).values.tolist()12 unmodified lines13141516171819202122232425262712 unmodified linesdef predict(text=None) -> dict:model.eval()inputs = tokenizer(str(text), return_tensors="pt")input_ids = inputs["input_ids"].to(device)attention_mask = inputs["attention_mask"].to(device)model.to(device)token_logits = model(input_ids, attention_mask=attention_mask).logitsprint(mask_token_index)mask_token_index = torch.where(inputs["input_ids"] == tokenizer.mask_token_id)[1]mask_token_logits = token_logits[0, mask_token_index, :]print(mask_token_logits)top_5_tokens = torch.topk(mask_token_logits, NUM_CLASSES, dim=1).indices[0].tolist()score = torch.nn.functional.softmax(mask_token_logits)[0]top_5_score = torch.topk(score, NUM_CLASSES).values.tolist()
app.py+3-2