-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dependency upgrades; disabling snorkel-related tests till the functio…
…nality is renamed and reworked, since snorkel is inactive
- Loading branch information
Showing
15 changed files
with
342 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,59 @@ | ||
import uuid | ||
|
||
|
||
def labeling_function(targets, label_encoder=None, **kwargs): | ||
""" | ||
???+ note "Hover's flavor of the Snorkel labeling_function decorator." | ||
However, due to the dynamic label encoding nature of hover, | ||
the decorated function should return the original string label, not its encoding integer. | ||
- assigns a UUID for easy identification | ||
- keeps track of LF targets | ||
| Param | Type | Description | | ||
| :-------------- | :----- | :----------------------------------- | | ||
| `targets` | `list` of `str` | labels that the labeling function is intended to create | | ||
| `label_encoder` | `dict` | {decoded_label -> encoded_label} mapping, if you also want an original snorkel-style labeling function linked as a `.snorkel` attribute | | ||
| `**kwargs` | | forwarded to `snorkel`'s `labeling_function()` | | ||
""" | ||
# lazy import so that the package does not require snorkel | ||
# Feb 3, 2022: snorkel's dependency handling is too strict | ||
# for other dependencies like NumPy, SciPy, SpaCy, etc. | ||
# Let's cite Snorkel and lazy import or copy functions. | ||
# DO NOT explicitly depend on Snorkel without confirming | ||
# that all builds/tests pass by Anaconda standards, else | ||
# we risk having to drop conda support. | ||
from snorkel.labeling import ( | ||
labeling_function as snorkel_lf, | ||
LabelingFunction as SnorkelLF, | ||
) | ||
|
||
def wrapper(func): | ||
# set up kwargs for Snorkel's LF | ||
# a default name that can be overridden | ||
snorkel_kwargs = {"name": func.__name__} | ||
snorkel_kwargs.update(kwargs) | ||
|
||
# return value of hover's decorator | ||
lf = SnorkelLF(f=func, **snorkel_kwargs) | ||
|
||
# additional attributes | ||
lf.uuid = uuid.uuid1() | ||
lf.targets = targets[:] | ||
|
||
# link a snorkel-style labeling function if applicable | ||
if label_encoder: | ||
lf.label_encoder = label_encoder | ||
|
||
def snorkel_style_func(x): | ||
return lf.label_encoder[func(x)] | ||
|
||
lf.snorkel = snorkel_lf(**kwargs)(snorkel_style_func) | ||
else: | ||
lf.label_encoder = None | ||
lf.snorkel = None | ||
|
||
return lf | ||
|
||
return wrapper | ||
# import uuid | ||
# | ||
# | ||
# def labeling_function(targets, label_encoder=None, **kwargs): | ||
# """ | ||
# ???+ note "Hover's flavor of the Snorkel labeling_function decorator." | ||
# However, due to the dynamic label encoding nature of hover, | ||
# the decorated function should return the original string label, not its encoding integer. | ||
# | ||
# - assigns a UUID for easy identification | ||
# - keeps track of LF targets | ||
# | ||
# | Param | Type | Description | | ||
# | :-------------- | :----- | :----------------------------------- | | ||
# | `targets` | `list` of `str` | labels that the labeling function is intended to create | | ||
# | `label_encoder` | `dict` | {decoded_label -> encoded_label} mapping, if you also want an original snorkel-style labeling function linked as a `.snorkel` attribute | | ||
# | `**kwargs` | | forwarded to `snorkel`'s `labeling_function()` | | ||
# """ | ||
# # lazy import so that the package does not require snorkel | ||
# # Feb 3, 2022: snorkel's dependency handling is too strict | ||
# # for other dependencies like NumPy, SciPy, SpaCy, etc. | ||
# # Let's cite Snorkel and lazy import or copy functions. | ||
# # DO NOT explicitly depend on Snorkel without confirming | ||
# # that all builds/tests pass by Anaconda standards, else | ||
# # we risk having to drop conda support. | ||
# from snorkel.labeling import ( | ||
# labeling_function as snorkel_lf, | ||
# LabelingFunction as SnorkelLF, | ||
# ) | ||
# | ||
# def wrapper(func): | ||
# # set up kwargs for Snorkel's LF | ||
# # a default name that can be overridden | ||
# snorkel_kwargs = {"name": func.__name__} | ||
# snorkel_kwargs.update(kwargs) | ||
# | ||
# # return value of hover's decorator | ||
# lf = SnorkelLF(f=func, **snorkel_kwargs) | ||
# | ||
# # additional attributes | ||
# lf.uuid = uuid.uuid1() | ||
# lf.targets = targets[:] | ||
# | ||
# # link a snorkel-style labeling function if applicable | ||
# if label_encoder: | ||
# lf.label_encoder = label_encoder | ||
# | ||
# def snorkel_style_func(x): | ||
# return lf.label_encoder[func(x)] | ||
# | ||
# lf.snorkel = snorkel_lf(**kwargs)(snorkel_style_func) | ||
# else: | ||
# lf.label_encoder = None | ||
# lf.snorkel = None | ||
# | ||
# return lf | ||
# | ||
# return wrapper | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.