BLOGLLM Logo
Go Pro
Guest
Not signed in
所有博客课程练习面试准备系列标签书签价格
Log in
All BlogsCoursesPracticeTagsBookmarksPricing
My PrepProblemsStudy PlansResearch PapersRoadmapInterviewContestsLeaderboard游戏
Articles
练习 / Recommender systems7 of 22 in topic

200. 衡量推荐列表的列表内多样性

EasyRecommender systems

重要性 推荐团队会在准确率指标之外追踪 ILD,以防止模型通过重复推荐近乎重复的内容而在离线评估中胜出。

一个包含十个几乎相同的 item 的列表虽然准确但很枯燥。列表内多样性 (ILD) 用于衡量推荐 item 之间的差异程度。

编写 intra_list_diversity(emb, items)。emb 是一个形状为 (N, D) 的 item embeddings 数组,items 是指向该数组的索引列表。返回列表中所有无序且不同的位置对之间 1 - cosine similarity 的平均值,结果为 float。如果列表中的 item 少于 2 个,则返回 0.0。

函数def intra_list_diversity(emb, items)

示例 1

输入: intra_list_diversity([[1, 0], [0, 1], [1, 1]], [0, 1, 2])

输出: 0.5286

示例 2

输入: emb = [[2, 2], [1, 1], [0, 3]], items = [0, 1]

输出: 2.220446e-16

示例 3

输入: emb = [[1, 0], [-1, 0]], items = [0, 1]

输出: 2.0

约束条件

  • Python 3 with NumPy. Code runs in your browser.
  • Your code must pass all 5 tests to be accepted.
提示 1

是对 n * (n - 1) / 2 个 pair 求平均,而不是对 n^2 个条目求平均。

提示 2

转换为数组后使用 emb[items] 进行索引。

提示 3

np.triu_indices(n, 1) 会排除对角线。

提示 4

对长度小于 2 的列表进行边界检查。

常见错误
  • 在计算平均值时包含了自对 (self-pairs)。
  • 使用了原始点积 (dot products) 而不是余弦相似度。
  • 除以了 n^2 而不是 pair 的数量。
理解思路

准确率指标奖励能够展示用户会点击的内容的推荐系统,但用户也会感到厌倦。如果首页展示了十个同款手机壳,准确率可能看起来很好,但用户体验却很差。列表内多样性为多样化程度提供了一个量化数值:即列表中每对 item 之间的平均距离。

Worked example

三个 item 的 embeddings 分别为 [1, 0], [0, 1] 和 [1, 1]。前两个成直角,距离为 1 - 0 = 1。它们中的每一个与第三个都成 45 度角,距离为 1 - 0.707 = 0.293。这三个 pair 的平均值为 (1 + 0.293 + 0.293) / 3 = 0.529。

ILD = mean over pairs i < j of (1 - cos(e_i, e_j))

团队通常在报告 NDCG 和 recall 的同时报告 ILD,并在 ILD 过低时使用 MMR 等重排序 (re-ranking) 方法。

主题
Recommender systems
相似题目
  • 衡量推荐系统的 hit rate 和 recall at kEasy
  • 计算隐式反馈的 BPR ranking loss 并防止溢出Easy
  • 推荐最热门的未见过的物品Easy
  • 衡量推荐系统的目录覆盖率Easy
所有 Recommender systems 道题目
反馈
200 / 903
Python 3solution.pyPython 空闲
1
2
3
4
5
6
import numpy as np
​
def intra_list_diversity(emb, items):
# your code here
pass
​

Run 会在浏览器中检查这些用例,无需登录。 Submit 会检查所有 5 个测试。

Ctrl/按 + 回车 运行
© BlogLLM, Bengaluru, India关于条款隐私退款DMCA联系我们RSS