-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfidence.py
More file actions
31 lines (22 loc) · 851 Bytes
/
Copy pathconfidence.py
File metadata and controls
31 lines (22 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from typing import Dict, Any
from scorer import EvalResult
def compute_confidence(result: EvalResult) -> float:
"""
Estimate confidence in the evaluation itself (not model confidence).
Lower confidence when:
- parsing is weak
- borderline scores
- limited signal in response
"""
score = result.weighted_score
# Penalize near-boundary scores
if 3.0 <= score <= 3.6:
score_adj = 0.2
else:
score_adj = 0.0
# Penalize weak parsing signals
item_penalty = 0.2 if result.notes.get("item_count", 0) < 3 else 0
price_penalty = 0.2 if result.notes.get("price_count", 0) < 3 else 0
region_penalty = 0.2 if result.notes.get("region_count", 0) < 2 else 0
confidence = 1.0 - (score_adj + item_penalty + price_penalty + region_penalty)
return round(max(0.0, confidence), 2)