来源:投稿 作者:LSC
编辑:学姐
unset
unset
一面
unset
unset
1.自我介绍
2.介绍自己对推荐流程的了解
3.介绍diffusion的原理
4.写一下diffusion的伪代码
5.写一下Masking Attention的伪代码
def masked_attention(Q, K, V, mask):
"""
计算 Masked Attention 的伪代码函数
Args:
- Q: 查询矩阵,shape: [batch_size, num_heads, seq_length, head_dim]
- K: 键矩阵,shape: [batch_size, num_heads, seq_length, head_dim]
- V: 值矩阵,shape: [batch_size, num_heads, seq_length, head_dim]
- mask: 掩码矩阵,用于屏蔽未来位置信息,shape: [batch_size, 1, seq_length, seq_length]
Returns:
- output: Masked Attention 的输出,shape: [batch_size, num_heads, seq_length, head_dim]
"""
# 计算 Q 和 K 的点积
scores = torch.matmul(Q, K.transpose(-1, -2)) # [batch_size, num_heads, seq_length, seq_length]
# 缩放点积
scores = scores / math.sqrt(Q.size(-1))
# 将掩码加入到得分中
scores = scores.masked_fill(mask == 0, float('-inf')) # 屏蔽未来位置信息
# 使用 softmax 函数进行归一化
attention_weights = F.softmax(scores, dim=-1) # [batch_size, num_heads, seq_length, seq_length]
# 将注意力权重应用于值向量
output = torch.matmul(attention_weights, V) # [batch_size, num_heads, seq_length, head_dim]
return output
6.0-1均匀的随机生成器,求均值,方差。然后怎么变成均值为0、方差为1的生成器?
期望值 E(x) = 1/2,方差 Var(x)=E(x^2) - [E(x)]^2=1/12
通过线性变换将其转换为均值为0,方差为1的随机变量:
7.BN有什么作用?为什么有效?
8.如果用户的喜好单一,怎么对用户实现多样而精准的推荐?
(1)深度理解用户偏好:
-
通过分析用户的历史行为数据(如浏览历史、购买记录、评分等),深度理解用户的偏好和兴趣。
-
利用用户的社交网络信息、个人资料信息等辅助数据,从多个维度对用户进行建模。
(2)引入多样性度量:
-
在推荐系统中引入多样性度量,如覆盖率、多样性指数等,用于评估推荐结果的多样性程度。
-
(3)采用多样性增强技术:
-
在推荐系统中引入多样性增强技术,如基于内容的推荐、隐式反馈的推荐、协同过滤的推荐等。
关注“
学姐带你玩AI
”公众号,