Tbruand
commited on
Commit
·
39dcbb5
1
Parent(s):
6bfce7a
feat(models): ajoute un modèle few-shot simulé basé sur des exemples textuels
Browse files- models/few_shot.py +21 -0
models/few_shot.py
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
from models.base import BaseModel
|
| 4 |
+
|
| 5 |
+
class FewShotModel(BaseModel):
|
| 6 |
+
def __init__(self):
|
| 7 |
+
self.examples = [
|
| 8 |
+
("Tu es un abruti", "toxique"),
|
| 9 |
+
("Je vais te tuer", "toxique"),
|
| 10 |
+
("Merci pour ton aide", "non-toxique"),
|
| 11 |
+
("J'apprécie ton soutien", "non-toxique")
|
| 12 |
+
]
|
| 13 |
+
|
| 14 |
+
def predict(self, text: str) -> str:
|
| 15 |
+
text = text.lower()
|
| 16 |
+
|
| 17 |
+
# Score simple basé sur correspondance de mots-clés
|
| 18 |
+
toxic_score = sum(any(word in example.lower() for word in text.split()) for example, label in self.examples if label == "toxique")
|
| 19 |
+
non_toxic_score = sum(any(word in example.lower() for word in text.split()) for example, label in self.examples if label == "non-toxique")
|
| 20 |
+
|
| 21 |
+
return "toxique" if toxic_score >= non_toxic_score else "non-toxique"
|