Views
No views yet
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4model_name="agentlans/deberta-v3-xsmall-quality-v2"
5
6# Put model on GPU or else CPU
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModelForSequenceClassification.from_pretrained(model_name)
9device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
10model = model.to(device)
11
12def quality(text):
13 """Processes the text using the model and returns its logits.
14 In this case, it's interpreted as the the combined quality score for that text."""
15 inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True).to(device)
16 with torch.no_grad():
17 logits = model(**inputs).logits.squeeze().cpu()
18 return logits.tolist()
19
20# Example usage
21text = [x.strip() for x in """
22Congratulations! You've won a $1,000 gift card! Click here to claim your prize now!!!
23Page 1 2 3 4 5 Next Last>>
24Urgent: Your account has been compromised! Click this link to verify your identity and secure your account immediately!!!
25Today marks a significant milestone in our journey towards sustainability! 🌍✨ We’re excited to announce our partnership with local organizations to plant 10,000 trees in our community this fall. Join us in making a positive impact on our environment!
26In recent years, the impact of climate change has become increasingly evident, affecting ecosystems and human livelihoods across the globe.
27The mitochondria is the powerhouse of the cell.
28Exclusive discount on Super MitoMax Energy Boost! Recharge your mitochondria today!
29Everyone is talking about this new diet that guarantees weight loss without exercise!
30Discover five tips for improving your productivity while working from home.
31""".strip().split("\n")]
32
33result = quality(text)
34for x, s in zip(text, result):
35 print(f"Text: {x}\nQuality: {round(s, 2)}\n")xsmall size model:Text: Congratulations! You've won a $1,000 gift card! Click here to claim your prize now!!!
Quality: -0.77
Text: Page 1 2 3 4 5 Next Last>>
Quality: -1.36
Text: Urgent: Your account has been compromised! Click this link to verify your identity and secure your account immediately!!!
Quality: -1.17
Text: Today marks a significant milestone in our journey towards sustainability! 🌍✨ We’re excited to announce our partnership with local organizations to plant 10,000 trees in our community this fall. Join us in making a positive impact on our environment!
Quality: -0.59
Text: In recent years, the impact of climate change has become increasingly evident, affecting ecosystems and human livelihoods across the globe.
Quality: 0.58
Text: The mitochondria is the powerhouse of the cell.
Quality: 0.39
Text: Exclusive discount on Super MitoMax Energy Boost! Recharge your mitochondria today!
Quality: -1.01
Text: Everyone is talking about this new diet that guarantees weight loss without exercise!
Quality: 0.57
Text: Discover five tips for improving your productivity while working from home.
Quality: 0.45