深度学习与自然语言处理(4)_斯坦福cs224d 大作业测验1与解答

本文是斯坦福大学CS224d课程的中文版作业详解,涵盖Softmax、神经网络基础、word2vec和情感分析等内容。作业涉及证明、代码实现和梯度计算,同时探讨了softmax的稳定性、神经网络的前向和反向传播、word2vec的梯度计算以及情感分析的实践应用。

作业内容翻译:@胡杨(superhy199148@hotmail.com) && @胥可(feitongxiaoke@gmail.com)
解答与编排:寒小阳 && 龙心尘
时间:2016年6月
出处:http://blog.csdn.net/han_xiaoyang/article/details/51760923

说明:本文为斯坦福大学CS224d课程的中文版内容笔记,已得到斯坦福大学课程@Richard Socher教授的授权翻译与发表

0 前言

前面一个接一个的Lecture,看得老衲自己也是一脸懵逼,不过你以为你做一个安安静静的美男子(总感觉有勇气做deep learning的女生也是一条汉纸)就能在Stanford这样的学校顺利毕业啦?图样图森破,除掉极高的内容学习梯度,这种顶尖大学的作业和考试一样会让你突(tong)飞(bu)猛(yu)进(sheng)。

说起来,怎么也是堂堂斯坦福的课,这种最看重前言研究在实际工业应用的学校,一定是理论和应用并进,对动手能力要求极强的,于是乎,我们把作业和小测验(MD你这也敢叫小测验!!)也扒过来,整理整理,让大家都来体验体验。反正博主君自己每次折腾完这些大学的assignment之后,都会感慨一句,“还好不生在水生火热的万恶资本主义国家,才能让我大学和研究僧顺利毕业(什么?phd?呵呵…博主是渣渣,智商常年处于欠费状态,我就不参与你们高端人士的趴体了)”。

不能再BB了,直接开始做作业考试吧…

1 Softmax (10 分)

(part a) (5分)
证明针对任何输入向量 x 和常数c,softmax函数的输出不会随着输入向量偏移(也就是常数c)而改变。即:

softmax(x)=softmax(x+c)

其中 x+c 就是给 x 每一个元素加上常数c。注意:

softmax(x)i=exijexj

提示:在实际应用中,经常会用到这个性质。为了稳定地计算softmax概率,我们会选择 c=maxixi 。(即将 x 的每个元素减去最大的那个元素)。

博主:熬过了高中,居然又看见证明了,也是惊(ri)喜(le)万(gou)分(le),答案拿来!!!

解答:

证明,针对所有维度 1idim(x)

(softmax(x+c))i=exp(xi+c)dim(x)j=1exp(xj+c)=exp(c)exp(xi)exp(c)dim(x)j=1exp(xj)=exp(xi)dim(x)j=1exp(xj)=(softmax(x))i

(part b) (5 分)
已知一个N行d列的输入矩阵,计算每一行的softmax概率。在q1_softmax.py中写出你的实现过程,并使用python q1_softmax.py执行。

要求:你所写的代码应该尽可能的有效并以向量化的形式来实现。非向量化的实现将不会得到满分。

博主:简直要哭晕在厕所了,当年毕业设计也是加论文一星期都可以写完的节奏,这里一个5分的作业,还这么多要求…社会主义好…答案拿来!!!

import numpy as np

def softmax(x):
    """
        Softmax 函数
    """
    assert len(x.shape) > 1, "Softmax的得分向量要求维度高于1"
    x -= np.max(x, axis=1, keepdims=True)
    x = np.exp(x) / np.sum(np.exp(x), axis=1, keepdims=True)

    return x

2 神经网络基础(30分)

(part a) (3 分)
推导sigmoid函数的导数,并且只以sigmoid函数值的形式写出来(导数的表达式里只包含 σ(x) ,不包含x)。证明针对这个问题没必要单独考虑x。方便回忆:下面给出sigmoid函数形式:

σ(x)=11+ex

旁白:我年纪轻轻干嘛要走上深度学习这条不归路,真是生无所恋了。

答案 σ(x)=σ(x)(1σ(x))

(part b) (3 分)
当使用交叉熵损失来作为评价标准时,推导出损失函数以softmax为预测结果的输入向量 θ 的梯度。注意,

CE(y,ŷ )=iyilog(ŷ i)

其中 y 是一个one-hot向量, ŷ  是所有类别的预测出的概率向量。(提示:你需要考虑 y 的许多元素为0,并且假设 y 仅有第k个类别是1)

答案: CE(y,ŷ )θ=ŷ y

或者等价于下面表达式,其中假设k是正确的类别

CE(y,ŷ )θ={ ŷ i1,i=kŷ i,otherwise

(part c) (6 分)
推导出单隐层神经网络关于输入 x 的梯度(也就是推导出 Jx ,其中J是神经网络的损失函数)。这个神经网络在隐层和输出层采用了sigmoid激活函数, y 是one-hot编码向量,使用了交叉熵损失。(使用 σ(x)

### SAP R3T RPROG Z_RPSD_DELIVERY_LIST Program Information and Usage In the context of SAP systems, custom programs such as `Z_RPSD_DELIVERY_LIST` are typically created to meet specific business requirements that standard transactions do not cover. The program name suggests this is a customized report or process related to delivery lists. For detailed information on how to find and use this program within an SAP environment: #### Locating the Custom Program To locate the custom program `Z_RPSD_DELIVERY_LIST`, one can utilize transaction code SE38 which serves as the ABAP Execution screen where users input their desired program names for execution[^1]. Once inside SE38: - Enter `Z_RPSD_DELIVERY_LIST` into the "Program" field. - Press F8 (Execute) to run the program directly from here if it has been set up with selection screens; otherwise, proceed through other development tools like SE80 Object Navigator for further inspection. #### Understanding Functionality The functionality provided by `Z_RPSD_DELIVERY_LIST` would depend heavily upon its design specifications at implementation time. Typically these types of reports might involve extracting data about deliveries including but not limited to order details, shipment status updates, etc., depending entirely on what was required when developing them specifically for organizational needs[^2]. If there exists documentation associated with this particular piece of software during deployment phases then referring back could provide insights regarding exact parameters expected while executing along with any special considerations programmers intended end-users should be aware of before running said script against live datasets. ```abap CALL TRANSACTION 'SE38' AND SKIP FIRST SCREEN. ``` This command allows direct access to execute predefined ABAP programs via transaction codes without navigating menus manually each time.
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值