Skip to main content
Version: 25.4

snorkelflow.lfs.LF

warning

This is a beta function. Beta features may have known gaps or bugs, but are functional workflows and eligible for Snorkel Support. To access beta features, contact Snorkel Support to enable the feature flag for your Snorkel-hosted instance.

class snorkelflow.lfs.LF(name, label=None, templates=None, multipolar_template=None, graph=None, is_trusted=False)

Bases: object

Class to represent an immutable LF.

Examples

Create an LF.

>>> from snorkelflow.lfs import LF
>>> lf_a = LF(name="lf_a", label=0, templates=...)

Due to the immutability, a new LF should be created if you want to change its attributes.

>>> lf_config = lf_a.to_dict()
>>> lf_config["name"] = "lf_b"
>>> lf_b = LF(**lf_config)

__init__

__init__(name, label=None, templates=None, multipolar_template=None, graph=None, is_trusted=False)

Initialize an LF object.

Parameters

NameTypeDefaultInfo
namestrName of the LF.
labelOptional[Any]NoneLabel associated with the LF. This shouldn’t be provided for a multi-polar LF.
templatesOptional[List[Dict[str, Any]]]NoneTemplates for the LF. Each template is assigned with a 0-th based index that can be used in graph.
multipolar_templateOptional[Dict[str, Any]]NoneTemplate for the multi-polar LF.
graphUnion[str, int, List[Any], None]NoneProvide this argument to construct a compound LF, one that’s made of multiple templates. Optional if there is only one template. It is a list that starts with a logical operator, followed by template indexes or sub-lists. The logical operator can be "$AND", "$OR", or "$NOT". The list can be nested but the depth should be 3 or less. For example, a compound LF with ["$AND", 0, ["$NOT", 1]] votes if the 0th template returns True and the 1st template returns False, and its depth is 2.
is_trustedOptional[bool]FalseIf True, designate the LF as trusted.

Methods

__init__(name[, label, templates, ...])Initialize an LF object.
to_dict()Get a dictionary representation of the LF.

Attributes

graph
is_multipolar
is_trusted
name
label
templates
multipolar_template

to_dict

to_dict()

Get a dictionary representation of the LF.

Returns

Dictionary representation of the LF

Return type

Dict[str, Any]

graph: Union[str, int, List[Any], None] = None
property is_multipolar: bool
is_trusted: Optional[bool] = False
label: Optional[Any]
multipolar_template: Optional[Dict[str, Any]]
name: str
templates: Optional[List[Dict[str, Any]]]