snorkel.labeling.labeling_function

class snorkel.labeling.labeling_function(name=None, resources=None, pre=None)[source]

Bases: object

Decorator to define a LabelingFunction object from a function.

Parameters
  • name (Optional[str]) – Name of the LF

  • resources (Optional[Mapping[str, Any]]) – Labeling resources passed in to f via kwargs

  • pre (Optional[List[BaseMapper]]) – Preprocessors to run on data points before LF execution

Examples

>>> @labeling_function()
... def f(x):
...     return 0 if x.a > 42 else -1
>>> f
LabelingFunction f, Preprocessors: []
>>> from types import SimpleNamespace
>>> x = SimpleNamespace(a=90, b=12)
>>> f(x)
0
>>> @labeling_function(name="my_lf")
... def g(x):
...     return 0 if x.a > 42 else -1
>>> g
LabelingFunction my_lf, Preprocessors: []
__init__(name=None, resources=None, pre=None)[source]

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

Return type

None

Methods

__init__([name, resources, pre])

Initialize self.

__call__(f)[source]

Wrap a function to create a LabelingFunction.

Parameters

f (Callable[…, int]) – Function that implements the core LF logic

Returns

New LabelingFunction executing logic in wrapped function

Return type

LabelingFunction