DeepEvaldeepeval 4.2 ยท Python 3.9+
0%
1
Curious builder0 XP earned ยท 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
23 small wins to finish your pathNext lesson โ†’

ExactMatchMetric: your first metric

A test case holds an answer and a metric scores it. The simplest metric in DeepEval does what lesson 1 did by hand, and it comes first because it needs no judge at all.

python
from deepeval.metrics import ExactMatchMetric

metric = ExactMatchMetric()
Example
metric.measure(case)

print("score:  ", metric.score)
print("reason: ", metric.reason)
print("success:", metric.is_successful())

measure scores the test case and keeps the result on the metric object, which is why the next three lines read it from metric.

score runs from 0 to 1. Every metric in DeepEval scores on that same scale.

reason says why, in a sentence.

is_successful() says whether the score was good enough to pass.

The reworded answer

Example
reworded = LLMTestCase(
    input="Where is order A17?",
    actual_output="Your order A17 was shipped on 3 March.",
    expected_output="Order A17 shipped on 3 March.",
)
metric.measure(reworded)

print("score:    ", metric.score)
print("reason:   ", metric.reason)
print("success:  ", metric.is_successful())
print("threshold:", metric.threshold)

Score 0, which is lesson 1's first problem again: the meaning is right and the characters are not.

The last line is the pass mark. threshold is the lowest score that counts as a pass, and a metric succeeds when its score reaches it. For exact match the default is 1, so only a perfect match passes. Most other metrics default to 0.5, which starts to matter in lesson 10.

Measuring the second test case replaced the first result. A metric object remembers only the last thing it measured.

Exact to the character
Casing, spaces and punctuation all count, so a missing full stop is a failure. Exact match calls no model and costs nothing, which makes it the right tool when there is exactly one acceptable answer: a category label, a yes or no, a fixed reply.
Try it yourself
  • Remove the full stop from the expected output and measure the first test case again.
  • Create ExactMatchMetric(threshold=0) and see what is_successful() says about the reworded answer.

Slow is fine. Stopping is the only problem.