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
Parameters
Name Type Default Info name Optional[str]
None
Name of the LF. resources Optional[Mapping[str, Any]]
None
Labeling resources passed in to f
viakwargs
resources_fn Optional[Callable[[], Dict[str, Any]]]
None
A 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__(name=None, resources=None, resources_fn=None)
\_\_init\_\_
__init__
Methods
__init__
([name, resources, resources_fn])