floop: INIT told placeholders are resolved + identity seed (his design)
His two-part direction after the PR-16 live run (the model spent a subquestion asking 'who is PERSON_1?'): 1. INIT desc now says masked entities (PERSON_1, ORGANIZATION_1...) are ALREADY-RESOLVED named entities — treat each as a known specific entity; do not ask what or who the placeholder is. 2. Safety net: identity_answer() detects a subquestion that ONLY asks who/what one placeholder refers to — the mask map already knows. The machine seeds it as evidence (engine=mask:seed, verified, zero LLM calls) instead of routing it to an expert. Detection is deterministic and conservative by law: exactly one placeholder in the text, literal 'who/what is <ph>' (ending there or in punctuation — possessives like 'who is PERSON_1's predecessor' do NOT match) or the text names the mask mechanism. Detection runs on the MASKED text (placeholders still present) before restore. VERIFIED: tests/anonymize.py 6/6 (seed marking, conservative detection incl. possessives/comparatives/no-placeholder forms); suite 15/15. Live E2E (glm-5.3-flash): with the new desc INIT returns exactly the TWO subquestions he wants (term years + predecessor) — no identity question, seed unused but armed; run answers Rajoy (E1+E2, 30 calls).
This commit is contained in:
+35
-1
@@ -26,7 +26,7 @@ from dspy._vendor.lm15 import Response, TextPart, Message, Usage
|
||||
from dspy.utils.exceptions import AdapterParseError
|
||||
|
||||
from floop.dspy_modules import FloopModules
|
||||
from floop.anonymize import NamedEntity, apply_mask, restore_mask
|
||||
from floop.anonymize import NamedEntity, apply_mask, identity_answer, restore_mask
|
||||
|
||||
|
||||
def _lm(script: list[str]) -> None:
|
||||
@@ -95,6 +95,38 @@ def test_no_entities_passthrough():
|
||||
print("ok: no entities found -> question reaches INIT unchanged")
|
||||
|
||||
|
||||
_TWO_SUBS_ID = '''[[ ## subquestions ## ]]
|
||||
[{"text": "Who is PERSON_1, i.e., which specific individual does the placeholder refer to?", "depends_on": [], "answer_type": "OPEN"},
|
||||
{"text": "Which office does PERSON_1 hold as President?", "depends_on": [1], "answer_type": "OPEN"},
|
||||
{"text": "Who held that office before PERSON_1?", "depends_on": [2], "answer_type": "OPEN"}]
|
||||
|
||||
[[ ## completed ## ]]'''
|
||||
|
||||
|
||||
def test_identity_subquestion_seeded():
|
||||
# the live PR-16 shape: subquestion 1 asks who PERSON_1 is — the mask
|
||||
# map already knows. It must come back marked known_answer, never routed.
|
||||
_lm([_MASKED_ENTS, _TWO_SUBS_ID])
|
||||
subs, _ = FloopModules().init_decompose(Q)
|
||||
assert len(subs) == 3, subs
|
||||
assert subs[0].get("known_answer") == "Pedro Sanchez", subs[0]
|
||||
assert not subs[1].get("known_answer") and not subs[2].get("known_answer")
|
||||
print("ok: identity subquestion carries known_answer (never routed)")
|
||||
|
||||
|
||||
def test_identity_detection_conservative():
|
||||
# 'who is PERSON_1's predecessor' is NOT an identity question
|
||||
r = {"PERSON_1": "Pedro Sanchez"}
|
||||
assert identity_answer("Who is PERSON_1?", r) == "Pedro Sanchez"
|
||||
assert identity_answer("What is ORGANIZATION_1?", {"ORGANIZATION_1": "PSOE"}) == "PSOE"
|
||||
assert identity_answer("Which specific individual does the placeholder refer to?", r) is None
|
||||
assert identity_answer("Who is PERSON_1, i.e., which specific individual does the placeholder refer to?", r) == "Pedro Sanchez"
|
||||
assert identity_answer("Who was PERSON_1's predecessor?", r) is None
|
||||
assert identity_answer("What office does PERSON_1 hold?", r) is None
|
||||
assert identity_answer("Who is PERSON_1 compared to PERSON_2?", {**r, "PERSON_2": "x"}) is None
|
||||
print("ok: identity detection conservative (possessives/comparatives not eaten)")
|
||||
|
||||
|
||||
def test_mask_death_passthrough():
|
||||
# MASK response violates the schema -> AdapterParseError -> passthrough
|
||||
_lm(["garbage", _TWO_SUBS.replace("PERSON_1", "Pedro Sanchez")])
|
||||
@@ -107,5 +139,7 @@ if __name__ == "__main__":
|
||||
test_apply_restore_deterministic()
|
||||
test_init_decompose_masks_and_restores()
|
||||
test_no_entities_passthrough()
|
||||
test_identity_subquestion_seeded()
|
||||
test_identity_detection_conservative()
|
||||
test_mask_death_passthrough()
|
||||
print("\nanonymization tests passed")
|
||||
Reference in New Issue
Block a user