当前位置:网站首页>学习笔记【gumbel softmax】
学习笔记【gumbel softmax】
2022-07-01 18:43:00 【hei_hei_hei_】
gumbel softmax
用于处理argmax不可导的情况
解决思路:引入gumbel分布。在前向传播中使用argmax,后向梯度回传中使用gumbel_softmax计算
代码
def gumbel_softmax(logits: Tensor, tau: float = 1, hard: bool = False, eps: float = 1e-10, dim: int = -1) -> Tensor:
。。。
gumbels = (
-torch.empty_like(logits, memory_format=torch.legacy_contiguous_format).exponential_().log()
) # ~Gumbel(0,1)
gumbels = (logits + gumbels) / tau # ~Gumbel(logits,tau)
y_soft = gumbels.softmax(dim)
if hard:
# Straight through.
index = y_soft.max(dim, keepdim=True)[1]
y_hard = torch.zeros_like(logits, memory_format=torch.legacy_contiguous_format).scatter_(dim, index, 1.0)
ret = y_hard - y_soft.detach() + y_soft
else:
# Reparametrization trick.
ret = y_soft
return ret
gumbel_softmax中引入了温度t, t越小,softmax就越接近One-hot。为了训练稳定性,一般t会取一个比较大的数字,然后逐步缩小。
内容转载自gumbel softmax
边栏推荐
- 记一次 .NET 差旅管理后台 CPU 爆高分析
- 水产行业智能供应链管理平台解决方案:支撑企业供应链数字化,提升企业管理效益
- [live broadcast appointment] database obcp certification comprehensive upgrade open class
- How to use the low code platform of the Internet of things for personal settings?
- 寶,運維100+服務器很頭疼怎麼辦?用行雲管家!
- linux下清理系统缓存并释放内存
- More information about M91 fast hall measuring instrument
- 毕业总结
- Manufacturing SRM management system supplier all-round closed-loop management, to achieve procurement sourcing and process efficient collaboration
- 组队学习! 14天鸿蒙设备开发“学练考”实战营限时免费加入!
猜你喜欢
MATLAB中subplot函数的使用
Openai video pre training (VPT): action learning based on watching unmarked online videos
Bao, what if the O & M 100+ server is a headache? Use Xingyun housekeeper!
微服务大行其道的今天,Service Mesh是怎样一种存在?
Lumiprobe 亚磷酰胺丨六甘醇亚磷酰胺说明书
有关 M91 快速霍尔测量仪的更多信息
11、用户、组和权限(1)
Lake Shore - crx-em-hf low temperature probe station
MySQL common graphics management tools | dark horse programmers
B2B e-commerce platform solution for fresh food industry to improve the standardization and transparency of enterprise transaction process
随机推荐
从零开始学 MySQL —数据库和数据表操作
ECS summer money saving secret, this time @ old users come and take it away
Lumiprobe 自由基分析丨H2DCFDA说明书
Solidity - 算术运算的截断模式(unchecked)与检查模式(checked)- 0.8.0新特性
ES6数组方法find()、findIndex()的总结「建议收藏」
太爱速M源码搭建,巅峰小店APP溢价寄卖源码分享
Solidity - 合约结构 - 错误(error)- ^0.8.4版本新增
B2B e-commerce platform solution for fresh food industry to improve the standardization and transparency of enterprise transaction process
Lake Shore 连续流动低温恒温器传输线
Viewing the whole ecology of Tiktok from a macro perspective
Viewing technological changes through Huawei Corps (VI): smart highway
水产行业智能供应链管理平台解决方案:支撑企业供应链数字化,提升企业管理效益
Digital business cloud: from planning to implementation, how does Minmetals Group quickly build a new pattern of digital development?
数据仓库(四)之ETL开发
Gameframework eating guide
M91快速霍尔测量仪—在更短的时间内进行更好的测量
华为游戏初始化init失败,返回错误码907135000
ETL development of data warehouse (IV)
CDGA|从事通信行业,那你应该考个数据管理证书
Bao, what if the O & M 100+ server is a headache? Use Xingyun housekeeper!