Bird
0
0

Given this custom metric class, what will metric.evaluate(['hello'], ['hello']) return?

medium📝 component behavior Q13 of 15
LangChain - Evaluation and Testing
Given this custom metric class, what will metric.evaluate(['hello'], ['hello']) return?
class ExactMatch(Evaluation):
    def evaluate(self, predictions, references):
        return sum(p == r for p, r in zip(predictions, references)) / len(references)
A1.0
B0.0
CError due to missing method
DNone
Step-by-Step Solution
Solution:
  1. Step 1: Understand the evaluate method logic

    It compares each prediction to the reference and counts matches, then divides by total references.
  2. Step 2: Apply inputs to the method

    With predictions=['hello'] and references=['hello'], the single pair matches, so sum is 1 and length is 1, result is 1/1 = 1.0.
  3. Final Answer:

    1.0 -> Option A
  4. Quick Check:

    Exact match count / total = 1.0 [OK]
Quick Trick: Check if predictions equal references, then divide [OK]
Common Mistakes:
MISTAKES
  • Forgetting to divide by length
  • Confusing sum with boolean values
  • Expecting method to return a list

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes