TypeClaim does not need to rewrite the quote/verbatim

This commit is contained in:
2026-11-01 17:12:32 +01:00
parent 4e7229c92c
commit 3d541ec8d6
5 changed files with 112 additions and 88 deletions
+29 -16
View File
@@ -5,8 +5,8 @@ VERBATIM spans. The containment check (checks.py) validates every span against
the FULL document text — so chunking can never fake a quote.
Two-pass (two_pass.py): Pass 1 (ExtractClaims) extracts the claims WITH their
VERBATIM spans; Pass 2 (TypeClaim) types ONE claim, the verbatim given to it
as an input — typing only, the VERBATIM is obtained before (owner 1/11).
VERBATIM spans; Pass 2 (TypeClaim) types ONE claim — typing only, the model
never sees the quote; code composes Fact = FactNoQuote + verbatim (owner 1/11).
"""
from __future__ import annotations
@@ -60,6 +60,24 @@ class Fact(BaseModel):
"of the sibling fact>}; empty when the text asserts no order")
class FactNoQuote(BaseModel):
subject: str = dspy.OutputField(desc="the fact's subject entity")
relation: str = dspy.OutputField(desc="the relation between subject and object")
object: str = dspy.OutputField(desc="the fact's object / value")
start: str | None = dspy.OutputField(
default=None,
desc="when the fact begins, as stated in the claim (a year like 2018, or a full date); empty when the claim states no start")
end: str | None = dspy.OutputField(
default=None,
desc="when the fact ends, as stated in the claim; empty when ongoing/unknown")
point: str | None = dspy.OutputField(
default=None,
desc="for point-in-time facts (events): the stated date; empty otherwise")
granularity: str | None = dspy.OutputField(
default=None,
desc="precision of the stated dates: year, month, or day; empty when no dates")
class ExtractSignature(dspy.Signature):
"""You are the EXTRACT step of a knowledge machine. From the given text,
extract facts about the NAMED ENTITIES: biographical facts, positions
@@ -108,21 +126,16 @@ class ExtractClaims(dspy.Signature):
class TypeClaim(dspy.Signature):
"""You are the TYPE step of a knowledge machine. Given ONE single claim
and the VERBATIM quote that states it (extracted before, from the
text the claim came from), type the claim into the Fact schema:
subject entity, relation, object/value, and the temporal
restrictions the quote states. The Fact's quote is the given
verbatim, copied exactly. All temporal fields are optional and must
be contained in the quote. Only what the claim and its quote state;
no inference. If the claim cannot be typed honestly, return null."""
"""You are the TYPE step of a knowledge machine. Given ONE single claim,
type the claim into the typed fact schema: subject entity, relation,
object/value, and the temporal restrictions the claim states. All
temporal fields are optional. Only what the claim states; no
inference. If the claim cannot be typed honestly, return null."""
claim: str = dspy.InputField(desc="the claim to type")
verbatim: str = dspy.InputField(
desc="the VERBATIM quote that states the claim, obtained before — "
"the Fact's quote field must copy it exactly")
fact: Fact | None = dspy.OutputField(
desc="the typed Fact whose quote is the given verbatim, or null "
"when the claim cannot be typed honestly")
fact: FactNoQuote | None = dspy.OutputField(
desc="the typed fact — subject, relation, object, temporal "
"restrictions, or null when the "
"claim cannot be typed honestly")
class AnswerFromKG(dspy.Signature):