How to use the snorkel.labeling.lf.labeling_function function in snorkel

To help you get started, we’ve selected a few snorkel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github snorkel-team / snorkel / test / labeling / apply / lf_applier_spark_test_script.py View on Github external
@labeling_function(resources=dict(db=[3, 6, 9]))
def g(x: DataPoint, db: List[int]) -> int:
    return 1 if x.a in db else 0
github snorkel-team / snorkel / test / labeling / apply / lf_applier_spark_test_script.py View on Github external
@labeling_function()
def f(x: DataPoint) -> int:
    return 1 if x.a > 42 else 0
github snorkel-team / snorkel-tutorials / crossmodal / openi_demo.py View on Github external
@labeling_function()
def LF_consistency_in_report(x):
    """
    The words 'clear', 'no', 'normal', 'free', 'midline' in
    findings section of the report
    """
    findings = x.text[x.text.find("FINDINGS:") :]
    findings = findings[: findings.find("IMPRESSION:")]
    sents = findings.split(".")

    normalcy_words = ["clear", "no", "normal", "unremarkable", "free", "midline"]
    num_sents_without_normal = ABSTAIN
    for sent in sents:
        sent = sent.lower()
        if not any(word in sent for word in normalcy_words):
            num_sents_without_normal += 1
        elif "not" in sent:
github snorkel-team / snorkel-tutorials / recsys / recsys_tutorial.py View on Github external
@labeling_function(
    resources=dict(low_rating_strs=low_rating_strs, high_rating_strs=high_rating_strs)
)
def stars_in_review(x, low_rating_strs, high_rating_strs):
    if not isinstance(x.review_text, str):
        return ABSTAIN
    for low_rating_str in low_rating_strs:
        if low_rating_str in x.review_text.lower():
            return NEGATIVE
    for high_rating_str in high_rating_strs:
        if high_rating_str in x.review_text.lower():
            return POSITIVE
    return ABSTAIN
github snorkel-team / snorkel-tutorials / crossmodal / openi_demo.py View on Github external
@labeling_function()
def LF_report_is_short_demo(x):
    """
    Checks if report is short.
    """
    return NORMAL if len(x.text) < 280 else ABSTAIN
lfs.append(LF_report_is_short_demo)
github snorkel-team / snorkel-tutorials / example / example_tutorial.py View on Github external
@labeling_function()
def lf_1(x):
    return 1 if x.n_failures > 10 else 0
github snorkel-team / snorkel / snorkel / slicing / sf.py View on Github external
from snorkel.labeling.lf import LabelingFunction, labeling_function
from snorkel.labeling.lf.nlp import nlp_labeling_function


class SlicingFunction(LabelingFunction):
    """Base class for slicing functions.

    See ``snorkel.labeling.lf.LabelingFunction`` for details.
    """

    pass


class slicing_function(labeling_function):
    """Decorator to define a SlicingFunction object from a function.

    See ``snorkel.labeling.lf.labeling_function`` for details.
    """

    pass


class nlp_slicing_function(nlp_labeling_function):
    """Decorator to define a NLPSlicingFunction object from a function.

    See ``snorkel.labeling.lf.nlp_labeling_function`` for details.
    """

    pass
github snorkel-team / snorkel-tutorials / drybell / drybell_lfs_spark.py View on Github external
@labeling_function()
def body_contains_fortune(x):
    return POSITIVE if "fortune" in x.body else ABSTAIN
github snorkel-team / snorkel-tutorials / crossmodal / openi_demo.py View on Github external
@labeling_function()
def LF_noted_or_seen(x, noted_or_seen):
    if any(word in x.text.lower() for word in noted_or_seen):
        return ABNORMAL
    else:
        return ABSTAIN
lfs.append(LF_noted_or_seen)
github snorkel-team / snorkel / tutorials / drybell / nlp_lf.py View on Github external
@labeling_function(preprocessors=[combine_text_preprocessor, spacy_preprocessor])
def article_mentions_person(x: DataPoint) -> int:
    for ent in x.article.ents:
        if ent.label_ == "PERSON":
            return ABSTAIN
    return NEGATIVE