Spaces:
Running
Running
| """Verifikasi cepat lapis ML Field-Fit: deteksi salah-field lintas field + dedup.""" | |
| import sys | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "src")) | |
| from field_fit.field_fit_detector import FieldFitDetector | |
| det = FieldFitDetector(use_ml=True) | |
| det.load() | |
| print("ML aktif:", det.ml_active, "\n") | |
| # (teks, field_sekarang, harapan: target field atau None bila tak ditandai) | |
| CASES = [ | |
| ("Kamu adalah seorang dokter spesialis anak", "task", "role"), # rule+ML, dedup -> role | |
| ("Sajikan dalam bentuk tabel dengan kolom tujuan", "task", "outputFormat"), | |
| ("Khusus untuk siswa kelas 3 SD", "task", "audience"), | |
| ("Jangan lebih dari 100 kata", "task", "constraints"), | |
| ("Gunakan bahasa yang ramah dan santai", "context", "tone"), | |
| ("Buatkan rencana pembelajaran tentang fotosintesis", "task", None), # benar di Task | |
| ("Untuk kelas 7 SMP, durasi 80 menit", "context", None), # benar di Context | |
| ("Gunakan buku paket halaman 20-35", "references", None), # benar di References | |
| ] | |
| ok = 0 | |
| for text, cur, expect in CASES: | |
| fs = det.detect(text, cur) | |
| got = fs[0].target_field if fs else None | |
| n = len(fs) | |
| verdict = "OK " if got == expect else "BEDA" | |
| if got == expect: | |
| ok += 1 | |
| print(f"[{verdict}] field={cur:11} -> target={str(got):12} (harap {str(expect):12}) " | |
| f"n={n} '{text[:42]}'") | |
| print(f"\nSesuai harapan: {ok}/{len(CASES)}") | |