当前位置:网站首页>学习笔记【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
边栏推荐
- js找出数字在数组中下一个相邻的元素
- Solution of digital supply chain centralized purchase platform in mechanical equipment industry: optimize resource allocation and realize cost reduction and efficiency increase
- 241. Different Ways to Add Parentheses
- 如何运营好技术相关的自媒体?
- Games202 operation 0 - environment building process & solving problems encountered
- XML语法、约束
- Improve yolov5 with gsconv+slim neck to maximize performance!
- 一次SQL优化,数据库查询速度提升 60 倍
- AppGallery Connect场景化开发实战—图片存储分享
- How to operate technology related we media well?
猜你喜欢

Solidity - 合约结构 - 错误(error)- ^0.8.4版本新增

Getting started with kubernetes command (namespaces, pods)

Manufacturing SRM management system supplier all-round closed-loop management, to achieve procurement sourcing and process efficient collaboration

Lumiprobe free radical analysis h2dcfda instructions

Prices of Apple products rose across the board in Japan, with iphone13 up 19%

11、用户、组和权限(1)

June issue | antdb database participated in the preparation of the "Database Development Research Report" and appeared on the list of information technology and entrepreneurship industries

华为游戏初始化init失败,返回错误码907135000

Lumiprobe 亚磷酰胺丨六甘醇亚磷酰胺说明书

11. Users, groups, and permissions (1)
随机推荐
ES6数组方法find()、findIndex()的总结「建议收藏」
Netease games, radical going to sea
组队学习! 14天鸿蒙设备开发“学练考”实战营限时免费加入!
Example explanation: move graph explorer to jupyterlab
Dom4J解析XML、Xpath检索XML
Stanford, salesforce|maskvit: masked vision pre training for video prediction
Taiaisu M source code construction, peak store app premium consignment source code sharing
Chaos engineering platform chaosblade box new heavy release
案例分享:QinQ基本组网配置
Dlib+Opencv库实现疲劳检测
【Go ~ 0到1 】 第五天 7月1 类型别名,自定义类型,接口,包与初始化函数
kubernetes命令入门(namespaces,pods)
记一次 .NET 差旅管理后台 CPU 爆高分析
6月刊 | AntDB数据库参与编写《数据库发展研究报告》 亮相信创产业榜单
Learn MySQL from scratch - database and data table operations
Solution: you can ping others, but others can't ping me
Lake shore M91 fast hall measuring instrument
Lumiprobe cell imaging study PKH26 cell membrane labeling kit
Prices of Apple products rose across the board in Japan, with iphone13 up 19%
Bao, que se passe - t - il si le serveur 100 + O & M a mal à la tête? Utilisez le majordome xingyun!