AI Engineer Portal
Your personal operating system for career transition.
Exercise
Compute semantic similarity for evaluation
Compute Semantic Similarity for Evaluation
Embedding-based similarity captures whether two texts mean the same thing even with different wording — essential for evaluating open-ended generation where BLEU/ROUGE produce false negatives.
What to build
Implement SemanticSimilarityScorer:
-
score(prediction, reference) -> float— Embeds both with injectedembed_fn, returns cosine similarity (0.0-1.0). Returns 0.0 (with a logged warning) ifembed_fnraises. -
score_batch(cases: list[dict]) -> dict— Each case has"prediction"and"reference". Returns{"avg_similarity", "above_threshold", "n"}. Threshold set in constructor (default 0.8). -
find_low_similarity_cases(cases, threshold=None) -> list[dict]— Returns cases below threshold with"similarity"added.
Constraints
- Standard library only (implement cosine manually). No external embedding library.
Evaluation / medium / Step 20 of 36
Evaluation and review loops
Separate the scoring logic from the interpretation logic. Your goal is not just a number; it is a useful next action.
- - Produces a useful signal, not decorative output
- - Makes regression review easier
- - Would support a benchmark or observability loop
- - Would this output help decide what to fix next?
- - Are important failure modes visible?
- - Does the score hide any ambiguity I should record?
Practice
Generate a variation
Generate a new exercise variation to deepen understanding or practice a related concept.
Attempt history
Recent submissions
Before you submit, decide what a strong answer should make obvious to the reviewer.
No attempts yet.