当前位置:网站首页>学习笔记【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
边栏推荐
- Improve yolov5 with gsconv+slim neck to maximize performance!
- Lake shore M91 fast hall measuring instrument
- Lumiprobe 自由基分析丨H2DCFDA说明书
- Lake Shore低温恒温器的氦气传输线
- Games202 operation 0 - environment building process & solving problems encountered
- M91快速霍尔测量仪—在更短的时间内进行更好的测量
- 有关 M91 快速霍尔测量仪的更多信息
- 小红书上的爱情买卖
- Golang error handling
- 太爱速M源码搭建,巅峰小店APP溢价寄卖源码分享
猜你喜欢

Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?

寶,運維100+服務器很頭疼怎麼辦?用行雲管家!

Lumiprobe phosphide hexaethylene phosphide specification

Is PMP cancelled??

Learn MySQL from scratch - database and data table operations
![[live broadcast appointment] database obcp certification comprehensive upgrade open class](/img/38/1ec382d0edda83d4052868255af9ea.jpg)
[live broadcast appointment] database obcp certification comprehensive upgrade open class

华为云专家详解GaussDB(for MySQL)新特性

Lake shore optimag superconducting magnet system om series

Chinese and English instructions human soluble advanced glycation end products receptor (sRAGE) ELISA Kit

Bao, what if the O & M 100+ server is a headache? Use Xingyun housekeeper!
随机推荐
Manufacturing SRM management system supplier all-round closed-loop management, to achieve procurement sourcing and process efficient collaboration
The best landing practice of cave state in an Internet ⽹⾦ financial technology enterprise
B2B e-commerce platform solution for fresh food industry to improve the standardization and transparency of enterprise transaction process
Cdga | if you are engaged in the communication industry, you should get a data management certificate
Huawei game failed to initialize init with error code 907135000
Lake Shore 连续流动低温恒温器传输线
2020, the regular expression for mobile phone verification of the latest mobile phone number is continuously updated
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
宝,运维100+服务器很头疼怎么办?用行云管家!
Love business in Little Red Book
Improve yolov5 with gsconv+slim neck to maximize performance!
Gameframework eating guide
PostgreSQL varchar[] 数组类型操作
Graduation summary
PMP是被取消了吗??
【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?
[6.24-7.1] review of wonderful technical blog posts in the writing community
linux下清理系统缓存并释放内存
Lumiprobe cell imaging study PKH26 cell membrane labeling kit
nacos配置文件发布失败,请检查参数是否正确的解决方案