提交 02036d80 编写于 作者: S ShusenTang

update doc 6.4

上级 4526754b
......@@ -38,7 +38,8 @@ one_hot(x, vocab_size)
我们每次采样的小批量的形状是(批量大小, 时间步数)。下面的函数将这样的小批量变换成数个可以输入进网络的形状为(批量大小, 词典大小)的矩阵,矩阵个数等于时间步数。也就是说,时间步$t$的输入为$\boldsymbol{X}_t \in \mathbb{R}^{n \times d}$,其中$n$为批量大小,$d$为输入个数,即one-hot向量长度(词典大小)。
``` python
def to_onehot(X, n_class): # 本函数已保存在d2lzh包中方便以后使用
# 本函数已保存在d2lzh_pytorch包中方便以后使用
def to_onehot(X, n_class):
# X shape: (batch, seq_len), output: seq_len elements of (batch, n_class)
return [one_hot(X[:, i], n_class) for i in range(X.shape[1])]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册