題目の通り、Chainer Tutorial 13章の[6]のコードでエラーが出たので、修正した内容をメモしておきます。(2019年6月22日時点)
ちなみにPythonのバージョンは3.6.8です。
# d y / d h1
dydh1 = w2
# d h1 / d u1
dh1du1 = h1 * (1 - h1)
# d u_1 / d w1
du1dw1 = x
# 上から du1 / dw1 の直前までを一旦計算
dLdu1 = dLdy * dydh1 * dh1du1
dLdu1 = dLdu1[None]
# du1dw1は (3,) というshapeなので、g_u1w1[None]として(1, 3)に変形
du1dw1 = du1dw1[None]
# dL / dw_1: 求めたい勾配
dLdw1 = dLdu1.T.dot(du1dw1)
print(dLdw1)
真ん中らへんにある以下のコードを挿入しただけです。
dLdu1 = dLdu1[None]