当前位置:网站首页>学习笔记【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
边栏推荐
- ES6数组方法find()、findIndex()的总结「建议收藏」
- Example explanation: move graph explorer to jupyterlab
- 有关 M91 快速霍尔测量仪的更多信息
- 如何使用物联网低代码平台进行个人设置?
- Love business in Little Red Book
- 3. "Create your own NFT collections and publish a Web3 application to show them" cast NFT locally
- [quick application] win7 system cannot run and debug projects using Huawei ide
- AppGallery Connect场景化开发实战—图片存储分享
- bean的生命周期核心步骤总结
- Implement a Prometheus exporter
猜你喜欢
随机推荐
Technical secrets of ByteDance data platform: implementation and optimization of complex query based on Clickhouse
MySQL common graphics management tools | dark horse programmers
Netease games, radical going to sea
【Go ~ 0到1 】 第四天 6月30 defer,结构体,方法
Database foundation: select basic query statement
Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
实现一个Prometheus exporter
CDGA|从事通信行业,那你应该考个数据管理证书
PriorityQueue的用法和底层实现原理
The market value evaporated by 74billion yuan, and the big man turned and entered the prefabricated vegetables
从零开始学 MySQL —数据库和数据表操作
中英说明书丨人可溶性晚期糖基化终末产物受体(sRAGE)Elisa试剂盒
Lumiprobe phosphide hexaethylene phosphide specification
2020, the regular expression for mobile phone verification of the latest mobile phone number is continuously updated
Chinese and English instructions human soluble advanced glycation end products receptor (sRAGE) ELISA Kit
Solidity - 算术运算的截断模式(unchecked)与检查模式(checked)- 0.8.0新特性
毕业总结
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
Go language self-study series | go language data type
bean的生命周期核心步骤总结









