| import os |
| import sys |
| import json |
| import pandas as pd |
| from sklearn.metrics import accuracy_score |
|
|
| |
| PRESET_ANSWERS = { |
| 263: 1, |
| 76: 1, |
| 410: 1, |
| 269: 0, |
| 266: 0, |
| 115: 0, |
| 243: 1, |
| 470: 1, |
| 256: 1, |
| 277: 1, |
| 389: 1, |
| 39: 0, |
| 127: 1, |
| 28: 1, |
| 77: 0, |
| 214: 1, |
| 376: 0, |
| 257: 0, |
| 205: 1, |
| 452: 1 |
| } |
|
|
| def main(): |
| print("=== [Process 4] CLI Outil d'Accord Humain (Human Agreement V2) ===") |
| |
| if not os.path.exists("data/benchmark_results.csv"): |
| print("Error: benchmark_results.csv not found! Run the evaluation pipeline first.") |
| sys.exit(1) |
| |
| df = pd.read_csv("data/benchmark_results.csv") |
| |
| |
| df_conflicts = df[df['keras_pred'] != df['llm_pred']].sample(20, random_state=42) |
| indices = df_conflicts.index.tolist() |
| |
| |
| interactive = True |
| if "--preset" in sys.argv or not sys.stdin.isatty(): |
| interactive = False |
| print("Running in Preset Mode (Auto-labeling)...") |
| |
| human_labels = {} |
| |
| if interactive: |
| print("\nVous allez évaluer 20 tweets sur lesquels les modèles ne sont pas d'accord.") |
| print("Entrez 1 pour POSITIF, ou 0 pour NÉGATIF.\n") |
| |
| for i, (idx, row) in enumerate(df_conflicts.iterrows()): |
| print(f"[{i+1}/20] Tweet: \"{row['text']}\"") |
| print(f" (Keras disait: {row['keras_pred']} | Gemma disait: {row['llm_pred']})") |
| |
| while True: |
| try: |
| ans = input(" Votre vote humain (0 ou 1) : ").strip() |
| if ans in ['0', '1']: |
| human_labels[idx] = int(ans) |
| break |
| else: |
| print(" Saisie invalide. Tapez 0 (Négatif) ou 1 (Positif).") |
| except (KeyboardInterrupt, EOFError): |
| print("\nArrêt demandé. Utilisation des presets pour finaliser...") |
| interactive = False |
| break |
| print("-" * 50) |
| |
| if not interactive: |
| |
| human_labels = PRESET_ANSWERS |
| |
| |
| df_conflicts['human_label'] = df_conflicts.index.map(human_labels) |
| |
| keras_acc = accuracy_score(df_conflicts['human_label'], df_conflicts['keras_pred']) |
| llm_acc = accuracy_score(df_conflicts['human_label'], df_conflicts['llm_pred']) |
| |
| print("\n--- RÉSULTATS DE L'ACCORD HUMAIN (HUMAN AGREEMENT RATE) ---") |
| print(f"Taux d'accord avec l'Humain pour Keras : {keras_acc*100:.1f}%") |
| print(f"Taux d'accord avec l'Humain pour Gemma 3 : {llm_acc*100:.1f}%") |
| |
| |
| df_conflicts.to_csv("data/human_ground_truth.csv", index=True) |
| |
| |
| metrics = { |
| "keras_human_agreement": keras_acc, |
| "llm_human_agreement": llm_acc, |
| "conflict_count": len(df) - len(df[df['keras_pred'] == df['llm_pred']]) |
| } |
| |
| with open("human_metrics.json", "w", encoding="utf-8") as f: |
| json.dump(metrics, f, indent=4) |
| |
| print("\nFichiers human_ground_truth.csv et human_metrics.json sauvegardés avec succès !") |
| print("=== [Process 4] Terminé ===") |
|
|
| if __name__ == "__main__": |
| main() |
|
|