带温度的softmax

编程入门 行业动态 更新时间:2024-10-26 06:31:58

带<a href=https://www.elefans.com/category/jswz/34/1769107.html style=温度的softmax"/>

带温度的softmax


用pytorch写一下使用带有温度的softmax的demo

import torch
import torch.nn.functional as F# 定义带有温度的softmax函数
def temperature_softmax(logits, temperature=1.0):return F.softmax(logits / temperature, dim=-1)# 输入logits
logits = torch.tensor([[1.0, 2.0, 3.0], [1.0, -1.0, 0.5]])# 不同温度的输出
temperatures = [0.5, 1.0, 2.0]for temp in temperatures:print(f"Temperature = {temp}")print(temperature_softmax(logits, temp))print()

更多推荐

带温度的softmax

本文发布于:2023-12-06 00:07:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1665827.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:温度   softmax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!