Coverage for credoai/artifacts/model/comparison_model.py: 100%
11 statements
« prev ^ index » next coverage.py v7.1.0, created at 2023-02-13 21:56 +0000
« prev ^ index » next coverage.py v7.1.0, created at 2023-02-13 21:56 +0000
1"""Model artifact wrapping any comparison model"""
2from .base_model import Model
5class ComparisonModel(Model):
6 """Class wrapper around comparison model to be assessed
8 ComparisonModel serves as an adapter between arbitrary pair-wise comparison
9 models and the identity verification evaluations in Lens. Evaluations depend
10 on ComparisonModel instantiating `compare`
12 Parameters
13 ----------
14 name : str
15 Label of the model
16 model_like : model_like
17 A pair-wise comparison model or pipeline. It must have a
18 `compare` function that takes a two-dimensional python list of data sample pairs and
19 returns a list containing the similarity scores for each pair.
20 Example input and output: [[sd1,sd2], [sd1,td3], [td3,td8]] --> [98, 4, 91]
21 Type of data sample is decided by this `compare` function and refelcted in `ComparisonData` object
22 """
24 def __init__(self, name: str, model_like=None):
25 super().__init__(
26 "COMPARISON",
27 ["compare"],
28 ["compare"],
29 name,
30 model_like,
31 )
34class DummyComparisonModel:
35 """Class wrapper around comparison model predictions
37 This class can be used when a comparison model is not available but its outputs are.
38 The output include the array containing the predicted similarity scores.
39 Wrap the outputs with this class into a dummy comparison model and pass it as
40 the model to `ComparisonModel`.
42 Parameters
43 ----------
44 compare_output : array
45 Array containing the output of a comparison model's "compare" method
46 """
48 def __init__(self, name: str, compare_output=None, tags=None):
49 self.compare_output = compare_output
50 self.name = name
51 self.tags = tags
53 def compare(self, pairs=None):
54 return self.compare_output