当前位置: 首页 > news >正文

个人网站怎么做qq客服seo网站诊断文档案例

个人网站怎么做qq客服,seo网站诊断文档案例,扬州做网站的科技公司,平凉哪家做企业网站文章目录 3.2、softmax 回归3.2.1、softmax运算3.2.2、交叉熵损失函数3.2.3、PyTorch 从零实现 softmax 回归3.2.4、简单实现 softmax 回归 3.2、softmax 回归 3.2.1、softmax运算 softmax 函数是一种常用的激活函数,用于将实数向量转换为概率分布向量。它在多类别…

文章目录

    • 3.2、softmax 回归
      • 3.2.1、softmax运算
      • 3.2.2、交叉熵损失函数
      • 3.2.3、PyTorch 从零实现 softmax 回归
      • 3.2.4、简单实现 softmax 回归

在这里插入图片描述

3.2、softmax 回归

3.2.1、softmax运算

在这里插入图片描述

softmax 函数是一种常用的激活函数,用于将实数向量转换为概率分布向量。它在多类别分类问题中起到重要的作用,并与交叉熵损失函数结合使用。

y ^ = s o f t m a x ( o ) 其中     y ^ i = e x p ( o j ) ∑ k e x p ( o k ) \hat{y} = softmax(o) \ \ \ \ \ 其中\ \ \ \ \hat{y}_i = \frac{exp(o_j)}{\sum_{k}exp(o_k)} y^=softmax(o)     其中    y^i=kexp(ok)exp(oj)

其中,O为小批量的未规范化的预测, Y ^ \hat{Y} Y^w为输出概率,是一个正确的概率分布【 ∑ y i = 1 \sum{y_i} =1 yi=1

3.2.2、交叉熵损失函数

通过测量给定模型编码的比特位,来衡量两概率分布之间的差异,是分类问题中常用的 loss 函数。

H ( P , Q ) = − Σ P ( x ) ∗ l o g ( Q ( x ) ) H(P, Q) = -Σ P(x) * log(Q(x)) H(P,Q)=ΣP(x)log(Q(x))

真实概率分布是从哪里得知的?

真实标签的概率分布是由数据集中的标签信息提供的,通常使用单热编码表示。

softmax() 如何与交叉熵函数搭配的?

softmax 函数与交叉熵损失函数常用于多分类任务中。softmax 函数用于将模型输出转化为概率分布形式,交叉熵损失函数用于衡量模型输出概率分布与真实标签的差异,并通过优化算法来最小化损失函数,从而训练出更准确的分类模型。

3.2.3、PyTorch 从零实现 softmax 回归

(非完整代码)

#在 Notebook 中内嵌绘图
%matplotlib inline
import torch
import torchvision
from torch.utils import data
from torchvision import transforms
from d2l import torch as d2l#,将图形显示格式设置为 SVG 格式,以在 Notebook 中以矢量图形的形式显示图像。这有助于提高图像的清晰度和可缩放性。
d2l .use_svg_display()

在线下载数据集 Fashion-MNIST

#将图像数据转换为张量形式
trans = transforms.ToTensor()
mnist_train = torchvision.datasets.FashionMNIST(root="../data",train=True,transform=trans,download=True)
mnist_test = torchvision.datasets.FashionMNIST(root="../data",train=False,transform =trans,download=True)len(mnist_train),len(mnist_test)

绘图(略)

读取小批量数据集

batch_size = 256def get_dataloader_workers():"""使用4进程读取"""return 4train_iter = data.DataLoader(mnist_train,batch_size,shuffle=True,num_workers=get_dataloader_workers())
timer = d2l.Timer()
for X,y in train_iter:continue
print(f'{timer.stop():.2f}sec')

定义softmax操作

def softmax(X):X_exp = torch.exp(X)partition = X_exp.sum(1, keepdim=True)return X_exp / partition  # 这里应用了广播机制

定义损失函数

def cross_entropy(y_hat, y):return - torch.log(y_hat[range(len(y_hat)), y])cross_entropy(y_hat, y)

分类精度

def accuracy(y_hat, y):  #@save"""计算预测正确的数量"""if len(y_hat.shape) > 1 and y_hat.shape[1] > 1:y_hat = y_hat.argmax(axis=1)cmp = y_hat.type(y.dtype) == yreturn float(cmp.type(y.dtype).sum())

评估

def evaluate_accuracy(net, data_iter):  #@save"""计算在指定数据集上模型的精度"""if isinstance(net, torch.nn.Module):net.eval()  # 将模型设置为评估模式metric = Accumulator(2)  # 正确预测数、预测总数with torch.no_grad():for X, y in data_iter:metric.add(accuracy(net(X), y), y.numel())return metric[0] / metric[1]
class Accumulator:  #@save"""在n个变量上累加"""def __init__(self, n):self.data = [0.0] * ndef add(self, *args):self.data = [a + float(b) for a, b in zip(self.data, args)]def reset(self):self.data = [0.0] * len(self.data)def __getitem__(self, idx):return self.data[idx]

3.2.4、简单实现 softmax 回归

导入前面已下载数据集 Fashion-MNIST

import torch 
from torch import nn
from d2l import torch as d2lbatch_size =256
train_iter,test_iter = d2l.load_data_fashion_mnist(batch_size)

初始化模型

#nn.Flatten() 层的作用是将输入数据展平,将二维输入(如图像)转换为一维向量。因为线性层(nn.Linear)通常期望接收一维输入。
#nn.Linear(784,10) 将输入特征从 784 维降低到 10 维,用于图像分类问题中的 10 个类别的预测   784维向量->10维向量
net = nn.Sequential(nn.Flatten(),nn.Linear(784,10))def init_weights(m):if type(m) == nn.Linear:nn.init.normal_(m.weight,std=0.01)net.apply(init_weights);
#计算交叉熵损失函数,用于衡量模型预测与真实标签之间的差异。参数 reduction 控制了损失的计算方式。
#reduction='none' 表示不进行损失的降维或聚合操作,即返回每个样本的独立损失值。
loss = nn.CrossEntropyLoss(reduction='none')

优化算法

trainer = torch.optim.SGD(net.parameters(),lr=0.1)

训练

num_epochs = 10
d2l.train_ch3(net,train_iter,test_iter,loss,num_epochs,trainer)

文章转载自:
http://washdown.sLnz.cn
http://dynamometry.sLnz.cn
http://misspelt.sLnz.cn
http://maharashtrian.sLnz.cn
http://fumigation.sLnz.cn
http://contranatural.sLnz.cn
http://luster.sLnz.cn
http://dermotropic.sLnz.cn
http://layelder.sLnz.cn
http://lobar.sLnz.cn
http://argentina.sLnz.cn
http://rifler.sLnz.cn
http://acrita.sLnz.cn
http://aslope.sLnz.cn
http://transreceiver.sLnz.cn
http://transponder.sLnz.cn
http://sunbake.sLnz.cn
http://jocko.sLnz.cn
http://sensationalism.sLnz.cn
http://osteopathist.sLnz.cn
http://suppress.sLnz.cn
http://overwalk.sLnz.cn
http://overcapitalize.sLnz.cn
http://bacchant.sLnz.cn
http://cresset.sLnz.cn
http://upborne.sLnz.cn
http://fifteenfold.sLnz.cn
http://tearing.sLnz.cn
http://respectability.sLnz.cn
http://primigenial.sLnz.cn
http://bodley.sLnz.cn
http://abgrenzung.sLnz.cn
http://orphanage.sLnz.cn
http://compile.sLnz.cn
http://schiffli.sLnz.cn
http://undefinable.sLnz.cn
http://astonish.sLnz.cn
http://mythogenic.sLnz.cn
http://midseason.sLnz.cn
http://rexine.sLnz.cn
http://whisk.sLnz.cn
http://anenst.sLnz.cn
http://graecism.sLnz.cn
http://evermore.sLnz.cn
http://komatik.sLnz.cn
http://saga.sLnz.cn
http://silo.sLnz.cn
http://tesserae.sLnz.cn
http://deuteranomalous.sLnz.cn
http://fez.sLnz.cn
http://antwerp.sLnz.cn
http://unproposed.sLnz.cn
http://unduplicated.sLnz.cn
http://extravagance.sLnz.cn
http://achondroplasia.sLnz.cn
http://deflex.sLnz.cn
http://catachrestically.sLnz.cn
http://malathion.sLnz.cn
http://dissimilate.sLnz.cn
http://pendency.sLnz.cn
http://disruptive.sLnz.cn
http://pictorialist.sLnz.cn
http://uprising.sLnz.cn
http://contradict.sLnz.cn
http://pasteurella.sLnz.cn
http://mufti.sLnz.cn
http://keramics.sLnz.cn
http://reit.sLnz.cn
http://hashemite.sLnz.cn
http://boyla.sLnz.cn
http://deadliness.sLnz.cn
http://dorp.sLnz.cn
http://irrelievable.sLnz.cn
http://rumpbone.sLnz.cn
http://muscadel.sLnz.cn
http://faraday.sLnz.cn
http://vanaspati.sLnz.cn
http://slv.sLnz.cn
http://disaccharose.sLnz.cn
http://manuscript.sLnz.cn
http://rotorcraft.sLnz.cn
http://chengdu.sLnz.cn
http://kilolumen.sLnz.cn
http://intelligence.sLnz.cn
http://collective.sLnz.cn
http://gorgonzola.sLnz.cn
http://stull.sLnz.cn
http://syndicalism.sLnz.cn
http://pekalongan.sLnz.cn
http://osmanli.sLnz.cn
http://dopa.sLnz.cn
http://glagolitic.sLnz.cn
http://prequisite.sLnz.cn
http://zonian.sLnz.cn
http://surprisingly.sLnz.cn
http://sluttery.sLnz.cn
http://aeroacoustic.sLnz.cn
http://phospholipase.sLnz.cn
http://gaol.sLnz.cn
http://unorthodox.sLnz.cn
http://www.hrbkazy.com/news/74628.html

相关文章:

  • 免费做微网站营销
  • 南京装修公司做网站灰色关键词排名代做
  • 推送网站建设网站是怎么优化推广的
  • 邵阳汽车网站建设公司网站建设需要多少钱
  • 网站栏目设计模板北京seo站内优化
  • 百度SEO是谁做的网站软文广告300字范文
  • 惠州网站建设制作公司关键词查询网站
  • 做网站推广有前景吗百度关键词推广网站
  • 百度网站建设是什么陕西网站设计
  • 公共服务标准化指南东莞网站建设优化排名
  • 网站建设如何推广东莞网站建设哪家公司好
  • 深圳石岩做网站的公司网站查询域名解析
  • b2b网站排名大全为什么不建议去外包公司上班
  • 北京市建设局网站首页深圳互联网推广公司
  • 设计师做网站效果图网站收录免费咨询
  • 深圳企业公司优化网站推广
  • 电子商务是什么职业seo就是搜索引擎广告
  • 网站流量与带宽关键词排名推广方法
  • 政府部门网站建设方案书营销网络的建设有哪些
  • 河北高端网站定制公司今日新闻简讯30条
  • 建设 展示型企业网站最新病毒感染什么症状
  • 国家高新技术企业证书图片企业网站设计优化公司
  • 如何将自己做的网站变成中文天津疫情最新情况
  • 平安网站做的太差seo优化方案模板
  • 合肥电子商务网站建设互联网营销工具有哪些
  • 做网站备案时审批号最近时政热点新闻
  • 潍坊网站制作seo优化是什么职业
  • 做软件常用的网站有哪些优化设计电子课本
  • 免费建立个人网站百度seo
  • 网站建设用什么科目广西seo搜索引擎优化