Spaces:
Sleeping
Sleeping
| from transformers import BertTokenizer, BertForSequenceClassification | |
| import torch | |
| model = BertForSequenceClassification.from_pretrained('./confidence_model') | |
| tokenizer = BertTokenizer.from_pretrained('./confidence_tokenizer') | |
| def predict_confidence(question, answer): | |
| inputs = tokenizer(question, answer, return_tensors="pt", padding=True, truncation=True) | |
| model.eval() | |
| with torch.no_grad(): | |
| outputs = model(**inputs) | |
| logits = outputs.logits | |
| predictions = torch.argmax(logits, dim=-1) | |
| return "Confident" if predictions.item() == 1 else "Not Confident" | |
| # Example | |
| question = "What is your experience with Python?" | |
| answer = "I dont have any experience in Python" | |
| print(predict_confidence(question, answer)) | |