snorkel.slicing.slicing_function

class snorkel.slicing.slicing_function(name=None, resources=None, pre=None)[source]

Bases: object

Decorator to define a SlicingFunction object from a function.

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

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

  • preprocessors – Preprocessors to run on data points before SF execution

Examples

>>> @slicing_function()
... def f(x):
...     return x.a > 42
>>> f
SlicingFunction f, Preprocessors: []
>>> from types import SimpleNamespace
>>> x = SimpleNamespace(a=90, b=12)
>>> f(x)
True
>>> @slicing_function(name="my_sf")
... def g(x):
...     return 0 if x.a > 42 else -1
>>> g
SlicingFunction my_sf, 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 SlicingFunction.

Parameters

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

Returns

New SlicingFunction executing logic in wrapped function

Return type

SlicingFunction