Views
No views yet
1from transformers import DebertaV2Tokenizer, DebertaV2ForSequenceClassification
2import torch
3
4# Load model
5model_name = "mohamedsa1/deberta-v3-nq-classification"
6tokenizer = DebertaV2Tokenizer.from_pretrained(model_name)
7model = DebertaV2ForSequenceClassification.from_pretrained(model_name)
8
9# Prepare input
10question = "What is the capital of France?"
11context = "Paris is the capital and most populous city of France."
12text = f"Question: {question} Context: {context}"
13
14# Inference
15inputs = tokenizer(text, return_tensors="pt", max_length=256, truncation=True, padding=True)
16with torch.no_grad():
17 outputs = model(**inputs)
18 probs = torch.nn.functional.softmax(outputs.logits, dim=-1)[0]
19 prediction = torch.argmax(probs).item()
20
21# Results
22labels = ["No Answer", "Has Answer", "Yes/No"]
23print(f"Prediction: {labels[prediction]}")
24print(f"Confidence: {probs[prediction]:.2%}")