Spaces:
Sleeping
Sleeping
Commit
·
65e5e42
1
Parent(s):
89f0e63
correction bug
Browse files
src/cuml_trainer.py
CHANGED
@@ -71,11 +71,19 @@ class CuMLTrainer(BaseTrainer, ABC):
|
|
71 |
|
72 |
data = cudf.read_csv(self.data_path)
|
73 |
|
74 |
-
# Identification
|
75 |
feature_columns = [col for col in data.columns if col != self.target_column]
|
76 |
if not feature_columns:
|
77 |
raise ValueError("Aucune colonne de feature trouvée.")
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
labels = data[self.target_column].astype(self._get_label_dtype()).values
|
80 |
|
81 |
# Premier split: 80% train, 20% temp (pour val+test)
|
|
|
71 |
|
72 |
data = cudf.read_csv(self.data_path)
|
73 |
|
74 |
+
# Identification des features
|
75 |
feature_columns = [col for col in data.columns if col != self.target_column]
|
76 |
if not feature_columns:
|
77 |
raise ValueError("Aucune colonne de feature trouvée.")
|
78 |
+
|
79 |
+
# Concaténation manuelle des features (agg n'est pas supporté pour les colonnes string dans cuDF)
|
80 |
+
# Commencer avec la première colonne
|
81 |
+
texts_concatenated = data[feature_columns[0]].astype(str)
|
82 |
+
|
83 |
+
# Ajouter les autres colonnes avec un espace comme séparateur
|
84 |
+
for col in feature_columns[1:]:
|
85 |
+
texts_concatenated = texts_concatenated.str.cat(data[col].astype(str), sep=' ')
|
86 |
+
|
87 |
labels = data[self.target_column].astype(self._get_label_dtype()).values
|
88 |
|
89 |
# Premier split: 80% train, 20% temp (pour val+test)
|
src/interfaces/metrics_calculator.py
CHANGED
@@ -95,40 +95,19 @@ class DefaultMetricsCalculator(MetricsCalculator):
|
|
95 |
Tuple contenant (précision optimale, rappel optimal, F1 score optimal, seuil optimal)
|
96 |
"""
|
97 |
# Ajouter le seuil 1.0 à thresholds (qui n'est pas inclus par défaut dans precision_recall_curve)
|
98 |
-
|
99 |
-
thresholds_with_one = cp.append(thresholds, cp.array([1.0]))
|
100 |
-
else:
|
101 |
-
thresholds_with_one = cp.array([1.0])
|
102 |
|
103 |
# Calculer le F1 score pour chaque point de la courbe
|
104 |
# F1 = 2 * (precision * recall) / (precision + recall)
|
105 |
-
|
106 |
-
denominator = precision + recall
|
107 |
-
# Créer un masque pour éviter la division par zéro
|
108 |
-
mask = denominator > 0
|
109 |
-
|
110 |
-
# Initialiser le F1 score avec des zéros
|
111 |
-
f1_scores = cp.zeros_like(precision)
|
112 |
-
# Calculer le F1 score uniquement où le dénominateur n'est pas zéro
|
113 |
-
f1_scores[mask] = 2 * (precision[mask] * recall[mask]) / denominator[mask]
|
114 |
|
115 |
# Trouver l'indice du F1 score maximal
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
if best_idx < len(thresholds_with_one):
|
124 |
-
best_threshold = float(thresholds_with_one[best_idx])
|
125 |
-
else:
|
126 |
-
best_threshold = 0.5 # Valeur par défaut si l'indice est hors limites
|
127 |
-
else:
|
128 |
-
# Valeurs par défaut si les tableaux sont vides
|
129 |
-
best_precision = 0.0
|
130 |
-
best_recall = 0.0
|
131 |
-
best_f1 = 0.0
|
132 |
-
best_threshold = 0.5
|
133 |
|
134 |
return best_precision, best_recall, best_f1, best_threshold
|
|
|
95 |
Tuple contenant (précision optimale, rappel optimal, F1 score optimal, seuil optimal)
|
96 |
"""
|
97 |
# Ajouter le seuil 1.0 à thresholds (qui n'est pas inclus par défaut dans precision_recall_curve)
|
98 |
+
thresholds_with_one = cp.append(thresholds, cp.array([1.0]))
|
|
|
|
|
|
|
99 |
|
100 |
# Calculer le F1 score pour chaque point de la courbe
|
101 |
# F1 = 2 * (precision * recall) / (precision + recall)
|
102 |
+
f1_scores = 2 * (precision * recall) / (precision + recall)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
# Trouver l'indice du F1 score maximal
|
105 |
+
best_idx = cp.argmax(f1_scores)
|
106 |
+
best_precision = float(precision[best_idx])
|
107 |
+
best_recall = float(recall[best_idx])
|
108 |
+
best_f1 = float(f1_scores[best_idx])
|
109 |
+
|
110 |
+
# Obtenir le seuil optimal
|
111 |
+
best_threshold = float(thresholds_with_one[best_idx])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
return best_precision, best_recall, best_f1, best_threshold
|
src/trainers/huggingface/huggingface_transformer_trainer.py
CHANGED
@@ -79,42 +79,21 @@ def calculate_optimal_f1(precision: cp.ndarray, recall: cp.ndarray, thresholds:
|
|
79 |
Tuple contenant (précision optimale, rappel optimal, F1 score optimal, seuil optimal)
|
80 |
"""
|
81 |
# Ajouter le seuil 1.0 à thresholds (qui n'est pas inclus par défaut dans precision_recall_curve)
|
82 |
-
|
83 |
-
|
84 |
-
else:
|
85 |
-
thresholds_with_one = cp.array([1.0])
|
86 |
-
|
87 |
# Calculer le F1 score pour chaque point de la courbe
|
88 |
# F1 = 2 * (precision * recall) / (precision + recall)
|
89 |
-
|
90 |
-
denominator = precision + recall
|
91 |
-
# Créer un masque pour éviter la division par zéro
|
92 |
-
mask = denominator > 0
|
93 |
-
|
94 |
-
# Initialiser le F1 score avec des zéros
|
95 |
-
f1_scores = cp.zeros_like(precision)
|
96 |
-
# Calculer le F1 score uniquement où le dénominateur n'est pas zéro
|
97 |
-
f1_scores[mask] = 2 * (precision[mask] * recall[mask]) / denominator[mask]
|
98 |
|
99 |
# Trouver l'indice du F1 score maximal
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
best_threshold = float(thresholds_with_one[best_idx])
|
109 |
-
else:
|
110 |
-
best_threshold = 0.5 # Valeur par défaut si l'indice est hors limites
|
111 |
-
else:
|
112 |
-
# Valeurs par défaut si les tableaux sont vides
|
113 |
-
best_precision = 0.0
|
114 |
-
best_recall = 0.0
|
115 |
-
best_f1 = 0.0
|
116 |
-
best_threshold = 0.5
|
117 |
-
|
118 |
return best_precision, best_recall, best_f1, best_threshold
|
119 |
|
120 |
class HuggingFaceTransformerTrainer(BaseTrainer):
|
|
|
79 |
Tuple contenant (précision optimale, rappel optimal, F1 score optimal, seuil optimal)
|
80 |
"""
|
81 |
# Ajouter le seuil 1.0 à thresholds (qui n'est pas inclus par défaut dans precision_recall_curve)
|
82 |
+
thresholds_with_one = cp.append(thresholds, cp.array([1.0]))
|
83 |
+
|
|
|
|
|
|
|
84 |
# Calculer le F1 score pour chaque point de la courbe
|
85 |
# F1 = 2 * (precision * recall) / (precision + recall)
|
86 |
+
f1_scores = 2 * (precision * recall) / (precision + recall)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
# Trouver l'indice du F1 score maximal
|
89 |
+
best_idx = cp.argmax(f1_scores)
|
90 |
+
best_precision = float(precision[best_idx])
|
91 |
+
best_recall = float(recall[best_idx])
|
92 |
+
best_f1 = float(f1_scores[best_idx])
|
93 |
+
|
94 |
+
# Obtenir le seuil optimal
|
95 |
+
best_threshold = float(thresholds_with_one[best_idx])
|
96 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
return best_precision, best_recall, best_f1, best_threshold
|
98 |
|
99 |
class HuggingFaceTransformerTrainer(BaseTrainer):
|