snorkelflow.studio.resources_fn_labeling_function
- class snorkelflow.studio.resources_fn_labeling_function(name=None, resources=None, resources_fn=None)
Bases:
labeling_functionSubclass of
@labeling_functiondecorator that allows passing resources as functions.Parameters
Parameters
Name Type Default Info name Optional[str]NoneName of the LF. resources Optional[Mapping[str, Any]]NoneLabeling resources passed in to fviakwargsresources_fn Optional[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__(name=None, resources=None, resources_fn=None)
\_\_init\_\_
__init__
Methods
__init__([name, resources, resources_fn])