らんだむな記憶

blogというものを体験してみようか!的なー

層の重み

Udacityのud187の課題「Celsius to Fahrenheit」を再び引き合いに出す。

●モデルの実装

model = tf.keras.Sequential([
    tf.keras.layers.Dense(units=1, input_shape=[1])
])

model.summary():

Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense (Dense)                (None, 1)                 2         
=================================================================
Total params: 2
Trainable params: 2
Non-trainable params: 0
_________________________________________________________________

model.get_weights():
●学習前

dense
shape: (1, 1)
[[1.5113307]]
shape: (1,)
[0.]

●学習後

dense
shape: (1, 1)
[[1.8202275]]
shape: (1,)
[29.315647]

となっていて $f=c\times1.8+32$ をかなり近く推定できていることが見える。ここで 1.82... が入力層への入力 $c$ に対して作用する重みであり、29.3... が次の層(= 出力層)へのバイアスに相当する。出力層の活性化関数を省略しているので“線形”活性化として恒等写像になっている。