|
spouse relation classification |
|
|
|
# 9 labeling functions (weak_labels) |
|
lfs = [ |
|
lf_husband_wife, |
|
lf_husband_wife_left_window, |
|
lf_same_last_name, |
|
lf_married, |
|
lf_familial_relationship, |
|
lf_family_left_window, |
|
lf_other_relationship, |
|
lf_distant_supervision, |
|
lf_distant_supervision_last_names, |
|
] |
|
|
|
|
|
# Labels |
|
0 as Negative |
|
1 as Positive |
|
-1 as ABSTAIN |
|
|
|
|
|
|
|
#### LF 1 |
|
# Check for the `spouse` words appearing between the person mentions |
|
spouses = {"spouse", "wife", "husband", "ex-wife", "ex-husband"} |
|
def lf_husband_wife(x, spouses): |
|
return POSITIVE if len(spouses.intersection(set(x.between_tokens))) > 0 else ABSTAIN |
|
|
|
|
|
#### LF 2 |
|
# Check for the `spouse` words appearing to the left of the person mentions |
|
def lf_husband_wife_left_window(x, spouses): |
|
if len(set(spouses).intersection(set(x.person1_left_tokens))) > 0: |
|
return POSITIVE |
|
elif len(set(spouses).intersection(set(x.person2_left_tokens))) > 0: |
|
return POSITIVE |
|
else: |
|
return ABSTAIN |
|
|
|
#### LF 3 |
|
# Check for the person mentions having the same last name |
|
@labeling_function(pre=[get_person_last_names]) |
|
def lf_same_last_name(x): |
|
p1_ln, p2_ln = x.person_lastnames |
|
|
|
if p1_ln and p2_ln and p1_ln == p2_ln: |
|
return POSITIVE |
|
return ABSTAIN |
|
|
|
#### LF 4 |
|
# Check for the word `married` between person mentions |
|
@labeling_function() |
|
def lf_married(x): |
|
return POSITIVE if "married" in x.between_tokens else ABSTAIN |
|
|
|
#### LF 5 |
|
# Check for words that refer to `family` relationships between the person mentions |
|
family = { |
|
"father", |
|
"mother", |
|
"sister", |
|
"brother", |
|
"son", |
|
"daughter", |
|
"grandfather", |
|
"grandmother", |
|
"uncle", |
|
"aunt", |
|
"cousin", |
|
} |
|
family = family.union({f + "-in-law" for f in family}) |
|
|
|
def lf_familial_relationship(x, family): |
|
return NEGATIVE if len(family.intersection(set(x.between_tokens))) > 0 else ABSTAIN |
|
|
|
|
|
#### LF 6 |
|
# Check for words that refer to `family` relationships to the left of the person mentions |
|
def lf_family_left_window(x, family): |
|
if len(set(family).intersection(set(x.person1_left_tokens))) > 0: |
|
return NEGATIVE |
|
elif len(set(family).intersection(set(x.person2_left_tokens))) > 0: |
|
return NEGATIVE |
|
else: |
|
return ABSTAIN |
|
|
|
|
|
#### LF 7 |
|
# Check for `other` relationship words between person mentions |
|
other = {"boyfriend", "girlfriend", "boss", "employee", "secretary", "co-worker"} |
|
def lf_other_relationship(x, other): |
|
return NEGATIVE if len(other.intersection(set(x.between_tokens))) > 0 else ABSTAIN |
|
|
|
|
|
#### LF 8 |
|
# Simple distant supervision labeling function via DBPedia |
|
@labeling_function(resources=dict(known_spouses=known_spouses), pre=[get_person_text]) |
|
def lf_distant_supervision(x, known_spouses): |
|
p1, p2 = x.person_names |
|
if (p1, p2) in known_spouses or (p2, p1) in known_spouses: |
|
return POSITIVE |
|
else: |
|
return ABSTAIN |
|
|
|
#### LF 9 |
|
# Last name pairs for known spouses |
|
last_names = set( |
|
[ |
|
(last_name(x), last_name(y)) |
|
for x, y in known_spouses |
|
if last_name(x) and last_name(y) |
|
] |
|
) |
|
@labeling_function(resources=dict(last_names=last_names), pre=[get_person_last_names]) |
|
def lf_distant_supervision_last_names(x, last_names): |
|
p1_ln, p2_ln = x.person_lastnames |
|
|
|
return ( |
|
POSITIVE |
|
if (p1_ln != p2_ln) |
|
and ((p1_ln, p2_ln) in last_names or (p2_ln, p1_ln) in last_names) |
|
else ABSTAIN |
|
) |