Repository navigation
Expand file tree
/
Copy pathminival_config.py
More file actions
82 lines (76 loc) · 3.21 KB
/
Copy pathminival_config.py
File metadata and controls
82 lines (76 loc) · 3.21 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from minival.dag import (
EvaluationGraph,
TaskNode,
BinaryJudgeNode,
NonBinaryJudgeNode,
VerdictNode,
)
from minival.metrics import DAGMetric, AnswerRelevancy, Faithfulness
from minival.types import TestCaseParams
# ---------------------------------------------------------------------------
# Built-in metrics
# ---------------------------------------------------------------------------
# AnswerRelevancy: checks whether the output is relevant to the input question.
# Faithfulness: checks whether the output is grounded in the retrieval context.
# Both accept a `threshold` (0.0–1.0) — scores at or above this value pass.
answer_relevancy = AnswerRelevancy(threshold=0.7)
faithfulness = Faithfulness(threshold=0.7)
# ---------------------------------------------------------------------------
# Custom DAG metric
# ---------------------------------------------------------------------------
# Build a DAG by composing node primitives:
#
# TaskNode — calls the LLM to extract/transform data, stores it
# under `output_label`, then fans out to `children`.
# BinaryJudgeNode — yes/no criterion; must have exactly two VerdictNode
# children (verdict=True and verdict=False).
# NonBinaryJudgeNode — categorical criterion; routes to the matching
# VerdictNode from two or more string verdicts.
# VerdictNode — leaf that either returns a `score` (int 0–10,
# normalised to 0.0–1.0) or delegates to a `child` node.
#
# Evaluation params available to nodes:
# TestCaseParams.INPUT, OUTPUT, EXPECTED_OUTPUT, RETRIEVAL_CONTEXT
cite_check = TaskNode(
instructions="List every factual claim made in the output.",
evaluation_params=[TestCaseParams.OUTPUT, TestCaseParams.RETRIEVAL_CONTEXT],
output_label="Claims",
children=[
BinaryJudgeNode(
criteria=(
"Are ALL claims in 'Claims' directly supported by the "
"retrieval context? Answer true only if every claim is covered."
),
children=[
VerdictNode(verdict=False, score=0),
VerdictNode(
verdict=True,
child=NonBinaryJudgeNode(
criteria=(
"How concise is the output relative to its claims? "
"Choose: 'concise', 'acceptable', or 'verbose'."
),
children=[
VerdictNode(verdict="concise", score=10),
VerdictNode(verdict="acceptable", score=7),
VerdictNode(verdict="verbose", score=4),
],
),
),
],
)
],
)
citation_quality = DAGMetric(
name="Citation Quality",
dag=EvaluationGraph(root_nodes=[cite_check]),
threshold=0.5,
)
# ---------------------------------------------------------------------------
# metrics — this list is required; the runner reads it from this module.
# ---------------------------------------------------------------------------
metrics = [
answer_relevancy,
faithfulness,
citation_quality,
]