Created
February 15, 2020 15:12
-
-
Save henry16lin/bba753622b0156fcc2f40a02398d0ea4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.metrics import confusion_matrix | |
true=[] | |
predictions=[] | |
with torch.no_grad(): | |
model.eval() | |
for data in testloader: | |
tokens_tensors, segments_tensors,masks_tensors, labels = [t.to(device) for t in data] | |
val_outputs = model(input_ids=tokens_tensors, | |
token_type_ids=segments_tensors, | |
attention_mask=masks_tensors, | |
labels=labels) | |
logits = val_outputs[1] | |
_, pred = torch.max(logits.data, 1) | |
true.extend(labels.cpu().tolist()) | |
predictions.extend(pred.cpu().tolist()) | |
c = confusion_matrix(true, predictions) | |
print(c) | |
accuracy_score(predictions,true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment