KatInterview

Evaluating a Text Classifier and Retriever: Metrics and Reporting

Machine LearningModel answer
EasyModel answerMachine Learningevaluation-metricsnlpranking

Last updated

Work through agreement, classification and ranking metrics, TF-IDF, reproducibility and model comparison for a document classification and search system, showing the arithmetic.

You are reviewing the evaluation of a system that classifies documents as relevant or not relevant and also ranks documents for search queries. Walk through each area below, state your assumptions, and show the arithmetic.

Assumptions: offline evaluation, a held-out test set, binary labels unless stated otherwise, and no special infrastructure.

  1. Label agreement. Two annotators label 100 documents. Both say "relevant" on 40, both say "not relevant" on 45, A says relevant and B says not on 10, and A says not and B says relevant on 5. Compute Cohen's kappa and explain what it tells you that raw agreement does not.

  2. Classification metrics. On 1,000 test documents the confusion matrix is TP = 80, FP = 20, FN = 40, TN = 860. Compute precision, recall, F1 and accuracy. Compare accuracy to a trivial baseline, and say which metrics you would report if positives are rare and missed positives are costly. Explain macro versus micro averaging for multi-class problems.

  3. Reproducibility. List what you would pin down and log so that another engineer can rerun the experiment and obtain the same numbers, and how you would report run-to-run variance.

  4. TF-IDF. In a corpus of 4 documents, the term "arbitration" appears in exactly 1 document, 3 times among 100 tokens. Compute its TF-IDF weight (natural log) and explain what happens to a term present in every document.

  5. Ranking metrics.

    • Binary relevance: the top 5 results are [relevant, not, relevant, not, not], and 3 relevant documents exist in total. Compute Precision@5, Recall@5, reciprocal rank and average precision.
    • Graded relevance: grades at ranks 1 to 5 are [2, 0, 3, 0, 1]. Compute NDCG@5 using gain = rel and discount = log2(rank + 1).
    • Say when you would prefer MRR, NDCG, or MAP/Recall@k.
  6. Comparing models. Model A scores 0.805 and Model B scores 0.812 accuracy on the same 2,000 test items. Can you claim B is better? Describe an appropriate test and what a good experiment report contains.

Close with how you would validate your answers and which pitfalls you would watch for.

Hints

Hint 1

Kappa is (p_o - p_e) / (1 - p_e). Get p_e from each annotator's marginal yes and no rates, not from the diagonal of the table.

Hint 2

Compare accuracy to the all-negative baseline before judging it. For ranking, average precision divides by all relevant documents, not only the retrieved ones, and NDCG divides DCG by the DCG of the ideal ordering.

Hint 3

For the model comparison, compute the standard error of an accuracy and compare it to the gap. Because both models scored the same items, use a paired method such as McNemar's test or a paired bootstrap.