valor-lite 0.33.15__py3-none-any.whl → 0.33.17__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of valor-lite might be problematic. Click here for more details.
- valor_lite/classification/metric.py +20 -0
- valor_lite/object_detection/annotation.py +0 -24
- valor_lite/object_detection/manager.py +72 -81
- valor_lite/object_detection/metric.py +20 -0
- valor_lite/schemas.py +0 -6
- valor_lite/semantic_segmentation/computation.py +2 -2
- valor_lite/semantic_segmentation/metric.py +20 -0
- valor_lite/text_generation/__init__.py +15 -0
- valor_lite/text_generation/annotation.py +56 -0
- valor_lite/text_generation/computation.py +609 -0
- valor_lite/text_generation/llm/__init__.py +0 -0
- valor_lite/text_generation/llm/exceptions.py +14 -0
- valor_lite/text_generation/llm/generation.py +903 -0
- valor_lite/text_generation/llm/instructions.py +814 -0
- valor_lite/text_generation/llm/integrations.py +226 -0
- valor_lite/text_generation/llm/utilities.py +43 -0
- valor_lite/text_generation/llm/validators.py +68 -0
- valor_lite/text_generation/manager.py +697 -0
- valor_lite/text_generation/metric.py +381 -0
- {valor_lite-0.33.15.dist-info → valor_lite-0.33.17.dist-info}/METADATA +11 -3
- valor_lite-0.33.17.dist-info/RECORD +38 -0
- {valor_lite-0.33.15.dist-info → valor_lite-0.33.17.dist-info}/WHEEL +1 -1
- valor_lite-0.33.15.dist-info/RECORD +0 -27
- {valor_lite-0.33.15.dist-info → valor_lite-0.33.17.dist-info}/LICENSE +0 -0
- {valor_lite-0.33.15.dist-info → valor_lite-0.33.17.dist-info}/top_level.txt +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
1
2
|
from enum import Enum
|
|
2
3
|
|
|
3
4
|
from valor_lite.schemas import BaseMetric
|
|
@@ -14,6 +15,7 @@ class MetricType(Enum):
|
|
|
14
15
|
ConfusionMatrix = "ConfusionMatrix"
|
|
15
16
|
|
|
16
17
|
|
|
18
|
+
@dataclass
|
|
17
19
|
class Metric(BaseMetric):
|
|
18
20
|
"""
|
|
19
21
|
Classification Metric.
|
|
@@ -28,6 +30,24 @@ class Metric(BaseMetric):
|
|
|
28
30
|
A dictionary containing metric parameters.
|
|
29
31
|
"""
|
|
30
32
|
|
|
33
|
+
def __post_init__(self):
|
|
34
|
+
if not isinstance(self.type, str):
|
|
35
|
+
raise TypeError(
|
|
36
|
+
f"Metric type should be of type 'str': {self.type}"
|
|
37
|
+
)
|
|
38
|
+
elif not isinstance(self.value, (int, float, dict)):
|
|
39
|
+
raise TypeError(
|
|
40
|
+
f"Metric value must be of type 'int', 'float' or 'dict': {self.value}"
|
|
41
|
+
)
|
|
42
|
+
elif not isinstance(self.parameters, dict):
|
|
43
|
+
raise TypeError(
|
|
44
|
+
f"Metric parameters must be of type 'dict[str, Any]': {self.parameters}"
|
|
45
|
+
)
|
|
46
|
+
elif not all([isinstance(k, str) for k in self.parameters.keys()]):
|
|
47
|
+
raise TypeError(
|
|
48
|
+
f"Metric parameter dictionary should only have keys with type 'str': {self.parameters}"
|
|
49
|
+
)
|
|
50
|
+
|
|
31
51
|
@classmethod
|
|
32
52
|
def precision(
|
|
33
53
|
cls,
|
|
@@ -142,18 +142,6 @@ class Polygon:
|
|
|
142
142
|
xmin, ymin, xmax, ymax = self.shape.bounds
|
|
143
143
|
return (xmin, xmax, ymin, ymax)
|
|
144
144
|
|
|
145
|
-
@property
|
|
146
|
-
def annotation(self) -> ShapelyPolygon:
|
|
147
|
-
"""
|
|
148
|
-
Returns the annotation's data representation.
|
|
149
|
-
|
|
150
|
-
Returns
|
|
151
|
-
-------
|
|
152
|
-
shapely.geometry.Polygon
|
|
153
|
-
The polygon shape.
|
|
154
|
-
"""
|
|
155
|
-
return self.shape
|
|
156
|
-
|
|
157
145
|
|
|
158
146
|
@dataclass
|
|
159
147
|
class Bitmask:
|
|
@@ -222,18 +210,6 @@ class Bitmask:
|
|
|
222
210
|
rows, cols = np.nonzero(self.mask)
|
|
223
211
|
return (cols.min(), cols.max(), rows.min(), rows.max())
|
|
224
212
|
|
|
225
|
-
@property
|
|
226
|
-
def annotation(self) -> NDArray[np.bool_]:
|
|
227
|
-
"""
|
|
228
|
-
Returns the annotation's data representation.
|
|
229
|
-
|
|
230
|
-
Returns
|
|
231
|
-
-------
|
|
232
|
-
NDArray[np.bool_]
|
|
233
|
-
The binary mask array.
|
|
234
|
-
"""
|
|
235
|
-
return self.mask
|
|
236
|
-
|
|
237
213
|
|
|
238
214
|
@dataclass
|
|
239
215
|
class Detection:
|
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
from collections import defaultdict
|
|
2
2
|
from dataclasses import dataclass
|
|
3
|
-
from typing import Type
|
|
4
3
|
|
|
5
4
|
import numpy as np
|
|
6
|
-
import valor_lite.object_detection.annotation as annotation
|
|
7
5
|
from numpy.typing import NDArray
|
|
8
6
|
from tqdm import tqdm
|
|
9
|
-
from valor_lite.object_detection.annotation import
|
|
10
|
-
Bitmask,
|
|
11
|
-
BoundingBox,
|
|
12
|
-
Detection,
|
|
13
|
-
Polygon,
|
|
14
|
-
)
|
|
7
|
+
from valor_lite.object_detection.annotation import Detection
|
|
15
8
|
from valor_lite.object_detection.computation import (
|
|
16
9
|
compute_bbox_iou,
|
|
17
10
|
compute_bitmask_iou,
|
|
@@ -307,7 +300,7 @@ class Evaluator:
|
|
|
307
300
|
filter_: Filter | None = None,
|
|
308
301
|
) -> dict[MetricType, list[Metric]]:
|
|
309
302
|
"""
|
|
310
|
-
Computes all
|
|
303
|
+
Computes all available metrics.
|
|
311
304
|
|
|
312
305
|
Parameters
|
|
313
306
|
----------
|
|
@@ -396,74 +389,47 @@ class DataLoader:
|
|
|
396
389
|
|
|
397
390
|
return self._evaluator.label_to_index[label]
|
|
398
391
|
|
|
399
|
-
def
|
|
392
|
+
def _cache_pairs(
|
|
400
393
|
self,
|
|
401
394
|
uid_index: int,
|
|
402
395
|
groundtruths: list,
|
|
403
396
|
predictions: list,
|
|
404
|
-
|
|
397
|
+
ious: NDArray[np.float64],
|
|
405
398
|
) -> None:
|
|
406
399
|
"""
|
|
407
400
|
Compute IOUs between groundtruths and preditions before storing as pairs.
|
|
408
401
|
|
|
409
402
|
Parameters
|
|
410
403
|
----------
|
|
411
|
-
uid_index: int
|
|
404
|
+
uid_index : int
|
|
412
405
|
The index of the detection.
|
|
413
|
-
groundtruths: list
|
|
406
|
+
groundtruths : list
|
|
414
407
|
A list of groundtruths.
|
|
415
|
-
predictions: list
|
|
408
|
+
predictions : list
|
|
416
409
|
A list of predictions.
|
|
417
|
-
|
|
418
|
-
|
|
410
|
+
ious : NDArray[np.float64]
|
|
411
|
+
An array with shape (n_preds, n_gts) containing IOUs.
|
|
419
412
|
"""
|
|
420
413
|
|
|
421
|
-
pairs = list()
|
|
422
|
-
n_predictions = len(predictions)
|
|
423
|
-
n_groundtruths = len(groundtruths)
|
|
424
|
-
|
|
425
|
-
all_pairs = np.array(
|
|
426
|
-
[
|
|
427
|
-
np.array([gann, pann])
|
|
428
|
-
for _, _, _, pann in predictions
|
|
429
|
-
for _, _, gann in groundtruths
|
|
430
|
-
]
|
|
431
|
-
)
|
|
432
|
-
|
|
433
|
-
match annotation_type:
|
|
434
|
-
case annotation.BoundingBox:
|
|
435
|
-
ious = compute_bbox_iou(all_pairs)
|
|
436
|
-
case annotation.Polygon:
|
|
437
|
-
ious = compute_polygon_iou(all_pairs)
|
|
438
|
-
case annotation.Bitmask:
|
|
439
|
-
ious = compute_bitmask_iou(all_pairs)
|
|
440
|
-
case _:
|
|
441
|
-
raise ValueError(
|
|
442
|
-
f"Invalid annotation type `{annotation_type}`."
|
|
443
|
-
)
|
|
444
|
-
|
|
445
|
-
ious = ious.reshape(n_predictions, n_groundtruths)
|
|
446
414
|
predictions_with_iou_of_zero = np.where((ious < 1e-9).all(axis=1))[0]
|
|
447
415
|
groundtruths_with_iou_of_zero = np.where((ious < 1e-9).all(axis=0))[0]
|
|
448
416
|
|
|
449
|
-
pairs
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
]
|
|
466
|
-
)
|
|
417
|
+
pairs = [
|
|
418
|
+
np.array(
|
|
419
|
+
[
|
|
420
|
+
float(uid_index),
|
|
421
|
+
float(gidx),
|
|
422
|
+
float(pidx),
|
|
423
|
+
ious[pidx, gidx],
|
|
424
|
+
float(glabel),
|
|
425
|
+
float(plabel),
|
|
426
|
+
float(score),
|
|
427
|
+
]
|
|
428
|
+
)
|
|
429
|
+
for pidx, plabel, score in predictions
|
|
430
|
+
for gidx, glabel in groundtruths
|
|
431
|
+
if ious[pidx, gidx] >= 1e-9
|
|
432
|
+
]
|
|
467
433
|
pairs.extend(
|
|
468
434
|
[
|
|
469
435
|
np.array(
|
|
@@ -496,13 +462,12 @@ class DataLoader:
|
|
|
496
462
|
for index in groundtruths_with_iou_of_zero
|
|
497
463
|
]
|
|
498
464
|
)
|
|
499
|
-
|
|
500
465
|
self.pairs.append(np.array(pairs))
|
|
501
466
|
|
|
502
467
|
def _add_data(
|
|
503
468
|
self,
|
|
504
469
|
detections: list[Detection],
|
|
505
|
-
|
|
470
|
+
detection_ious: list[NDArray[np.float64]],
|
|
506
471
|
show_progress: bool = False,
|
|
507
472
|
):
|
|
508
473
|
"""
|
|
@@ -512,13 +477,15 @@ class DataLoader:
|
|
|
512
477
|
----------
|
|
513
478
|
detections : list[Detection]
|
|
514
479
|
A list of Detection objects.
|
|
515
|
-
|
|
516
|
-
|
|
480
|
+
detection_ious : list[NDArray[np.float64]]
|
|
481
|
+
A list of arrays containing IOUs per detection.
|
|
517
482
|
show_progress : bool, default=False
|
|
518
483
|
Toggle for tqdm progress bar.
|
|
519
484
|
"""
|
|
520
485
|
disable_tqdm = not show_progress
|
|
521
|
-
for detection in tqdm(
|
|
486
|
+
for detection, ious in tqdm(
|
|
487
|
+
zip(detections, detection_ious), disable=disable_tqdm
|
|
488
|
+
):
|
|
522
489
|
|
|
523
490
|
# update metadata
|
|
524
491
|
self._evaluator.n_datums += 1
|
|
@@ -541,11 +508,6 @@ class DataLoader:
|
|
|
541
508
|
predictions = list()
|
|
542
509
|
|
|
543
510
|
for gidx, gann in enumerate(detection.groundtruths):
|
|
544
|
-
if not isinstance(gann, annotation_type):
|
|
545
|
-
raise ValueError(
|
|
546
|
-
f"Expected {annotation_type}, but annotation is of type {type(gann)}."
|
|
547
|
-
)
|
|
548
|
-
|
|
549
511
|
self._evaluator.groundtruth_examples[uid_index][
|
|
550
512
|
gidx
|
|
551
513
|
] = gann.extrema
|
|
@@ -556,16 +518,10 @@ class DataLoader:
|
|
|
556
518
|
(
|
|
557
519
|
gidx,
|
|
558
520
|
label_idx,
|
|
559
|
-
gann.annotation,
|
|
560
521
|
)
|
|
561
522
|
)
|
|
562
523
|
|
|
563
524
|
for pidx, pann in enumerate(detection.predictions):
|
|
564
|
-
if not isinstance(pann, annotation_type):
|
|
565
|
-
raise ValueError(
|
|
566
|
-
f"Expected {annotation_type}, but annotation is of type {type(pann)}."
|
|
567
|
-
)
|
|
568
|
-
|
|
569
525
|
self._evaluator.prediction_examples[uid_index][
|
|
570
526
|
pidx
|
|
571
527
|
] = pann.extrema
|
|
@@ -577,15 +533,14 @@ class DataLoader:
|
|
|
577
533
|
pidx,
|
|
578
534
|
label_idx,
|
|
579
535
|
pscore,
|
|
580
|
-
pann.annotation,
|
|
581
536
|
)
|
|
582
537
|
)
|
|
583
538
|
|
|
584
|
-
self.
|
|
539
|
+
self._cache_pairs(
|
|
585
540
|
uid_index=uid_index,
|
|
586
541
|
groundtruths=groundtruths,
|
|
587
542
|
predictions=predictions,
|
|
588
|
-
|
|
543
|
+
ious=ious,
|
|
589
544
|
)
|
|
590
545
|
|
|
591
546
|
def add_bounding_boxes(
|
|
@@ -603,10 +558,22 @@ class DataLoader:
|
|
|
603
558
|
show_progress : bool, default=False
|
|
604
559
|
Toggle for tqdm progress bar.
|
|
605
560
|
"""
|
|
561
|
+
ious = [
|
|
562
|
+
compute_bbox_iou(
|
|
563
|
+
np.array(
|
|
564
|
+
[
|
|
565
|
+
[gt.extrema, pd.extrema]
|
|
566
|
+
for pd in detection.predictions
|
|
567
|
+
for gt in detection.groundtruths
|
|
568
|
+
]
|
|
569
|
+
)
|
|
570
|
+
).reshape(len(detection.predictions), len(detection.groundtruths))
|
|
571
|
+
for detection in detections
|
|
572
|
+
]
|
|
606
573
|
return self._add_data(
|
|
607
574
|
detections=detections,
|
|
575
|
+
detection_ious=ious,
|
|
608
576
|
show_progress=show_progress,
|
|
609
|
-
annotation_type=BoundingBox,
|
|
610
577
|
)
|
|
611
578
|
|
|
612
579
|
def add_polygons(
|
|
@@ -624,10 +591,22 @@ class DataLoader:
|
|
|
624
591
|
show_progress : bool, default=False
|
|
625
592
|
Toggle for tqdm progress bar.
|
|
626
593
|
"""
|
|
594
|
+
ious = [
|
|
595
|
+
compute_polygon_iou(
|
|
596
|
+
np.array(
|
|
597
|
+
[
|
|
598
|
+
[gt.shape, pd.shape] # type: ignore - using the AttributeError as a validator
|
|
599
|
+
for pd in detection.predictions
|
|
600
|
+
for gt in detection.groundtruths
|
|
601
|
+
]
|
|
602
|
+
)
|
|
603
|
+
).reshape(len(detection.predictions), len(detection.groundtruths))
|
|
604
|
+
for detection in detections
|
|
605
|
+
]
|
|
627
606
|
return self._add_data(
|
|
628
607
|
detections=detections,
|
|
608
|
+
detection_ious=ious,
|
|
629
609
|
show_progress=show_progress,
|
|
630
|
-
annotation_type=Polygon,
|
|
631
610
|
)
|
|
632
611
|
|
|
633
612
|
def add_bitmasks(
|
|
@@ -645,10 +624,22 @@ class DataLoader:
|
|
|
645
624
|
show_progress : bool, default=False
|
|
646
625
|
Toggle for tqdm progress bar.
|
|
647
626
|
"""
|
|
627
|
+
ious = [
|
|
628
|
+
compute_bitmask_iou(
|
|
629
|
+
np.array(
|
|
630
|
+
[
|
|
631
|
+
[gt.mask, pd.mask] # type: ignore - using the AttributeError as a validator
|
|
632
|
+
for pd in detection.predictions
|
|
633
|
+
for gt in detection.groundtruths
|
|
634
|
+
]
|
|
635
|
+
)
|
|
636
|
+
).reshape(len(detection.predictions), len(detection.groundtruths))
|
|
637
|
+
for detection in detections
|
|
638
|
+
]
|
|
648
639
|
return self._add_data(
|
|
649
640
|
detections=detections,
|
|
641
|
+
detection_ious=ious,
|
|
650
642
|
show_progress=show_progress,
|
|
651
|
-
annotation_type=Bitmask,
|
|
652
643
|
)
|
|
653
644
|
|
|
654
645
|
def finalize(self) -> Evaluator:
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
1
2
|
from enum import Enum
|
|
2
3
|
|
|
3
4
|
from valor_lite.schemas import BaseMetric
|
|
@@ -21,6 +22,7 @@ class MetricType(str, Enum):
|
|
|
21
22
|
ConfusionMatrix = "ConfusionMatrix"
|
|
22
23
|
|
|
23
24
|
|
|
25
|
+
@dataclass
|
|
24
26
|
class Metric(BaseMetric):
|
|
25
27
|
"""
|
|
26
28
|
Object Detection Metric.
|
|
@@ -35,6 +37,24 @@ class Metric(BaseMetric):
|
|
|
35
37
|
A dictionary containing metric parameters.
|
|
36
38
|
"""
|
|
37
39
|
|
|
40
|
+
def __post_init__(self):
|
|
41
|
+
if not isinstance(self.type, str):
|
|
42
|
+
raise TypeError(
|
|
43
|
+
f"Metric type should be of type 'str': {self.type}"
|
|
44
|
+
)
|
|
45
|
+
elif not isinstance(self.value, (int, float, dict)):
|
|
46
|
+
raise TypeError(
|
|
47
|
+
f"Metric value must be of type 'int', 'float' or 'dict': {self.value}"
|
|
48
|
+
)
|
|
49
|
+
elif not isinstance(self.parameters, dict):
|
|
50
|
+
raise TypeError(
|
|
51
|
+
f"Metric parameters must be of type 'dict[str, Any]': {self.parameters}"
|
|
52
|
+
)
|
|
53
|
+
elif not all([isinstance(k, str) for k in self.parameters.keys()]):
|
|
54
|
+
raise TypeError(
|
|
55
|
+
f"Metric parameter dictionary should only have keys with type 'str': {self.parameters}"
|
|
56
|
+
)
|
|
57
|
+
|
|
38
58
|
@classmethod
|
|
39
59
|
def precision(
|
|
40
60
|
cls,
|
valor_lite/schemas.py
CHANGED
|
@@ -7,11 +7,5 @@ class BaseMetric:
|
|
|
7
7
|
value: int | float | dict
|
|
8
8
|
parameters: dict
|
|
9
9
|
|
|
10
|
-
def __post_init__(self):
|
|
11
|
-
if not isinstance(self.value, (int, float, dict)):
|
|
12
|
-
raise TypeError(
|
|
13
|
-
"Metric value must be of type `int`, `float` or `dict`."
|
|
14
|
-
)
|
|
15
|
-
|
|
16
10
|
def to_dict(self) -> dict:
|
|
17
11
|
return asdict(self)
|
|
@@ -46,8 +46,8 @@ def compute_intermediate_confusion_matrices(
|
|
|
46
46
|
predictions.reshape(1, n_pd_labels, -1),
|
|
47
47
|
).sum(axis=2)
|
|
48
48
|
|
|
49
|
-
intersected_groundtruth_counts = intersection_counts.sum(axis=
|
|
50
|
-
intersected_prediction_counts = intersection_counts.sum(axis=
|
|
49
|
+
intersected_groundtruth_counts = intersection_counts.sum(axis=1)
|
|
50
|
+
intersected_prediction_counts = intersection_counts.sum(axis=0)
|
|
51
51
|
|
|
52
52
|
confusion_matrix = np.zeros((n_labels + 1, n_labels + 1), dtype=np.int32)
|
|
53
53
|
confusion_matrix[0, 0] = background_counts
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
1
2
|
from enum import Enum
|
|
2
3
|
|
|
3
4
|
from valor_lite.schemas import BaseMetric
|
|
@@ -13,6 +14,7 @@ class MetricType(Enum):
|
|
|
13
14
|
ConfusionMatrix = "ConfusionMatrix"
|
|
14
15
|
|
|
15
16
|
|
|
17
|
+
@dataclass
|
|
16
18
|
class Metric(BaseMetric):
|
|
17
19
|
"""
|
|
18
20
|
Semantic Segmentation Metric.
|
|
@@ -27,6 +29,24 @@ class Metric(BaseMetric):
|
|
|
27
29
|
A dictionary containing metric parameters.
|
|
28
30
|
"""
|
|
29
31
|
|
|
32
|
+
def __post_init__(self):
|
|
33
|
+
if not isinstance(self.type, str):
|
|
34
|
+
raise TypeError(
|
|
35
|
+
f"Metric type should be of type 'str': {self.type}"
|
|
36
|
+
)
|
|
37
|
+
elif not isinstance(self.value, (int, float, dict)):
|
|
38
|
+
raise TypeError(
|
|
39
|
+
f"Metric value must be of type 'int', 'float' or 'dict': {self.value}"
|
|
40
|
+
)
|
|
41
|
+
elif not isinstance(self.parameters, dict):
|
|
42
|
+
raise TypeError(
|
|
43
|
+
f"Metric parameters must be of type 'dict[str, Any]': {self.parameters}"
|
|
44
|
+
)
|
|
45
|
+
elif not all([isinstance(k, str) for k in self.parameters.keys()]):
|
|
46
|
+
raise TypeError(
|
|
47
|
+
f"Metric parameter dictionary should only have keys with type 'str': {self.parameters}"
|
|
48
|
+
)
|
|
49
|
+
|
|
30
50
|
@classmethod
|
|
31
51
|
def precision(
|
|
32
52
|
cls,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from .annotation import Context, QueryResponse
|
|
2
|
+
from .llm.integrations import ClientWrapper, MistralWrapper, OpenAIWrapper
|
|
3
|
+
from .manager import Evaluator
|
|
4
|
+
from .metric import Metric, MetricType
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"QueryResponse",
|
|
8
|
+
"Context",
|
|
9
|
+
"Evaluator",
|
|
10
|
+
"Metric",
|
|
11
|
+
"MetricType",
|
|
12
|
+
"ClientWrapper",
|
|
13
|
+
"OpenAIWrapper",
|
|
14
|
+
"MistralWrapper",
|
|
15
|
+
]
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from dataclasses import dataclass, field
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
@dataclass
|
|
5
|
+
class Context:
|
|
6
|
+
"""
|
|
7
|
+
Contextual ground truth and prediction.
|
|
8
|
+
|
|
9
|
+
Attributes
|
|
10
|
+
----------
|
|
11
|
+
groundtruth : list[str]
|
|
12
|
+
The definitive context.
|
|
13
|
+
prediction : list[str]
|
|
14
|
+
Any retrieved context from a retrieval-augmented-generation (RAG) pipeline.
|
|
15
|
+
|
|
16
|
+
Examples
|
|
17
|
+
--------
|
|
18
|
+
... context = Context(
|
|
19
|
+
... groundtruth=[...],
|
|
20
|
+
... prediction=[...],
|
|
21
|
+
... )
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
groundtruth: list[str] = field(default_factory=list)
|
|
25
|
+
prediction: list[str] = field(default_factory=list)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass
|
|
29
|
+
class QueryResponse:
|
|
30
|
+
"""
|
|
31
|
+
Text generation data structure containing ground truths and predictions.
|
|
32
|
+
|
|
33
|
+
Attributes
|
|
34
|
+
----------
|
|
35
|
+
query : str
|
|
36
|
+
The user query.
|
|
37
|
+
response : str
|
|
38
|
+
The language model's response.
|
|
39
|
+
context : Context
|
|
40
|
+
Any context provided to the model.
|
|
41
|
+
|
|
42
|
+
Examples
|
|
43
|
+
--------
|
|
44
|
+
>>> query = QueryResponse(
|
|
45
|
+
... query='When was George Washington born?',
|
|
46
|
+
... response="February 22, 1732",
|
|
47
|
+
... context=Context(
|
|
48
|
+
... groundtruth=["02/22/1732"],
|
|
49
|
+
... prediction=["02/22/1732"],
|
|
50
|
+
... ),
|
|
51
|
+
... )
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
query: str
|
|
55
|
+
response: str
|
|
56
|
+
context: Context | None = field(default=None)
|