snorkelflow.lfs.LF
- 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__(name, label=None, templates=None, multipolar_template=None, graph=None, is_trusted=False)
Initialize an LF object.
- Parameters:
name (
str
) – Name of the LFlabel (
Optional
[Any
], default:None
) – Label associated with the LF. This shouldn’t be provided for a multi-polar LF.templates (
Optional
[List
[Dict
[str
,Any
]]], default:None
) – Templates for the LF. Each template is assigned with a 0-th based index that can be used in graph.multipolar_template (
Optional
[Dict
[str
,Any
]], default:None
) – Template for the multi-polar LFgraph (
Union
[str
,int
,List
[Any
],None
], default:None
) – Provide 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_trusted (
Optional
[bool
], default:False
) – If 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
- 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
]]]