Intent classifier hits

Write codeEasy10 minOpenAI and Anthropic style

Your task

A chatbot's intent classifier returns a short ranked list of candidate intent ids for each utterance, and the eval counts a hit when the true intent appears anywhere in that list (top-k accuracy). Given y_true, a list of true intent ids, and topk_preds, where topk_preds[i] is the candidate list for utterance i, return the number of utterances whose true id appears in their candidate list. Example: y_true = [3, 1, 2] with topk_preds = [[3, 5], [2, 4], [2, 1]] has hits at positions 0 and 2, so return 2.

Examples

topk_hits(y_true: list[int], topk_preds: list[list[int]]) -> int
Example 1
Inputtopk_hits([3, 1, 2], [[3, 5], [2, 4], [2, 1]])
Output2