TrickyGo / Dive-into-DL-TensorFlow2.0

本项目将《动手学深度学习》(Dive into Deep Learning)原书中的MXNet实现改为TensorFlow 2.0实现,项目已得到李沐老师的认可
https://trickygo.github.io/Dive-into-DL-TensorFlow2.0/#/
Apache License 2.0
3.79k stars 820 forks source link

6.4 和 6.5 小结中,损失函数缺少一个参数,导致训练结果不正确 #64

Closed sunshine-zkf closed 3 years ago

sunshine-zkf commented 4 years ago

l = tf.reduce_mean(tf.losses.sparse_categorical_crossentropy(y,outputs)) 该损失函数缺少参数 from_logits = True。在计算输出是没有使用激活函数softmax,因此需要在损失函数上指定,即令from_logits = True。故损失函数应该为: l = tf.reduce_mean(tf.losses.sparse_categorical_crossentropy(y,outputs,from_logits=True))

错误结果:

epoch 50, perplexity 100.705286, time 1.76 sec 分开

archersama commented 4 years ago

了解,感谢指正

pengfei-chen commented 3 years ago

👍

archersama commented 3 years ago

已修正