loss reweight技术、flooding技术

一、loss reweight技术

由于推荐结果具有多种形态形态,不同场景优化目标不同,并且不止一个,所以我们使用reweight技术来将多个目标合理加权到总loss上,实现多目标学习

θ σ + 1 = α θ ~ + ( 1 − α ) θ σ \theta_{\sigma+1}=\alpha\tilde{\theta}+\left(1-\alpha\right)\theta_{\sigma} θσ+1=αθ~+(1α)θσ
θ ~ = L ( σ + 1 ) main L ( σ + 1 ) main + λ L ( σ + 1 ) contractive-learn \tilde{\theta}=\frac{\mathcal{L}_{\left(\sigma+1\right)_{\text{main}}}}{\mathcal{L}_{\left(\sigma+1\right)_{\text{main}}}+\lambda\mathcal{L}_{\left(\sigma+1\right)_{\text{contractive-learn}}}} θ~=L(σ+1)main+λL(σ+1)contractive-learnL(σ+1)main
L ( σ + 1 ) joint = L ( σ + 1 ) main + θ σ + 1 ( α , λ ) L ( σ + 1 ) contractive-learn \mathcal{L}_{\left(\sigma+1\right)_{\text{joint}}}=\mathcal{L}_{\left(\sigma+1\right)_{\text{main}}}+\theta_{\sigma+1}\left(\alpha,\ \lambda\right)\mathcal{L}_{\left(\sigma+1\right)_{\text{contractive-learn}}} L(σ+1)joint=L(σ+1)main+θσ+1(α, λ)L(σ+1)contractive-learn

# sup_con_curriculum_loss:第一个loss,一维张量
# recommender_ce_loss:第二个loss,一维张量
# reweight_loss_lambda:λ的值
# reweight_loss_alpha:α的值
#reweight_loss_theta_hat:θ tilde的值# 将loss除以batchsize
sup_con_curriculum_loss_div = torch.div(sup_con_curriculum_loss,torch.tensor(float(self.train_batch_size), requires_grad=True))
recommender_ce_loss_div = torch.div(recommender_ce_loss,torch.tensor(float(self.train_batch_size), requires_grad=True))# 算出theta_hat
reweight_loss_theta_hat = \recommender_ce_loss_div / (recommender_ce_loss_div + self.reweight_loss_lambda * sup_con_curriculum_loss_div)# 获取最终loss加权的值
self.reweight_loss_theta_after = self.reweight_loss_alpha * reweight_loss_theta_hat + \(1 - self.reweight_loss_alpha) * self.reweight_loss_theta_before# 存储上一轮的θ,用于下一轮的θ计算
self.reweight_loss_theta_before = self.reweight_loss_theta_after.data# 最终的loss加权公式,得到一维的张量
total_loss = recommender_ce_loss_div + self.reweight_loss_theta_after * sup_con_curriculum_loss_div

二、flooding技术

该技术是为了解决在训练模型的时候,训练集损失降到一定的值之后,验证集的损失就开始上升了,但奇怪的是准确率还跟着上升的这个问题,从而使验证集的损失也下降,本质来说flooding也是一种正则化

L ~ ( θ ) = ∣ L ( θ ) − b ∣ + b \tilde{\mathcal{L}}\left(\theta\right)=|\mathcal{L}\left(\theta\right)-b|+b L~(θ)=L(θ)b+b

  • 当training loss大于一个阈值(flood level)时,进行正常的梯度下降;
  • 当training loss低于阈值时,会反过来进行梯度上升,让training loss保持在一个阈值附近,让模型持续进行“random walk”,并期望模型能被优化到一个平坦的损失区域,这样发现test loss进行了double decent!
 # 正则化floodingtotal_loss_after_reg = (total_loss - self.total_loss_b).abs() + self.total_loss_b


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部