当前位置:网站首页>学习笔记【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
边栏推荐
- Chinese and English instructions human soluble advanced glycation end products receptor (sRAGE) ELISA Kit
- Lake Shore continuous flow cryostat transmission line
- 华为云专家详解GaussDB(for MySQL)新特性
- 【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决
- 【Go ~ 0到1 】 第四天 6月30 defer,结构体,方法
- C-end dream is difficult to achieve. What does iFLYTEK rely on to support the goal of 1billion users?
- Viewing technological changes through Huawei Corps (VI): smart highway
- Solidity - 算术运算的截断模式(unchecked)与检查模式(checked)- 0.8.0新特性
- Viewing the whole ecology of Tiktok from a macro perspective
- 机械设备行业数字化供应链集采平台解决方案:优化资源配置,实现降本增效
猜你喜欢

Love business in Little Red Book

Once the SQL is optimized, the database query speed is increased by 60 times

Huawei game failed to initialize init with error code 907135000

Lumiprobe cell imaging study PKH26 cell membrane labeling kit

Lake Shore 连续流动低温恒温器传输线

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

Lumiprobe 细胞成像研究丨PKH26细胞膜标记试剂盒

C端梦难做,科大讯飞靠什么撑起10亿用户目标?

有关 M91 快速霍尔测量仪的更多信息

Example explanation: move graph explorer to jupyterlab
随机推荐
The best landing practice of cave state in an Internet ⽹⾦ financial technology enterprise
PriorityQueue的用法和底层实现原理
Lake Shore低温恒温器的氦气传输线
Shell array
ES6数组去重的三个简单办法
洞态在某互联⽹⾦融科技企业的最佳落地实践
Lumiprobe free radical analysis h2dcfda instructions
寶,運維100+服務器很頭疼怎麼辦?用行雲管家!
kubernetes命令入门(namespaces,pods)
有关 M91 快速霍尔测量仪的更多信息
华为联机对战服务玩家掉线重连案例总结
How to realize the applet in its own app to realize continuous live broadcast
Learning notes - steps of JDBC connection database operation
Learn MySQL from scratch - database and data table operations
[quick application] there are many words in the text component. How to solve the problem that the div style next to it will be stretched
Clean up system cache and free memory under Linux
Today, with the popularity of micro services, how does service mesh exist?
MySQL常用图形管理工具 | 黑马程序员
太爱速M源码搭建,巅峰小店APP溢价寄卖源码分享
2. Create your own NFT collections and publish a Web3 application to show them start and run your local environment