Softmax回归的从零实现

感谢!
我也是遇到了这个问题,找不到解决方法,翻了好久评论终于在你这找到了答案!
我也挺好奇为什么其他的同学没有遇到类似的问题 :joy:

Run with Jupyter notebook or add “d2l.plt.show()”


这里执行第二段代码报
UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at .[./learn_/Dive_into_deep_learning/d2l-zh/pytorch/chapter_linear-networks/torch/csrc/utils/tensor_numpy.cpp:180).)
这个错,不过好像不影响运行其他代码,有什么办法修复吗?

cross_entropy只是计算loss,真更新还是靠updater,相当于前面章节的train方法,updater里面就是一个sgd,最后训练好的模型的参数就是W和b了。

def cross_entropy(y_hat, y):
return - torch.log(y_hat[range(len(y_hat)), y])

cross_entropy(y_hat, y)

这里的交叉熵损失函数定义为什么没有y_hat本身与LOG相乘?就是直接使用LOG函数了。

我发现这里每个epoch只训练了一个batchsize的数据,对吗?这好像我以前对于“每个epoch要遍历全体数据集一遍”的认知,并且下载的fashion-mnist数据都是一些无法打开的文件,它们是怎么被读入的?

每个epoch只训练了一个batchsize的数据

不是的,你看Dataloader部分的定义

fashion-mnist数据都是一些无法打开的文件

从名称看应该都是字节数据,直接读取的byte