-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathevaluate_your_engine.py
More file actions
46 lines (33 loc) · 1.45 KB
/
Copy pathevaluate_your_engine.py
File metadata and controls
46 lines (33 loc) · 1.45 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
"""Score a custom matcher against a benchmark JSON file.
Usage:
PYTHONPATH=src python3 examples/evaluate_your_engine.py benchmark.json
PYTHONPATH=src python3 examples/evaluate_your_engine.py --offline
"""
from __future__ import annotations
import argparse
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from ssb.benchmark import Benchmark, build, format_scorecard, score
from ssb.matching import BaselineMatcher
from ssb.sources import load_fixture
def my_engine(query: str, candidate: str) -> float:
"""Replace this with your screening API's similarity score in [0, 1]."""
return BaselineMatcher()(query, candidate)
def main(argv=None) -> int:
ap = argparse.ArgumentParser(description=__doc__)
ap.add_argument("benchmark", nargs="?", help="path to benchmark.json")
ap.add_argument("--offline", action="store_true", help="build from synthetic fixture")
ap.add_argument("--threshold", type=float, default=0.85)
ap.add_argument("--name", default="my-engine")
args = ap.parse_args(argv)
if args.offline or args.benchmark is None:
bench = build(load_fixture(), limit=None, seed=0, max_per_class=2)
else:
bench = Benchmark.from_json(args.benchmark)
sc = score(bench, my_engine, threshold=args.threshold, matcher_name=args.name)
print(format_scorecard(sc))
return 0
if __name__ == "__main__":
raise SystemExit(main())