-
Notifications
You must be signed in to change notification settings - Fork 246
/
default_suites.py
161 lines (140 loc) · 6.35 KB
/
default_suites.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# ----------------------------------------------------------------------------
# Copyright (C) 2021-2023 Deepchecks (https://www.deepchecks.com)
#
# This file is part of Deepchecks.
# Deepchecks is distributed under the terms of the GNU Affero General
# Public License (version 3 or later).
# You should have received a copy of the GNU Affero General Public License
# along with Deepchecks. If not, see <http://www.gnu.org/licenses/>.
# ----------------------------------------------------------------------------
#
# pylint: disable=unused-argument
"""Functions for loading the default (built-in) nlp suites for various validation stages.
Each function returns a new suite that is initialized with a list of checks and default conditions.
It is possible to customize these suites by editing the checks and conditions inside it after the suites' creation.
"""
from deepchecks.nlp import Suite
from deepchecks.nlp.checks import (ConflictingLabels, LabelDrift, MetadataSegmentsPerformance, PredictionDrift,
PropertyDrift, PropertyLabelCorrelation, PropertySegmentsPerformance,
SpecialCharacters, TextDuplicates, TextPropertyOutliers, TrainTestPerformance,
TrainTestSamplesMix, UnderAnnotatedMetaDataSegments, UnderAnnotatedPropertySegments,
UnknownTokens)
__all__ = ['data_integrity', 'train_test_validation',
'model_evaluation', 'full_suite']
def data_integrity(n_samples: int = None,
random_state: int = 42,
**kwargs) -> Suite:
"""Suite for detecting integrity issues within a single dataset.
Parameters
----------
n_samples : int , default: None
number of samples to use for checks that sample data. If none, using the default n_samples per check.
random_state : int, default: 42
random seed for all checkss.
**kwargs : dict
additional arguments to pass to the checks.
Returns
-------
Suite
A suite for validating correctness of train-test split, including distribution, \
leakage and integrity checks.
Examples
--------
>>> from deepchecks.nlp.suites import data_integrity
>>> suite = data_integrity(n_samples=1_000_000)
>>> result = suite.run()
>>> result.show()
"""
args = locals()
args.pop('kwargs')
non_none_args = {k: v for k, v in args.items() if v is not None}
kwargs = {**non_none_args, **kwargs}
return Suite(
'Data Integrity Suite',
PropertyLabelCorrelation(**kwargs).add_condition_property_pps_less_than(),
TextPropertyOutliers(**kwargs),
TextDuplicates(**kwargs).add_condition_ratio_less_or_equal(),
ConflictingLabels(**kwargs).add_condition_ratio_of_conflicting_labels_less_or_equal(),
SpecialCharacters(**kwargs).add_condition_ratio_of_samples_with_special_characters_less_or_equal(),
UnknownTokens(**kwargs).add_condition_ratio_of_unknown_words_less_or_equal(),
UnderAnnotatedPropertySegments(**kwargs).add_condition_segments_relative_performance_greater_than(),
UnderAnnotatedMetaDataSegments(**kwargs).add_condition_segments_relative_performance_greater_than(),
)
def train_test_validation(n_samples: int = None,
random_state: int = 42,
**kwargs) -> Suite:
"""Suite for validating correctness of train-test split, including distribution, \
leakage and integrity checks.
Parameters
----------
n_samples : int , default: None
number of samples to use for checks that sample data. If none, using the default n_samples per check.
random_state : int, default: 42
random seed for all checkss.
**kwargs : dict
additional arguments to pass to the checks.
Returns
-------
Suite
A suite for validating correctness of train-test split, including distribution, \
leakage and integrity checks.
Examples
--------
>>> from deepchecks.nlp.suites import train_test_validation
>>> suite = train_test_validation(n_samples=1_000_000)
>>> result = suite.run()
>>> result.show()
"""
args = locals()
args.pop('kwargs')
non_none_args = {k: v for k, v in args.items() if v is not None}
kwargs = {**non_none_args, **kwargs}
return Suite(
'Train Test Validation Suite',
PropertyDrift(**kwargs).add_condition_drift_score_less_than(),
LabelDrift(**kwargs).add_condition_drift_score_less_than(),
TrainTestSamplesMix(**kwargs).add_condition_duplicates_ratio_less_or_equal()
)
def model_evaluation(n_samples: int = None,
random_state: int = 42,
**kwargs) -> Suite:
"""Suite for evaluating the model's performance over different metrics, segments, error analysis, examining \
overfitting, comparing to baseline, and more.
Parameters
----------
n_samples : int , default: 1_000_000
number of samples to use for checks that sample data. If none, use the default n_samples per check.
random_state : int, default: 42
random seed for all checks.
**kwargs : dict
additional arguments to pass to the checks.
Returns
-------
Suite
A suite for evaluating the model's performance.
Examples
--------
>>> from deepchecks.nlp.suites import model_evaluation
>>> suite = model_evaluation(n_samples=1_000_000)
>>> result = suite.run()
>>> result.show()
"""
args = locals()
args.pop('kwargs')
non_none_args = {k: v for k, v in args.items() if v is not None}
kwargs = {**non_none_args, **kwargs}
return Suite(
'Model Evaluation Suite',
TrainTestPerformance(**kwargs).add_condition_train_test_relative_degradation_less_than(),
PredictionDrift(**kwargs).add_condition_drift_score_less_than(),
PropertySegmentsPerformance(**kwargs).add_condition_segments_relative_performance_greater_than(),
MetadataSegmentsPerformance(**kwargs).add_condition_segments_relative_performance_greater_than(),
)
def full_suite(**kwargs) -> Suite:
"""Create a suite that includes many of the implemented checks, for a quick overview of your model and data."""
return Suite(
'Full Suite',
data_integrity(**kwargs),
model_evaluation(**kwargs),
train_test_validation(**kwargs),
)