snorkel.map.LambdaMapper¶
-
class
snorkel.map.LambdaMapper(name, f, pre=None, memoize=False, memoize_key=None)[source]¶ Bases:
snorkel.map.core.BaseMapperDefine a mapper from a function.
Convenience class for mappers that execute a simple function with no set up. The function should map from an input data point to a new data point directly, unlike
Mapper.run. The original data point will not be updated, so in-place operations are safe.- Parameters
name (
str) – Name of mapperf (
Callable[[Any],Optional[Any]]) – Function executing the mapping operationpre (
Optional[List[BaseMapper]]) – Mappers to run before this mapper is executedmemoize (
bool) – Memoize mapper outputs?memoize_key (
Optional[Callable[[Any],Hashable]]) – Hashing function to handle the memoization (default to snorkel.map.core.get_hashable)
-
__init__(name, f, pre=None, memoize=False, memoize_key=None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
- Return type
None
Methods
__init__(name, f[, pre, memoize, memoize_key])Initialize self.
Reset the memoization cache.
-
__call__(x)[source]¶ Run mapping function on input data point.
Deep copies the data point first so as not to make accidental in-place changes. If
memoizeis set toTrue, an internal cache is checked for results. If no cached results are found, the computed results are added to the cache.- Parameters
x (
Any) – Data point to run mapping function on- Returns
Mapped data point of same format but possibly different fields
- Return type
DataPoint