snorkel.labeling.LabelingFunction

class snorkel.labeling.LabelingFunction(name, f, resources=None, pre=None, fault_tolerant=False)[source]

Bases: object

Base class for labeling functions.

A labeling function (LF) is a function that takes a data point as input and produces an integer label, corresponding to a class. A labeling function can also abstain from voting by outputting -1. For examples, see the Snorkel tutorials.

This class wraps a Python function outputting a label. Extra functionality, such as running preprocessors and storing resources, is provided. Simple LFs can be defined via a decorator. See labeling_function.

Parameters
  • name (str) – Name of the LF

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

  • 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

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

Raises

ValueError – Calling incorrectly defined preprocessors

name[source]

See above

fault_tolerant[source]

See above

__init__(name, f, resources=None, pre=None, fault_tolerant=False)[source]

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

Return type

None

Methods

__init__(name, f[, resources, pre, …])

Initialize self.

__call__(x)[source]

Label data point.

Runs all preprocessors, then passes to LF. If an exception is encountered and the LF is in fault tolerant mode, the LF abstains from voting.

Parameters

x (Any) – Data point to label

Returns

Label for data point

Return type

int