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:
name (
Optional
[str
], default:None
) – Name of the LFresources (
Optional
[Mapping
[str
,Any
]], default:None
) – Labeling resources passed in tof
viakwargs
resources_fn (
Optional
[Callable
[[],Dict
[str
,Any
]]], default: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)
Methods
__init__
([name, resources, resources_fn])