Skip to main content
Version: 0.95

Code LFs

In Snorkel Flow, labeling functions (LFs) help automate the process of labeling data. Snorkel Flow provides modular building blocks, like AND and OR logic blocks, to create many types of LFs. However, in cases where your labeling logic isn't fully captured by the available LF builders, you can write custom Python functions.

These custom LFs, referred to as code LFs, allow you to directly define labeling logic and integrate it into your project.

Here is an example code LF. Use @labeling_function() to define your LF, and sf.add_code_lf() to add the LF to the model node for your application.

import snorkelflow.client as sf
from snorkel.labeling.lf import labeling_function

@labeling_function()
def my_code_lf(x):
if "drug" in x.body:
return "SPAM"
return "UNKNOWN"

# Save to a model node
sf.add_code_lf(node, my_code_lf)