Skip to content

Commit adf94c6

Browse files
committed
Remove fault tolerant mode from LF/SF
1 parent 9a86617 commit adf94c6

File tree

6 files changed

+10
-85
lines changed

6 files changed

+10
-85
lines changed

snorkel/labeling/lf/core.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ class LabelingFunction:
2727
Labeling resources passed in to ``f`` via ``kwargs``
2828
pre
2929
Preprocessors to run on data points before LF execution
30-
fault_tolerant
31-
Output ``-1`` if LF execution fails?
3230
3331
Raises
3432
------
@@ -39,8 +37,6 @@ class LabelingFunction:
3937
----------
4038
name
4139
See above
42-
fault_tolerant
43-
See above
4440
"""
4541

4642
def __init__(
@@ -49,10 +45,8 @@ def __init__(
4945
f: Callable[..., int],
5046
resources: Optional[Mapping[str, Any]] = None,
5147
pre: Optional[List[BasePreprocessor]] = None,
52-
fault_tolerant: bool = False,
5348
) -> None:
5449
self.name = name
55-
self.fault_tolerant = fault_tolerant
5650
self._f = f
5751
self._resources = resources or {}
5852
self._pre = pre or []
@@ -67,9 +61,7 @@ def _preprocess_data_point(self, x: DataPoint) -> DataPoint:
6761
def __call__(self, x: DataPoint) -> int:
6862
"""Label data point.
6963
70-
Runs all preprocessors, then passes to LF. If an exception
71-
is encountered and the LF is in fault tolerant mode,
72-
the LF abstains from voting.
64+
Runs all preprocessors, then passes preprocessed data point to LF.
7365
7466
Parameters
7567
----------
@@ -82,11 +74,6 @@ def __call__(self, x: DataPoint) -> int:
8274
Label for data point
8375
"""
8476
x = self._preprocess_data_point(x)
85-
if self.fault_tolerant:
86-
try:
87-
return self._f(x, **self._resources)
88-
except Exception:
89-
return -1
9077
return self._f(x, **self._resources)
9178

9279
def __repr__(self) -> str:
@@ -105,8 +92,6 @@ class labeling_function:
10592
Labeling resources passed in to ``f`` via ``kwargs``
10693
preprocessors
10794
Preprocessors to run on data points before LF execution
108-
fault_tolerant
109-
Output ``-1`` if LF execution fails?
11095
11196
Examples
11297
--------
@@ -132,14 +117,12 @@ def __init__(
132117
name: Optional[str] = None,
133118
resources: Optional[Mapping[str, Any]] = None,
134119
pre: Optional[List[BasePreprocessor]] = None,
135-
fault_tolerant: bool = False,
136120
) -> None:
137121
if callable(name):
138122
raise ValueError("Looks like this decorator is missing parentheses!")
139123
self.name = name
140124
self.resources = resources
141125
self.pre = pre
142-
self.fault_tolerant = fault_tolerant
143126

144127
def __call__(self, f: Callable[..., int]) -> LabelingFunction:
145128
"""Wrap a function to create a ``LabelingFunction``.
@@ -155,10 +138,4 @@ def __call__(self, f: Callable[..., int]) -> LabelingFunction:
155138
New ``LabelingFunction`` executing logic in wrapped function
156139
"""
157140
name = self.name or f.__name__
158-
return LabelingFunction(
159-
name=name,
160-
f=f,
161-
resources=self.resources,
162-
pre=self.pre,
163-
fault_tolerant=self.fault_tolerant,
164-
)
141+
return LabelingFunction(name=name, f=f, resources=self.resources, pre=self.pre)

snorkel/labeling/lf/nlp.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ def __init__(
7373
f: Callable[..., int],
7474
resources: Optional[Mapping[str, Any]] = None,
7575
pre: Optional[List[BasePreprocessor]] = None,
76-
fault_tolerant: bool = False,
7776
text_field: str = "text",
7877
doc_field: str = "doc",
7978
language: str = EN_CORE_WEB_SM,
@@ -83,13 +82,7 @@ def __init__(
8382
self._create_or_check_preprocessor(
8483
text_field, doc_field, language, disable, pre or [], memoize
8584
)
86-
super().__init__(
87-
name,
88-
f,
89-
resources=resources,
90-
pre=[self._nlp_config.nlp],
91-
fault_tolerant=fault_tolerant,
92-
)
85+
super().__init__(name, f, resources=resources, pre=[self._nlp_config.nlp])
9386

9487

9588
class NLPLabelingFunction(BaseNLPLabelingFunction):
@@ -123,8 +116,6 @@ class NLPLabelingFunction(BaseNLPLabelingFunction):
123116
Labeling resources passed in to ``f`` via ``kwargs``
124117
pre
125118
Preprocessors to run before SpacyPreprocessor is executed
126-
fault_tolerant
127-
Output -1 if LF execution fails?
128119
text_field
129120
Name of data point text field to input
130121
doc_field
@@ -161,8 +152,6 @@ class NLPLabelingFunction(BaseNLPLabelingFunction):
161152
----------
162153
name
163154
See above
164-
fault_tolerant
165-
See above
166155
"""
167156

168157
@classmethod
@@ -182,14 +171,13 @@ def __init__(
182171
name: Optional[str] = None,
183172
resources: Optional[Mapping[str, Any]] = None,
184173
pre: Optional[List[BasePreprocessor]] = None,
185-
fault_tolerant: bool = False,
186174
text_field: str = "text",
187175
doc_field: str = "doc",
188176
language: str = EN_CORE_WEB_SM,
189177
disable: Optional[List[str]] = None,
190178
memoize: bool = True,
191179
) -> None:
192-
super().__init__(name, resources, pre, fault_tolerant)
180+
super().__init__(name, resources, pre)
193181
self.text_field = text_field
194182
self.doc_field = doc_field
195183
self.language = language
@@ -217,7 +205,6 @@ def __call__(self, f: Callable[..., int]) -> BaseNLPLabelingFunction:
217205
f=f,
218206
resources=self.resources,
219207
pre=self.pre,
220-
fault_tolerant=self.fault_tolerant,
221208
text_field=self.text_field,
222209
doc_field=self.doc_field,
223210
language=self.language,
@@ -237,8 +224,6 @@ class nlp_labeling_function(base_nlp_labeling_function):
237224
Labeling resources passed in to ``f`` via ``kwargs``
238225
pre
239226
Preprocessors to run before SpacyPreprocessor is executed
240-
fault_tolerant
241-
Output -1 if LF execution fails?
242227
text_field
243228
Name of data point text field to input
244229
doc_field

snorkel/labeling/lf/nlp_spark.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ class SparkNLPLabelingFunction(BaseNLPLabelingFunction):
2424
Labeling resources passed in to ``f`` via ``kwargs``
2525
pre
2626
Preprocessors to run before SpacyPreprocessor is executed
27-
fault_tolerant
28-
Output -1 if LF execution fails?
2927
text_field
3028
Name of data point text field to input
3129
doc_field
@@ -48,8 +46,6 @@ class SparkNLPLabelingFunction(BaseNLPLabelingFunction):
4846
----------
4947
name
5048
See above
51-
fault_tolerant
52-
See above
5349
"""
5450

5551
@classmethod
@@ -72,8 +68,6 @@ class spark_nlp_labeling_function(base_nlp_labeling_function):
7268
Labeling resources passed in to ``f`` via ``kwargs``
7369
pre
7470
Preprocessors to run before SpacyPreprocessor is executed
75-
fault_tolerant
76-
Output -1 if LF execution fails?
7771
text_field
7872
Name of data point text field to input
7973
doc_field

snorkel/slicing/sf/core.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ class slicing_function:
2424
Slicing resources passed in to ``f`` via ``kwargs``
2525
preprocessors
2626
Preprocessors to run on data points before SF execution
27-
fault_tolerant
28-
Output ``-1`` if SF execution fails?
2927
3028
Examples
3129
--------
@@ -51,14 +49,12 @@ def __init__(
5149
name: Optional[str] = None,
5250
resources: Optional[Mapping[str, Any]] = None,
5351
pre: Optional[List[BasePreprocessor]] = None,
54-
fault_tolerant: bool = False,
5552
) -> None:
5653
if callable(name):
5754
raise ValueError("Looks like this decorator is missing parentheses!")
5855
self.name = name
5956
self.resources = resources
6057
self.pre = pre
61-
self.fault_tolerant = fault_tolerant
6258

6359
def __call__(self, f: Callable[..., int]) -> SlicingFunction:
6460
"""Wrap a function to create a ``SlicingFunction``.
@@ -74,10 +70,4 @@ def __call__(self, f: Callable[..., int]) -> SlicingFunction:
7470
New ``SlicingFunction`` executing logic in wrapped function
7571
"""
7672
name = self.name or f.__name__
77-
return SlicingFunction(
78-
name=name,
79-
f=f,
80-
resources=self.resources,
81-
pre=self.pre,
82-
fault_tolerant=self.fault_tolerant,
83-
)
73+
return SlicingFunction(name=name, f=f, resources=self.resources, pre=self.pre)

snorkel/slicing/sf/nlp.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ class NLPSlicingFunction(BaseNLPLabelingFunction):
3737
Labeling resources passed in to ``f`` via ``kwargs``
3838
pre
3939
Preprocessors to run before SpacyPreprocessor is executed
40-
fault_tolerant
41-
Output -1 if LF execution fails?
4240
text_field
4341
Name of data point text field to input
4442
doc_field
@@ -75,8 +73,6 @@ class NLPSlicingFunction(BaseNLPLabelingFunction):
7573
----------
7674
name
7775
See above
78-
fault_tolerant
79-
See above
8076
"""
8177

8278
@classmethod

test/labeling/lf/test_core.py

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,14 @@ def _run_lf(self, lf: LabelingFunction) -> None:
3434
self.assertEqual(lf(x_43), 0)
3535
self.assertEqual(lf(x_19), -1)
3636

37-
def _run_lf_raise(self, lf: LabelingFunction) -> None:
38-
x_none = SimpleNamespace(num=None)
39-
with self.assertRaises(TypeError):
40-
lf(x_none)
41-
42-
def _run_lf_no_raise(self, lf: LabelingFunction) -> None:
43-
x_none = SimpleNamespace(num=None)
44-
self.assertEqual(lf(x_none), -1)
45-
4637
def test_labeling_function(self) -> None:
4738
lf = LabelingFunction(name="my_lf", f=f)
4839
self._run_lf(lf)
49-
self._run_lf_raise(lf)
50-
51-
def test_labeling_function_fault_tolerant(self) -> None:
52-
lf = LabelingFunction(name="my_lf", f=f, fault_tolerant=True)
53-
self._run_lf(lf)
54-
self._run_lf_no_raise(lf)
5540

5641
def test_labeling_function_resources(self) -> None:
5742
db = [3, 6, 43]
5843
lf = LabelingFunction(name="my_lf", f=g, resources=dict(db=db))
5944
self._run_lf(lf)
60-
self._run_lf_no_raise(lf)
6145

6246
def test_labeling_function_preprocessor(self) -> None:
6347
lf = LabelingFunction(name="my_lf", f=f, pre=[square, square])
@@ -79,7 +63,6 @@ def test_labeling_function_serialize(self) -> None:
7963
lf = LabelingFunction(name="my_lf", f=g, resources=dict(db=db))
8064
lf_load = pickle.loads(pickle.dumps(lf))
8165
self._run_lf(lf_load)
82-
self._run_lf_no_raise(lf_load)
8366

8467
def test_labeling_function_decorator(self) -> None:
8568
@labeling_function()
@@ -89,17 +72,17 @@ def lf(x: DataPoint) -> int:
8972
self.assertIsInstance(lf, LabelingFunction)
9073
self.assertEqual(lf.name, "lf")
9174
self._run_lf(lf)
92-
self._run_lf_raise(lf)
9375

9476
def test_labeling_function_decorator_args(self) -> None:
95-
@labeling_function(name="my_lf", fault_tolerant=True)
96-
def lf(x: DataPoint) -> int:
97-
return 0 if x.num > 42 else -1
77+
db = [3, 6, 43]
78+
79+
@labeling_function(name="my_lf", resources=dict(db=db))
80+
def lf(x: DataPoint, db: List[int]) -> int:
81+
return 0 if x.num in db else -1
9882

9983
self.assertIsInstance(lf, LabelingFunction)
10084
self.assertEqual(lf.name, "my_lf")
10185
self._run_lf(lf)
102-
self._run_lf_no_raise(lf)
10386

10487
def test_labeling_function_decorator_no_parens(self) -> None:
10588
with self.assertRaisesRegex(ValueError, "missing parentheses"):

0 commit comments

Comments
 (0)