Evaluation
RecDistillery evaluates teachers and students with top-k recommendation metrics.
The common metric implementation lives in recdistill.evaluation and is used by
the teacher and student evaluation scripts.
Teacher Evaluation
python scripts/recdistill/evaluate_teacher.py \
--teacher-path results/teacher/<run>/artifacts/<teacher>_best.teacher
Student Evaluation
python scripts/recdistill/evaluate_students.py \
--student-path results/student/<run>/artifacts/<student>_best.student
Distilled students use the same evaluator:
python scripts/recdistill/evaluate_students.py \
--student-path results/recdistill/<run>/artifacts/<student>_best.distilled_student
Metrics
The evaluation module computes ranking metrics such as precision, recall, NDCG, and hit ratio over held-out validation or test interactions.
| Function | Purpose |
|---|---|
evaluate_teacher |
Evaluates a TeacherState on validation and test splits. |
evaluate_student |
Evaluates a trained student model with the same ranking protocol. |
evaluate_embeddings |
Shared embedding/scorer evaluator used by teacher and student APIs. |
Evaluate a serialized or imported teacher on validation/test splits.
The teacher may expose either user/item embeddings or a scorer-only representation such as a precomputed score matrix or top-k predictions. Training interactions are masked before ranking so the metrics are computed only over unseen candidate items.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
teacher_state
|
TeacherState
|
Runtime teacher representation loaded from a |
required |
train_seen
|
dict[int, set[int]]
|
Mapping from user index to training items that must be removed from the ranked candidate set. |
required |
val_gt
|
dict[int, set[int]]
|
Validation ground-truth items keyed by user index. |
required |
test_gt
|
dict[int, set[int]]
|
Test ground-truth items keyed by user index. |
required |
top_k
|
int
|
Recommendation cutoff used by precision, recall, NDCG and hit ratio. |
required |
batch_size
|
int
|
Number of users evaluated per embedding-ranking batch. |
required |
device
|
device
|
Torch device used for score computation. |
required |
eval_val_only
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, float] | int]
|
A dictionary with split metrics and train-leakage counters. The metric |
dict[str, dict[str, float] | int]
|
dictionaries contain |
Source code in recdistill/evaluation.py
Evaluate a trained student model on validation and test splits.
The student must expose get_all_user_embeddings and
get_all_item_embeddings. If it also implements score_items_for_user,
that scorer is used for ranking.
Source code in recdistill/evaluation.py
Evaluate top-k recommendations from embeddings or a scorer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_embeddings
|
Tensor
|
User embedding matrix, or |
required |
item_embeddings
|
Tensor
|
Item embedding matrix, or |
required |
train_seen
|
dict[int, set[int]]
|
Training items keyed by user. These items are masked before ranking. |
required |
ground_truth
|
dict[int, set[int]]
|
Held-out target items keyed by user. |
required |
top_k
|
int
|
Recommendation cutoff. |
required |
batch_size
|
int
|
Number of users per embedding-ranking batch. |
required |
device
|
device
|
Torch device used for score computation. |
required |
scorer
|
TeacherScorer | None
|
Optional object implementing |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
A pair containing the metric dictionary and the number of users whose |
int
|
raw top-k list still contained a training item before final filtering. |