valor-lite 0.33.14__py3-none-any.whl → 0.33.16__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.

@@ -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,
@@ -408,17 +408,20 @@ def compute_precion_recall(
408
408
 
409
409
  # calculate component metrics
410
410
  recall = np.zeros_like(tp_count)
411
- precision = np.zeros_like(tp_count)
412
411
  np.divide(tp_count, gt_count, where=gt_count > 1e-9, out=recall)
412
+
413
+ precision = np.zeros_like(tp_count)
413
414
  np.divide(tp_count, pd_count, where=pd_count > 1e-9, out=precision)
415
+
414
416
  fn_count = gt_count - tp_count
415
417
 
416
418
  f1_score = np.zeros_like(precision)
417
419
  np.divide(
418
- np.multiply(precision, recall),
420
+ 2 * np.multiply(precision, recall),
419
421
  (precision + recall),
420
422
  where=(precision + recall) > 1e-9,
421
423
  out=f1_score,
424
+ dtype=np.float64,
422
425
  )
423
426
 
424
427
  counts[iou_idx][score_idx] = np.concatenate(
@@ -307,7 +307,7 @@ class Evaluator:
307
307
  filter_: Filter | None = None,
308
308
  ) -> dict[MetricType, list[Metric]]:
309
309
  """
310
- Computes all avaiable metrics.
310
+ Computes all available metrics.
311
311
 
312
312
  Parameters
313
313
  ----------
@@ -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)
@@ -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)