Spaces:
Sleeping
Sleeping
Download app/confidence_analysis.py from RiteshAkhade/Interview-prep_app: direct link, hf CLI and curl.
- Browser
- Download file 755 Bytes
-
https://huggingface.co/spaces/RiteshAkhade/Interview-prep_app/resolve/main/app/confidence_analysis.py
- Command line
-
hf download hf://spaces/RiteshAkhade/Interview-prep_app/app/confidence_analysis.py
-
curl -L -o confidence_analysis.py https://huggingface.co/spaces/RiteshAkhade/Interview-prep_app/resolve/main/app/confidence_analysis.py
755 Bytes
| 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)) | |