snorkel.labeling.LFApplier

class snorkel.labeling.LFApplier(lfs)[source]

Bases: snorkel.labeling.apply.core.BaseLFApplier

LF applier for a list of data points (e.g. SimpleNamespace) or a NumPy array.

Parameters

lfs (List[LabelingFunction]) – LFs that this applier executes on examples

Example

>>> from snorkel.labeling import labeling_function
>>> @labeling_function()
... def is_big_num(x):
...     return 1 if x.num > 42 else 0
>>> applier = LFApplier([is_big_num])
>>> from types import SimpleNamespace
>>> applier.apply([SimpleNamespace(num=10), SimpleNamespace(num=100)])
array([[0], [1]])
>>> @labeling_function()
... def is_big_num_np(x):
...     return 1 if x[0] > 42 else 0
>>> applier = LFApplier([is_big_num_np])
>>> applier.apply(np.array([[10], [100]]))
array([[0], [1]])
__init__(lfs)[source]

Initialize self. See help(type(self)) for accurate signature.

Return type

None

Methods

__init__(lfs)

Initialize self.

apply(data_points[, progress_bar, …])

Label list of data points or a NumPy array with LFs.

apply(data_points, progress_bar=True, fault_tolerant=False, return_meta=False)[source]

Label list of data points or a NumPy array with LFs.

Parameters
  • data_points (Union[Sequence[Any], ndarray]) – List of data points or NumPy array to be labeled by LFs

  • progress_bar (bool) – Display a progress bar?

  • fault_tolerant (bool) – Output -1 if LF execution fails?

  • return_meta (bool) – Return metadata from apply call?

Return type

Union[ndarray, Tuple[ndarray, ApplierMetadata]]

Returns

  • np.ndarray – Matrix of labels emitted by LFs

  • ApplierMetadata – Metadata, such as fault counts, for the apply call