Skip to main content
Version: 25.3

snorkelflow.studio.resources_fn_labeling_function

class snorkelflow.studio.resources_fn_labeling_function(name=None, resources=None, resources_fn=None)

Bases: labeling_function

Subclass of @labeling_function decorator that allows passing resources as functions.

Parameters

NameTypeDefaultInfo
nameOptional[str]NoneName of the LF.
resourcesOptional[Mapping[str, Any]]NoneLabeling resources passed in to f via kwargs
resources_fnOptional[Callable[[], Dict[str, Any]]]NoneA function that takes no arguments and returns a dict of resources, which is passed as kwargs to the underlying function. Expensive dependencies (like spacy nlp) and imports should be passed here to avoid serializing or repeatedly computing them.

Examples

>>> from snorkelflow.studio import resources_fn_labeling_function
>>> def get_nlp() -> Dict[str, Any]:
... import spacy
... return {"nlp": spacy.load("en_core_web_sm")}
>>> @resources_fn_labeling_function(name="my_lf", resources_fn=get_nlp)
... def many_entities(x, nlp) -> str:
... return "LABEL" if len(nlp(x).ents) > 5 else "UNKNOWN"

__init__

__init__(name=None, resources=None, resources_fn=None)

Methods

__init__([name, resources, resources_fn])