Skip to Content
深度学习入门 : 基于Python的理论与实现
book

深度学习入门 : 基于Python的理论与实现

by 斋藤康毅
July 2018
Intermediate to advanced
310 pages
8h 21m
Chinese
Posts & Telecom Press
Content preview from 深度学习入门 : 基于Python的理论与实现
3章 神经网络
66
3.5.2
 实现softmax函数时的注意事项
上面的
softmax
函数的实现虽然正确描述了式(3.10),但在计算机的运算
上有一定的缺陷。这个缺陷就是溢出问题。
softmax
函数的实现中要进行指
数函数的运算,但是此时指数函数的值很容易变得非常大。比如,
e
10
的值
会超过20000
e
100
会变成一个后面有40 多个0 的超大值,
e
1000
的结果会返回
一个表示无穷大的
inf
。如果在这些超大值之间进行除法运算,结果会出现“不
确定”的情况。
计算机处理“数”时,数值必须在 4 字节或 8 字节的有限数据宽度内。
这意味着数存在有效位数,也就是说,可以表示的数值范围是有
限的。因此,会出现超大值无法表示的问题。这个问题称为溢出,
在进行计算机的运算时必须(常常)注意。
softmax
函数的实现可以像式(3.11)这样进行改进。
3.11
首先,式(3.11)在分子和分母上都乘上
C
这个任意的常数(因为同时对
分母和分子乘以相同的常数,所以计算结果不变)。然后,把这个
C
移动到
指数函数(
exp
)中,记为
log C
。最后,把
log C
替换为另一个符号
C
式(3.11)说明,在进行
softmax
的指数函数的运算时,加上(或者减去)
某个常数并不会改变运算的结果。这里的
C
可以使用任何值,但是为了防
止溢出,一般会使用输入信号中的最大值。我们来看一个具体的例子。
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

ルールズ・オブ・プログラミング ―より良いコードを書くための21のルール

ルールズ・オブ・プログラミング ―より良いコードを書くための21のルール

Chris Zimmerman, 久富木 隆一

Publisher Resources

ISBN: 9787115485588