ipatate
commited on
Commit
·
e00793e
1
Parent(s):
b01b845
add exemple in README
Browse files
README.md
CHANGED
@@ -27,3 +27,64 @@ inputs = tokenizer(text, return_tensors="pt")
|
|
27 |
outputs = model(**inputs)
|
28 |
|
29 |
print(outputs.logits)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
outputs = model(**inputs)
|
28 |
|
29 |
print(outputs.logits)
|
30 |
+
```
|
31 |
+
|
32 |
+
### Exemple for list
|
33 |
+
|
34 |
+
```python
|
35 |
+
import torch
|
36 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
37 |
+
|
38 |
+
model_name = "Goodmotion/spam-mail-classifier"
|
39 |
+
|
40 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
41 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
42 |
+
|
43 |
+
texts = [
|
44 |
+
'Join us for a webinar on AI innovations',
|
45 |
+
'Urgent: Verify your account immediately.',
|
46 |
+
'Meeting rescheduled to 3 PM',
|
47 |
+
'Happy Birthday!',
|
48 |
+
'Limited time offer: Act now!',
|
49 |
+
'Join us for a webinar on AI innovations',
|
50 |
+
'Claim your free prize now!',
|
51 |
+
'You have unclaimed rewards waiting!',
|
52 |
+
'Weekly newsletter from Tech World',
|
53 |
+
'Update on the project status',
|
54 |
+
'Lunch tomorrow at 12:30?',
|
55 |
+
'Get rich quick with this amazing opportunity!',
|
56 |
+
'Invoice for your recent purchase',
|
57 |
+
'Don\'t forget: Gym session at 6 AM',
|
58 |
+
'Join us for a webinar on AI innovations',
|
59 |
+
'bonjour comment allez vous ?',
|
60 |
+
'Documents suite à notre rendez-vous',
|
61 |
+
'Valentin Dupond mentioned you in a comment',
|
62 |
+
'Bolt x Supabase = 🤯',
|
63 |
+
'Modification site web de la société',
|
64 |
+
'Image de mise en avant sur les articles',
|
65 |
+
'Bring new visitors to your site',
|
66 |
+
'Le Cloud Éthique sans bullshit',
|
67 |
+
'Remix Newsletter #25: React Router v7',
|
68 |
+
'Votre essai auprès de X va bientôt prendre fin',
|
69 |
+
'Introducing a Google Docs integration, styles and more in Claude.ai',
|
70 |
+
'Carte de crédit sur le point d’expirer sur Cloudflare'
|
71 |
+
]
|
72 |
+
inputs = tokenizer(texts, padding=True, truncation=True, max_length=128, return_tensors="pt")
|
73 |
+
outputs = model(**inputs)
|
74 |
+
|
75 |
+
# Convertir les logits en probabilités avec softmax
|
76 |
+
logits = outputs.logits
|
77 |
+
probabilities = torch.softmax(logits, dim=1)
|
78 |
+
|
79 |
+
# Décoder les classes pour chaque texte
|
80 |
+
labels = ["NOSPAM", "SPAM"] # Mapping des indices à des labels
|
81 |
+
results = [
|
82 |
+
{"text": text, "label": labels[torch.argmax(prob).item()], "confidence": prob.max().item()}
|
83 |
+
for text, prob in zip(texts, probabilities)
|
84 |
+
]
|
85 |
+
|
86 |
+
# Afficher les résultats
|
87 |
+
for result in results:
|
88 |
+
print(f"Texte : {result['text']}")
|
89 |
+
print(f"Résultat : {result['label']} (Confiance : {result['confidence']:.2%})\n")
|
90 |
+
```
|