Semantic recall checks how well a generated summary covers the ideas in a reference summary, regardless of whether it uses the same words. section 8.6.1
An LLM judge can assess semantic precision and recall. DSPy provides SemanticF1, which combines these measures but expects examples with question and response fields. section 8.6.1
Listing 8.13 Metric function using SemanticF1
import dspy
from dspy.evaluate import SemanticF1
lm = dspy.LM('openai/gpt-4.1-nano', cache=False)
dspy.configure(lm=lm)
test_example = dspy.Example(
question="What is the Rime of the Ancient Mariner about?",
response="A sailor stops a wedding guest to recount his cursed journey
after he "
"thoughtlessly shoots an albatross, a bird of good omen, bringing
death to "
"shipmates and himself.") #1
test_pred = dspy.Prediction(response=
"A mariner recalls his voyage at sea, which was doomed
after he killed a bird") #2
semantic_f1 = SemanticF1() #3
semantic_f1(test_example, test_pred) #4
See SemanticF1 applied to a reference and generated summary about the Rime of the Ancient Mariner. section 8.6.1
