- # NLL is a symbolic variable ; to get the actual value of NLL, this symbolic
- # expression has to be compiled into a Theano function (see the Theano
- # tutorial for more details)
- NLL = -T.sum(T.log(p_y_given_x)[T.arange(y.shape[0]), y])
- # note on syntax: T.arange(y.shape[0]) is a vector of integers [0,1,2,...,len(y)].
- # Indexing a matrix M by the two vectors [0,1,...,K], [a,b,...,k] returns the
- # elements M[0,a], M[1,b], ..., M[K,k] as a vector. Here, we use this
- # syntax to retrieve the log-probability of the correct labels, y.
theano中的index好怪异。。比如最大似然估计的损失计算部分。
本文介绍了如何使用 Theano 计算负对数似然 (NLL)。通过构建一个符号变量 NLL,并利用 Theano 的特性将其编译为函数。文中详细解释了 T.arange 和 T.log 在获取正确标签的对数概率中的应用。


被折叠的 条评论
为什么被折叠?



