in dataset-construction/src/ndb_data/construction/make_questions.py [0:0]
def generate_negative_bool(hf, question_template, origianal_hyp):
candidate_negatives_1 = []
for f in hf.keys():
if (
f[1] == origianal_hyp[1]
and f[0] != origianal_hyp[0]
and f[2] != origianal_hyp[2]
):
candidate_negatives_1.append(f)
if len(candidate_negatives_1):
hyp_to_make_negative = list(copy(origianal_hyp))
hyp_to_make_negative[2] = random.choice(candidate_negatives_1)[2]
hyp_to_make_negative = tuple(hyp_to_make_negative)
s, r, o = hyp_to_make_negative
subject_name = wiki.get_by_id_or_uri(hyp_to_make_negative[0])["english_name"]
if hyp_to_make_negative[2].startswith("Q"):
object_name = wiki.get_by_id_or_uri(hyp_to_make_negative[2])["english_name"]
if object_name is None:
return None
else:
object_name = hyp_to_make_negative[2]
assert object_name != origianal_hyp[2]
subj_in_q = f"_{s}" if "$s" in question_template[0] else ""
obj_in_q = f"_{o}" if "$o" in question_template[0] else ""
s_key = (
question_template[1].split("[SEP]")[0].strip()
if "$" in question_template[1]
else ""
)
sort_key = (
(f"_{s_key}" if "$" in question_template[1] else "")
if r != "P47"
else "_$both"
)
qid = f"bool_{r}{subj_in_q}{obj_in_q}{sort_key}_art_false"
out = [
q.replace("$s", subject_name).replace("$o", object_name)
for q in question_template
]
out[1] = "FALSE"
return qid, "bool", out, hf[origianal_hyp]
return None