You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/usage/evals.mdx
+120-1Lines changed: 120 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -256,4 +256,123 @@ When you run this code, you will see a TUI that includes:
256
256
-**Event Log:** A timestamped log of key events, such as a sample failing.
257
257
-**Summary Statistics:** A live-updating summary of the pass/fail rate.
258
258
259
-
Using `.console()` is perfect for interactive development and for monitoring large benchmark runs.
259
+
Using `.console()` is perfect for interactive development and for monitoring large benchmark runs.
260
+
261
+
### **Advanced Patterns**
262
+
263
+
Once you are comfortable with the basics, you can use these advanced features to build more resilient and sophisticated evaluation pipelines.
264
+
265
+
#### **Loading Datasets from Files**
266
+
267
+
For larger evaluations, defining your dataset in-memory isn't practical. You can load a dataset directly from a file by providing a string or `pathlib.Path` object. Supported formats include `.jsonl`, `.csv`, `.json`, and `.yaml`.
268
+
269
+
Let's assume you have a file named `dataset.jsonl` with the following content:
# Simply pass the file path to the `dataset` argument.
290
+
file_based_eval = get_capital.as_eval(
291
+
dataset="dataset.jsonl",
292
+
dataset_input_mapping=["country"],
293
+
scorers=[correctness_check],
294
+
assert_scores=["is_correct"],
295
+
)
296
+
297
+
result =await file_based_eval.run()
298
+
print(f"Pass Rate: {result.pass_rate:.2%}")
299
+
```
300
+
301
+
#### **Customizing Input Mapping**
302
+
303
+
The system can automatically map dataset columns to task parameters if their names match. However, if your dataset columns have different names than your task's parameters, you must provide an explicit mapping using `dataset_input_mapping`.
304
+
305
+
Here's how you would map a dataset with a `location` column to the task's `country` parameter.
When working with large datasets or non-deterministic tasks, some samples may fail due to transient issues or bad data. You can configure your `Eval` to tolerate a certain number of failures without stopping the entire run.
335
+
336
+
-`max_errors`: The total number of sample errors to tolerate before stopping.
337
+
-`max_consecutive_errors`: The number of *consecutive* sample errors to tolerate before stopping.
print(f"Samples with errors: {len([s for s in result.samples if s.error])}")
360
+
```
361
+
362
+
#### **Programmatic Event Streaming**
363
+
364
+
The `.console()` method is a convenient wrapper around a lower-level event stream. If you need to build custom logic or UIs based on evaluation events, you can consume this stream directly using `async with eval.stream()`.
365
+
366
+
This is useful for advanced cases like sending real-time alerts or implementing custom early-stopping logic.
367
+
368
+
```python
369
+
# Uses the `capital_eval` from a previous example.
370
+
asyncwith capital_eval.stream() as stream:
371
+
asyncfor event in stream:
372
+
ifisinstance(event, dn.eval.SampleComplete):
373
+
if event.sample.failed:
374
+
print(f"Detected a failure on sample {event.sample.index}!")
375
+
elifisinstance(event, dn.eval.EvalEnd):
376
+
print(f"Evaluation finished with stop reason: {event.stop_reason}")
0 commit comments