Spaces:
Running
Running
apply_sigmoid
Browse files
app.py
CHANGED
|
@@ -100,6 +100,10 @@ def get_embedding(text: str):
|
|
| 100 |
# ABLATION STUDY
|
| 101 |
# ==========================================
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
def bm25_only(query: str, match_count: int = 50):
|
| 104 |
"""Hanya Lexical / Full-Text Search (Tanpa Vector, Tanpa Gemini, Tanpa Reranker)"""
|
| 105 |
# Catatan: Pastikan Anda sudah membuat RPC 'search_kbli_lexical' di Supabase
|
|
@@ -191,20 +195,12 @@ def hybrid_search_no_gemini(query: str, match_count: int = 50):
|
|
| 191 |
print("Reranker error:", e)
|
| 192 |
return {"results": sorted(candidates, key=lambda x: x.get("similarity", 0), reverse=True)[:10]}
|
| 193 |
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
c["rerank_score"] = s
|
| 199 |
-
if rmax - rmin > 1e-9:
|
| 200 |
-
c["rerank_norm"] = (s - rmin) / (rmax - rmin)
|
| 201 |
-
else:
|
| 202 |
-
c["rerank_norm"] = 0.0
|
| 203 |
-
|
| 204 |
-
db_hybrid_sim = c.get("similarity", 0.0)
|
| 205 |
-
c["final_score"] = (0.5 * db_hybrid_sim) + (0.5 * c["rerank_norm"])
|
| 206 |
|
| 207 |
-
candidates = sorted(candidates, key=lambda x: x["
|
| 208 |
return {"results": candidates[:10]}
|
| 209 |
|
| 210 |
# ==========================================
|
|
|
|
| 100 |
# ABLATION STUDY
|
| 101 |
# ==========================================
|
| 102 |
|
| 103 |
+
# Helper Function
|
| 104 |
+
def apply_sigmoid(logit):
|
| 105 |
+
return 1 / (1 + math.exp(-logit))
|
| 106 |
+
|
| 107 |
def bm25_only(query: str, match_count: int = 50):
|
| 108 |
"""Hanya Lexical / Full-Text Search (Tanpa Vector, Tanpa Gemini, Tanpa Reranker)"""
|
| 109 |
# Catatan: Pastikan Anda sudah membuat RPC 'search_kbli_lexical' di Supabase
|
|
|
|
| 195 |
print("Reranker error:", e)
|
| 196 |
return {"results": sorted(candidates, key=lambda x: x.get("similarity", 0), reverse=True)[:10]}
|
| 197 |
|
| 198 |
+
for c, s in zip(candidates, scores):
|
| 199 |
+
c["rerank_score"] = float(s)
|
| 200 |
+
# Ubah logit jadi probabilitas absolut (0 sampai 1)
|
| 201 |
+
c["rerank_prob"] = apply_sigmoid(float(s))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
|
| 203 |
+
candidates = sorted(candidates, key=lambda x: x["rerank_prob"], reverse=True)
|
| 204 |
return {"results": candidates[:10]}
|
| 205 |
|
| 206 |
# ==========================================
|