Views
No views yet
1from tooltrace_verifier import ToolTraceVerifier
2
3detector = ToolTraceVerifier.from_pretrained("Resonans/tooltrace-verifier", load_lettuce=True)
4
5result = detector.predict(
6 query="Help me check the weather in Beijing.",
7 context='Weather_API: {"location": "Beijing", "weather": "sunny"}',
8 output="The weather in Beijing is rainy.",
9 available_tools="Weather_API: checks weather by location",
10 hallucination_type="contradiction",
11)
12
13print(result["spans"])lookback_lens/.
The large base LM is not included:meta-llama/Llama-3.1-8B-Instruct1{
2 "contradiction": {
3 "threshold": 0.52,
4 "selected_candidate": "sum__lettuce_contradiction:1__lookback_lens__tool_output:1__tool_rules:0",
5 "candidate_meta": {
6 "type": "weighted_sum",
7 "components": [
8 "lettuce_contradiction",
9 "lookback_lens__tool_output",
10 "tool_rules"
11 ],
12 "weights": [
13 1.0,
14 1.0,
15 0.0
16 ]
17 },
18 "validation_metrics": {
19 "dataset": "contradiction",
20 "method": "tooltrace_verifier",
21 "context_mode": "hybrid",
22 "split": "lettuce_group_validation",
23 "n_examples": 1571,
24 "n_gold_hallucinated": 787,
25 "n_pred_hallucinated": 748,
26 "example_precision": 0.9799465240641712,
27 "example_recall": 0.9313850063532402,
28 "example_f1": 0.9550488599348534,
29 "example_accuracy": 0.9560789306174411,
30 "span_precision": 0.7990827045420921,
31 "span_recall": 0.8792121113462478,
32 "span_f1": 0.8372345372810418,
33 "span_macro_precision": 0.8643177693267186,
34 "span_macro_recall": 0.9352901268265252,
35 "span_macro_f1": 0.8853980289420389,
36 "span_total_tp_chars": 5401,
37 "span_total_pred_chars": 6759,
38 "span_total_gold_chars": 6143,
39 "threshold": 0.52
40 },
41 "test_metrics": {
42 "dataset": "contradiction",
43 "method": "tooltrace_verifier",
44 "context_mode": "hybrid",
45 "split": "lettuce_group_test",
46 "n_examples": 2747,
47 "n_gold_hallucinated": 1372,
48 "n_pred_hallucinated": 1312,
49 "example_precision": 0.9763719512195121,
50 "example_recall": 0.9336734693877551,
51 "example_f1": 0.9545454545454546,
52 "example_accuracy": 0.9555879140880961,
53 "span_precision": 0.7633746567934104,
54 "span_recall": 0.8405093440820813,
55 "span_f1": 0.8000872029649008,
56 "span_macro_precision": 0.8618285944573578,
57 "span_macro_recall": 0.9301384040407126,
58 "span_macro_f1": 0.8802671907055231,
59 "span_total_tp_chars": 9175,
60 "span_total_pred_chars": 12019,
61 "span_total_gold_chars": 10916,
62 "threshold": 0.52
63 },
64 "lettuce_checkpoint": "lettuce/contradiction",
65 "lookback_context_mode": "tool_output",
66 "lookback_classifier": "lookback_lens/dataset_contradiction_raw__ctx-tool_output__src-context__w4s4__max2048__lettuce_group_split__solver-lbfgs__iter1000__tol0.0001__C1.joblib",
67 "rules_enabled": true
68 },
69 "missing_tool": {
70 "threshold": 0.36000000000000004,
71 "selected_candidate": "sum__lettuce_missing_tool:0.75__lookback_lens__tools_plus_tool_output:1__tool_rules:1",
72 "candidate_meta": {
73 "type": "weighted_sum",
74 "components": [
75 "lettuce_missing_tool",
76 "lookback_lens__tools_plus_tool_output",
77 "tool_rules"
78 ],
79 "weights": [
80 0.75,
81 1.0,
82 1.0
83 ]
84 },
85 "validation_metrics": {
86 "dataset": "missing_tool",
87 "method": "tooltrace_verifier",
88 "context_mode": "hybrid",
89 "split": "lettuce_group_validation",
90 "n_examples": 1555,
91 "n_gold_hallucinated": 778,
92 "n_pred_hallucinated": 798,
93 "example_precision": 0.968671679197995,
94 "example_recall": 0.993573264781491,
95 "example_f1": 0.9809644670050761,
96 "example_accuracy": 0.9807073954983923,
97 "span_precision": 0.8428213309024613,
98 "span_recall": 0.9438050274339671,
99 "span_f1": 0.8904592788779871,
100 "span_macro_precision": 0.914277505332574,
101 "span_macro_recall": 0.9588100149090778,
102 "span_macro_f1": 0.9281479903401246,
103 "span_total_tp_chars": 36983,
104 "span_total_pred_chars": 43880,
105 "span_total_gold_chars": 39185,
106 "threshold": 0.36000000000000004
107 },
108 "test_metrics": {
109 "dataset": "missing_tool",
110 "method": "tooltrace_verifier",
111 "context_mode": "hybrid",
112 "split": "lettuce_group_test",
113 "n_examples": 2733,
114 "n_gold_hallucinated": 1367,
115 "n_pred_hallucinated": 1397,
116 "example_precision": 0.9742304939155333,
117 "example_recall": 0.9956108266276518,
118 "example_f1": 0.9848046309696092,
119 "example_accuracy": 0.9846322722283205,
120 "span_precision": 0.8427726340807292,
121 "span_recall": 0.9427240059598586,
122 "span_f1": 0.8899507015547972,
123 "span_macro_precision": 0.9164472653398278,
124 "span_macro_recall": 0.9608651994218956,
125 "span_macro_f1": 0.9305490153879314,
126 "span_total_tp_chars": 64537,
127 "span_total_pred_chars": 76577,
128 "span_total_gold_chars": 68458,
129 "threshold": 0.36000000000000004
130 },
131 "lettuce_checkpoint": "lettuce/missing_tool",
132 "lookback_context_mode": "tools_plus_tool_output",
133 "lookback_classifier": "lookback_lens/dataset_missing_tool_raw__ctx-tools_plus_tool_output__src-context__w8s8__max2048__lettuce_group_split.joblib",
134 "rules_enabled": true
135 },
136 "overgeneration": {
137 "threshold": 0.52,
138 "selected_candidate": "sum__lettuce_overgeneration:1__lookback_lens__tool_output:1__tool_rules:0",
139 "candidate_meta": {
140 "type": "weighted_sum",
141 "components": [
142 "lettuce_overgeneration",
143 "lookback_lens__tool_output",
144 "tool_rules"
145 ],
146 "weights": [
147 1.0,
148 1.0,
149 0.0
150 ]
151 },
152 "validation_metrics": {
153 "dataset": "overgeneration",
154 "method": "tooltrace_verifier",
155 "context_mode": "hybrid",
156 "split": "lettuce_group_validation",
157 "n_examples": 1550,
158 "n_gold_hallucinated": 779,
159 "n_pred_hallucinated": 784,
160 "example_precision": 0.9770408163265306,
161 "example_recall": 0.9833119383825417,
162 "example_f1": 0.9801663467690339,
163 "example_accuracy": 0.98,
164 "span_precision": 0.8689510433062921,
165 "span_recall": 0.9347863841611671,
166 "span_f1": 0.900667238386078,
167 "span_macro_precision": 0.9229057843113527,
168 "span_macro_recall": 0.962588027284481,
169 "span_macro_f1": 0.932678173966709,
170 "span_total_tp_chars": 21530,
171 "span_total_pred_chars": 24777,
172 "span_total_gold_chars": 23032,
173 "threshold": 0.52
174 },
175 "test_metrics": {
176 "dataset": "overgeneration",
177 "method": "tooltrace_verifier",
178 "context_mode": "hybrid",
179 "split": "lettuce_group_test",
180 "n_examples": 2716,
181 "n_gold_hallucinated": 1356,
182 "n_pred_hallucinated": 1353,
183 "example_precision": 0.9852180339985218,
184 "example_recall": 0.9830383480825958,
185 "example_f1": 0.9841269841269841,
186 "example_accuracy": 0.9841678939617083,
187 "span_precision": 0.8816129107271585,
188 "span_recall": 0.9298310156230839,
189 "span_f1": 0.9050802139037434,
190 "span_macro_precision": 0.9300223131199776,
191 "span_macro_recall": 0.9660561378593199,
192 "span_macro_f1": 0.9381312056411896,
193 "span_total_tp_chars": 37912,
194 "span_total_pred_chars": 43003,
195 "span_total_gold_chars": 40773,
196 "threshold": 0.52
197 },
198 "lettuce_checkpoint": "lettuce/overgeneration",
199 "lookback_context_mode": "tool_output",
200 "lookback_classifier": "lookback_lens/dataset_overgeneration_raw__ctx-tool_output__src-context__w4s4__max2048__lettuce_group_split__solver-lbfgs__iter1000__tol0.0001__C1.joblib",
201 "rules_enabled": true
202 }
203}1lettuce/ Fine-tuned LettuceDetect checkpoints
2lookback_lens/ sklearn/joblib LookBackLens classifiers
3rules/ Symbolic tool-aware rule config
4tooltrace_verifier/ Inference code
5results/ Evaluation tables and predictions
6config.json Composite model config
7hybrid_config.json Validation-tuned hybrid route config
8thresholds.json Per-route thresholds