|
|
|
|
|
"""
|
|
|
Demo script for EdTech Feedback Validation Model
|
|
|
"""
|
|
|
|
|
|
import torch
|
|
|
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
|
|
|
|
def load_model(model_name):
|
|
|
"""Load the model and tokenizer"""
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
|
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
|
|
return tokenizer, model
|
|
|
|
|
|
def predict_alignment(text, reason, tokenizer, model):
|
|
|
"""Predict whether text aligns with reason"""
|
|
|
|
|
|
inputs = tokenizer(
|
|
|
text,
|
|
|
reason,
|
|
|
return_tensors="pt",
|
|
|
padding=True,
|
|
|
truncation=True,
|
|
|
max_length=512
|
|
|
)
|
|
|
|
|
|
|
|
|
with torch.no_grad():
|
|
|
outputs = model(**inputs)
|
|
|
probabilities = torch.softmax(outputs.logits, dim=1)
|
|
|
prediction = torch.argmax(probabilities, dim=1).item()
|
|
|
confidence = probabilities[0][prediction].item()
|
|
|
|
|
|
return prediction, confidence
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
model_name = "your-username/edtech-feedback-validation"
|
|
|
|
|
|
|
|
|
tokenizer, model = load_model(model_name)
|
|
|
|
|
|
|
|
|
test_cases = [
|
|
|
("this is an amazing app for online classes!", "good app for conducting online classes"),
|
|
|
("i cannot login to zoom", "help"),
|
|
|
("very practical and easy to use", "app is user-friendly")
|
|
|
]
|
|
|
|
|
|
for text, reason in test_cases:
|
|
|
prediction, confidence = predict_alignment(text, reason, tokenizer, model)
|
|
|
result = "ALIGNED" if prediction == 1 else "NOT ALIGNED"
|
|
|
print(f"Text: {text}")
|
|
|
print(f"Reason: {reason}")
|
|
|
print(f"Result: {result} (Confidence: {confidence:.3f})")
|
|
|
print("-" * 50)
|
|
|
|