Spaces:
Sleeping
Sleeping
Merwan6
commited on
Commit
·
2cbc3d1
1
Parent(s):
11204e4
metric
Browse files- .DS_Store +0 -0
- scripts/.DS_Store +0 -0
- scripts/metric.py +14 -8
.DS_Store
CHANGED
|
Binary files a/.DS_Store and b/.DS_Store differ
|
|
|
scripts/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
scripts/metric.py
CHANGED
|
@@ -8,6 +8,7 @@ from inference import (
|
|
| 8 |
few_shot_inference,
|
| 9 |
base_model_inference,
|
| 10 |
)
|
|
|
|
| 11 |
|
| 12 |
# Dictionnaire des fonctions à évaluer
|
| 13 |
models_to_evaluate = {
|
|
@@ -18,8 +19,9 @@ models_to_evaluate = {
|
|
| 18 |
|
| 19 |
label_map = {0: "World", 1: "Sports", 2: "Business", 3: "Sci/Tech"}
|
| 20 |
|
| 21 |
-
# Charger
|
| 22 |
-
dataset = load_dataset("ag_news", split="test
|
|
|
|
| 23 |
|
| 24 |
def evaluate_model(name, inference_func):
|
| 25 |
print(f"\n🔍 Évaluation du modèle : {name}")
|
|
@@ -40,7 +42,10 @@ def evaluate_model(name, inference_func):
|
|
| 40 |
print(f"⚠️ Erreur sur un exemple : {e}")
|
| 41 |
continue
|
| 42 |
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
| 44 |
prob_dist = [scores.get(c, 0.0) for c in label_map.values()]
|
| 45 |
pred_index = list(label_map.values()).index(pred_class)
|
| 46 |
|
|
@@ -58,11 +63,11 @@ def evaluate_model(name, inference_func):
|
|
| 58 |
loss = log_loss(true_labels, all_probs, labels=[0, 1, 2, 3])
|
| 59 |
|
| 60 |
print(f"✅ Résultats {name} :")
|
| 61 |
-
print(f"- Accuracy : {acc:.
|
| 62 |
-
print(f"- F1 Score : {f1:.
|
| 63 |
-
print(f"- Precision : {prec:.
|
| 64 |
-
print(f"- Recall : {rec:.
|
| 65 |
-
print(f"- Log Loss : {loss:.
|
| 66 |
print(f"- Runtime : {runtime:.2f} sec\n")
|
| 67 |
|
| 68 |
return {
|
|
@@ -82,4 +87,5 @@ for name, func in models_to_evaluate.items():
|
|
| 82 |
|
| 83 |
# Affichage résumé
|
| 84 |
df = pd.DataFrame(results)
|
|
|
|
| 85 |
print(df)
|
|
|
|
| 8 |
few_shot_inference,
|
| 9 |
base_model_inference,
|
| 10 |
)
|
| 11 |
+
from datasets import load_dataset
|
| 12 |
|
| 13 |
# Dictionnaire des fonctions à évaluer
|
| 14 |
models_to_evaluate = {
|
|
|
|
| 19 |
|
| 20 |
label_map = {0: "World", 1: "Sports", 2: "Business", 3: "Sci/Tech"}
|
| 21 |
|
| 22 |
+
# Charger tout le test set
|
| 23 |
+
dataset = load_dataset("ag_news", split="test")
|
| 24 |
+
dataset = dataset.shuffle(seed=42).select(range(500))
|
| 25 |
|
| 26 |
def evaluate_model(name, inference_func):
|
| 27 |
print(f"\n🔍 Évaluation du modèle : {name}")
|
|
|
|
| 42 |
print(f"⚠️ Erreur sur un exemple : {e}")
|
| 43 |
continue
|
| 44 |
|
| 45 |
+
if pred_class not in label_map.values():
|
| 46 |
+
print(f"⚠️ Classe prédite inconnue : '{pred_class}', exemple ignoré.")
|
| 47 |
+
continue
|
| 48 |
+
|
| 49 |
prob_dist = [scores.get(c, 0.0) for c in label_map.values()]
|
| 50 |
pred_index = list(label_map.values()).index(pred_class)
|
| 51 |
|
|
|
|
| 63 |
loss = log_loss(true_labels, all_probs, labels=[0, 1, 2, 3])
|
| 64 |
|
| 65 |
print(f"✅ Résultats {name} :")
|
| 66 |
+
print(f"- Accuracy : {acc:.2f}")
|
| 67 |
+
print(f"- F1 Score : {f1:.2f}")
|
| 68 |
+
print(f"- Precision : {prec:.2f}")
|
| 69 |
+
print(f"- Recall : {rec:.2f}")
|
| 70 |
+
print(f"- Log Loss : {loss:.2f}")
|
| 71 |
print(f"- Runtime : {runtime:.2f} sec\n")
|
| 72 |
|
| 73 |
return {
|
|
|
|
| 87 |
|
| 88 |
# Affichage résumé
|
| 89 |
df = pd.DataFrame(results)
|
| 90 |
+
df["loss"] = df["loss"].round(4)
|
| 91 |
print(df)
|