【李宏毅2022 机器学习春】hw4_Self-Attention(接近 strong baseline,等待改进中)

实验记录

去年的程序,洗洗还能用:【李宏毅2021机器学习深度学习——作业4 Self-Attention】Speaker classification 记录(双过strong baseline)(待改进)

在这里插入图片描述
做了conformer却没达到strong baseline,参数用的默认参数(没有调参,参数也不是很理解), AMSoftmax有提升,SAP却低了(可能代码写错了?)。

等待改进中…做了一回调包侠…

评分标准

在这里插入图片描述
在这里插入图片描述

收获

train的准确率是1,说明过拟合了把所有样本记下来了,模型并没有真正学到。必须Additive Margin Softmax 使任务更难一点。
在这里插入图片描述

参考资料

李宏毅2022机器学习HW4解析

Conformer

https://github.com/lucidrains/conformer/blob/master/conformer/conformer.py

AM-Softmax:

我用的这个 code:https://github.com/zhilangtaosha/SpeakerVerification_AMSoftmax_pytorch
【论文阅读】AM-Softmax:Additive Margin Softmax for Face Verification. 1801.05599.【损失函数设计】
在这里插入图片描述

FocalSoftmax

在这里插入图片描述

【ML2021李宏毅机器学习】作业4 Speaker Classification 思路讲解:https://www.bilibili.com/video/BV1nL4y1H7Wo

Self_Attention_Pooling
在这里插入图片描述

SAP另一实现:https://github.com/nii-yamagishilab/project-NN-Pytorch-scripts/commit/b0d9ac3e2602cd96e042daf5f78103df6a9bb1af

class SelfWeightedPooling(torch_nn.Module):
    """ SelfWeightedPooling module
    Inspired by
    https://github.com/joaomonteirof/e2e_antispoofing/blob/master/model.py
    To avoid confusion, I will call it self weighted pooling
    """

    def __init__(self, feature_dim, mean_only=False):
        super(SelfWeightedPooling, self).__init__()

        self.feature_dim = feature_dim
        self.mean_only = mean_only
        self.noise_std = 1e-5

        self.mm_weights = torch_nn.Parameter(
            torch.Tensor(1, feature_dim), requires_grad=True)
        torch_init.kaiming_uniform_(self.mm_weights)

    def forward(self, inputs):
        """
        inputs
        ------
          tensor of shape (batchsize, length, feature_dim)
        
        output
        ------
          tensor of shape (batchsize, feature_dim * 2) if mean_only is False
          tensor of shape (batchsize, feature_dim) if mean_only is True
        """

        # batch matrix multiplication
        batch_size = inputs.size(0)
        # change mm_weights to (batchsize, feature_dim, 1)
        # weights in shape (batchsize, length, 1)
        weights = torch.bmm(
            inputs, 
            self.mm_weights.permute(1, 0).unsqueeze(0).repeat(batch_size, 1, 1))

        # attention (batchsize, length, 1)
        attentions = torch_nn_func.softmax(torch.tanh(weights),dim=1)

        # pooling
        # weighted (batchsize, length, feature_dim)
        weighted = torch.mul(inputs, attentions.expand_as(inputs))

        if self.mean_only:
            # only output the mean vector
            return weighted.sum(1)
        else:
            # output the mean and std vector
            noise = self.noise_std * torch.randn(
                weighted.size(), dtype=weighted.dtype, device=weighted.device)

            avg_repr, std_repr = weighted.sum(1), (weighted+noise).std(1)

            # concatenate mean and std
            representations = torch.cat((avg_repr,std_repr),1)
            return representations

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
李宏毅2023机器学习作业12是使用强化学习完成Lunar Lander任务,训练飞行器在月球上着陆。作业基于OpenAI的gym框架,但只能在Linux系统上使用。作业过程需要助教提供的代码,可以通过关注公众号获取代码。\[1\] 此外,还有一些与ML2023Spring - HW01相关的信息,包括课程主页、课程视频、Kaggle链接、示例代码等。你可以在做作业之前观看相关视频,了解数据特征等内容。\[2\] 在作业,还对代码进行了一些修改,以便于后续的调参。具体修改的部分是在My_Model类,通过修改超参数'config'的模型结构,注意维度的变化。\[3\] 希望以上信息对你有所帮助。如果还有其他问题,请随时提问。 #### 引用[.reference_title] - *1* [李宏毅2022机器学习HW12解析](https://blog.csdn.net/weixin_42369818/article/details/126119360)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [李宏毅2023机器学习作业 HW01 解析和代码分享](https://blog.csdn.net/weixin_42426841/article/details/129520007)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值